Deleting characters from 2d arrays
hello all :) i need some help.
as it stands i am coding a game: 'Bejeweled' in C, for a school project.
So before you read my problem remember I only want hints not complete solves :p
so far i have coded:
function to fill and print-
a 6 x 6 array to be filled up with random characters (any one of a given four eg # $ % &)
function to check-
where there are 3 or more of the same characters in a row (both horizontally and vertically)- and mark those positions
function to shift any character above a marked character down
eg lets pretend you have
Code:
$ the output of that column should be: -
% -
# -
! $
! %
! #
then of course a simple function which replaces all '-' with new random characters.
unfortunately, this shifting down only works sometimes, in general it works fine, but sometimes it only shifts my column down once or twice instead of three times.
i am using 2 for loops to count backwards from element [5][5] to [0][0] and inside these loops another loop which when it sees an '!' element it checks above it until there is a character which is not '!' or '-' and replaces the position of '!' with that character, and that character with '-'.
my general question: is there a smarter way to do this? eg, see where there are '!' chars, remove them from the array, and shift the column down- without using these troublesome iterations.
what really bugs me is that my algorithm seems to work fine on paper, but only sometimes in my actual program. Testing through all 36 cases about 6 times to check exactly where ive gone wrong seems a bit tedious, so i just wanted a poke in the right direction.
there of course could be something wrong with my code :rolleyes:
but if i post that here ive basically solved the problem for my entire class. :D