Home | History | Annotate | Download | only in shootout

Lines Matching full:cell

41 /* The board is a 50 cell hexagonal pattern.  For    . . . . .
107 * 12 rotations. However, not all 12 rotations will fit on every cell, so
111 * I'm also going to record the next possible open cell for each piece and
129 /* Returns the new cell index from the specified cell in the
131 * starting cell and direction have been checked by the
134 char shift(char cell, char dir) {
137 return cell + 1;
139 if((cell / 5) % 2)
140 return cell + 7;
142 return cell + 6;
144 if((cell / 5) % 2)
145 return cell + 6;
147 return cell + 5;
149 return cell + 10;
151 if((cell / 5) % 2)
152 return cell + 5;
154 return cell + 4;
156 if((cell / 5) % 2)
157 return cell + 4;
159 return cell + 3;
161 return cell - 1;
163 if((cell / 5) % 2)
164 return cell - 6;
166 return cell - 7;
168 if((cell / 5) % 2)
169 return cell - 5;
171 return cell - 6;
173 return cell - 10;
175 if((cell / 5) % 2)
176 return cell - 4;
178 return cell - 5;
180 if((cell / 5) % 2)
181 return cell - 3;
183 return cell - 4;
185 return cell;
189 /* Returns wether the specified cell and direction will land outside
193 char out_of_bounds(char cell, char dir) {
197 return cell % 5 == 4;
199 i = cell % 10;
200 return i == 4 || i == 8 || i == 9 || cell >= 45;
202 return cell % 10 == 9 || cell >= 45;
204 return cell >= 40;
206 return cell % 10 == 0 || cell >= 45;
208 i = cell % 10;
209 return i == 0 || i == 1 || i == 5 || cell >= 45;
211 return cell % 5 == 0;
213 i = cell % 10;
214 return i == 0 || i == 1 || i == 5 || cell < 5;
216 return cell % 10 == 0 || cell < 5;
218 return cell < 10;
220 return cell % 10 == 9 || cell < 5;
222 i = cell % 10;
223 return i == 4 || i == 8 || i == 9 || cell < 5;
244 void calc_cell_indices(char *cell, int piece, char index) {
245 cell[0] = index;
246 cell[1] = shift(cell[0], piece_def[piece][0]);
247 cell[2] = shift(cell[1], piece_def[piece][1]);
248 cell[3] = shift(cell[2], piece_def[piece][2]);
249 cell[4] = shift(cell[3], piece_def[piece][3]);
253 int cells_fit_on_board(char *cell, int piece) {
254 return (!out_of_bounds(cell[0], piece_def[piece][0]) &&
255 !out_of_bounds(cell[1], piece_def[piece][1]) &&
256 !out_of_bounds(cell[2], piece_def[piece][2]) &&
257 !out_of_bounds(cell[3], piece_def[piece][3]));
264 char minimum_of_cells(char *cell) {
265 char minimum = cell[0];
266 minimum = cell[1] < minimum ? cell[1] : minimum;
267 minimum = cell[2] < minimum ? cell[2] : minimum;
268 minimum = cell[3] < minimum ? cell[3] : minimum;
269 minimum = cell[4] < minimum ? cell[4] : minimum;
273 /* Calculate the lowest possible open cell if the piece is placed on the board.
277 char first_empty_cell(char *cell, char minimum) {
279 while(first_empty == cell[0] || first_empty == cell[1] ||
280 first_empty == cell[2] || first_empty == cell[3] ||
281 first_empty == cell[4])
289 unsigned long long bitmask_from_cells(char *cell) {
293 piece_mask |= 1ULL << cell[i];
308 /* Fill the entire board going cell by cell. If any cells are "trapped"
336 int has_island(char *cell, int piece) {
343 temp_board[((int)cell[i])] = 1;
368 char rotation, cell[5];
374 calc_cell_indices(cell, piece, index);
375 if(cells_fit_on_board(cell, piece) && !has_island(cell, piece)) {
376 minimum = minimum_of_cells(cell);
377 first_empty = first_empty_cell(cell, minimum);
378 piece_mask = bitmask_from_cells(cell);
512 int boardHasIslands(char cell) {
514 if(cell >= 40)
516 int current_triple = (board >> ((cell / 5) * 5)) & TRIPLE_MASK;
517 if((cell / 5) % 2)
525 * leftmost empty cell. Mark off available pieces as it goes along.
554 void solve(int depth, int cell) {
562 while(board & (1ULL << cell))
563 cell++;
570 max_rots = piece_counts[piece][cell];
571 piece_mask = pieces[piece][cell];
583 if(!boardHasIslands(next_cell[piece][cell][rotation]))
584 solve(depth + 1, next_cell[piece][cell][rotation]);