Tetris, again.

Rules:


On a 16x16 grid, each of the the 256 squares are initially painted with either colors a,b,c or d.
The game (a Tetris-like) follows as:

1) we remove one square.
2) if there are some squares 'floating' above an empty one, the whole column falls vertically until the space is filled.
3) Cluster of adjacent square sharing the same color may appears. Is so, every cluster of size 4 or more is removed. "Adjacent" means here being neighbours along one of the four Est, West, North or South direction (hence: not the diagonals).

For instance, this is a cluster:

     
     
     

but this one isn't:

     
     
     


4) Goto step 2) until there still are some falling squares.
5) Goto step 1) until they are some squares left.

Goal:

The games starts with the following configuration:

                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 
                                 

with color convention:

a =    
b =    
c =    
d =    
? =    

Here is a C-version:

char *Grid[16] = {
 "adbdcdbdddcbdbab",
 "bccbddbccaadcdaa",
 "dabdacdbbdacaccd",
 "cdababcacbdcadca",
 "baadab????dbaddb",	// <- missing
 "addbdaadcdaddcba",
 "adcacdabcabcaadc",
 "acadcbddbbcdcccd",
 "bdbaadaaabdcaaba",
 "adadbccbdacddcdb",
 "dbaaddbcbdbbbcaa",
 "dccbdcbaacaaacad",
 "cbdacbcadcbdddcc",
 "dbaadbacdcaaacab",
 "dbcdcdbadbbbdaca",
 "dcddccdcccacdcdb"
};

As you've noticed, there's 4 missing squares in the middle, yet-unknown.

You program must accept as only argument a string of 4 characters 'a', 'b', 'c' or 'd'. These characters are the 4 ones missing, in order from left to right. They will be randomly chosen later (when ranking the entries). It will be the same for everybody. It will respect the constaint of *NOT* generating any removable cluster once inserted in the initial grid. Given this input, your program must then ouput, on the standard channel (stdout), a sequence of square index to remove, one after the other, with a carriage return ('\n') inbetween. The squares are indexed in increasing order (beginning at 0) starting from the upper-left corner, and heading to the right. The output format must be in hexadecimal, with 2 chars ([0-9A-F] or [0-9a-f]), without any leading '0x' or ending 'h'.

Namely, the squares' indexes look like:

+++++++++++++++++++++++++++++++++++++++++++++++++
+00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f+
+10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f+
+ ...                                           +
+f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff+
+++++++++++++++++++++++++++++++++++++++++++++++++

Each time you give a new index, the corresponding square is removed from the grid and the steps 2), 3), and 4) of game are run until there is no more cluster to remove.

The goal is to remove all the grid's squares with as few square removal as possible.

At any time, you can stop the process and print the grid's state. This will cost you a penalty (see below).
If you succeed in removing all the squares, you don't need to print the grid.
The grid must be printed as 16 strings of 16 characters ' ', 'a', 'b', 'c' or 'd', empty squares corresponding to ' '.
This output will be compared to what the grid *should* be. If a square is of the correct type, it will cost you less than if the square's type is wrong.

Scoring:

As entry, you can supply a dos-box executable, or an ANSI-C source file. This later must compile with 'gcc -o prog prog.c -lm', either with DJGPP or linux' gcc. In case of problem, watcom-C will the tried too, or even MSVC.

- Every byte of executable, or source file, costs 1 point.
- Every square index output costs 10 points.
- Printing the grid (and ending) costs a 500 points penalty.
- A false grid given at the end costs 5 points per wrong square.
- Correct squares cost 2 points each.

The program's execution may not exceed 5 minutes in time, on the compo PC.

The winning entry will be the one scoring least.

Entry's output will be checked using this C-program. Use it! (and warn me if anything seems strange/bugged in this 'check.c' :)

/Skal