I'm working on the base of a game in which the object is to destroy as many blocks as possible. If connected, clicking a block will destroy it along with all blocks connected to it (cardinal directions only). The blocks above a destroyed section will fall down. If a column is empty, all columns to the right of it will shift left to occupy the empty space and ensure that the blocks are kept together.
My problem lies with just how I should go about tracking and shifting the columns to the right of an empty one. I use an associative array to keep track of the columns (1-10) and which blocks are located within them. Beyond that, I'm not too sure. I have had some success but run into problems when there is more than one empty column next to each other, between full columns.
Really, I'm unsure of how to work out how far I should move the columns. As you can see below, even my pseudo code is very vague. Any ideas on how to resolve this would be much appreciated.
Pseudo Code:
Loop through all columns
if column is empty
find all non-empty columns to the right
move them left until there are no breaks betwen columns