Home | History | Annotate | Download | only in shootout

Lines Matching defs:piece

58  *   Piece 0   Piece 1   Piece 2   Piece 3   Piece 4
64 * Piece 5 Piece 6 Piece 7 Piece 8 Piece 9
71 * piece definitions to fit into the same size arrays. It is
72 * not possible to define piece 4 in terms of the 6 cardinal
105 * I'm going to allocate enough space for all legal rotations of each piece
111 * I'm also going to record the next possible open cell for each piece and
190 * of the board. Used to determine if a piece is at a legal board
229 /* Rotate a piece 60 degrees clockwise */
230 void rotate_piece(int piece) {
233 piece_def[piece][i] = rotate(piece_def[piece][i]);
236 /* Flip a piece along the horizontal axis */
237 void flip_piece(int piece) {
240 piece_def[piece][i] = flip(piece_def[piece][i]);
243 /* Convenience function to quickly calculate all of the indices for a piece */
244 void calc_cell_indices(char *cell, int piece, char 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]);
252 /* Convenience function to quickly calculate if a piece fits on the board */
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]));
260 /* Returns the lowest index of the cells of a piece.
261 * I use the lowest index that a piece occupies as the index for looking up
262 * the piece in the solve function.
273 /* Calculate the lowest possible open cell if the piece is placed on the board.
297 /* Record the piece and other important information in arrays that will
300 void record_piece(int piece, int minimum, char first_empty,
302 pieces[piece][minimum][piece_counts[piece][minimum]] = piece_mask;
303 next_cell[piece][minimum][piece_counts[piece][minimum]] = first_empty;
304 piece_counts[piece][minimum]++;
332 * the board can be solved with the trapped cells. For example: piece 8 can
333 * trap 5 cells in the corner, but piece 3 can fit in those cells, or piece 0
336 int has_island(char *cell, int piece) {
352 if(c == 0 || (c == 5 && piece == 8) || (c == 40 && piece == 8) ||
353 (c % 5 == 0 && piece == 0))
360 /* Calculate all six rotations of the specified piece at the specified index.
361 * We calculate only half of piece 3's rotations. This is because any solution
364 * degree-rotated pieces of ONE of the pieces. I chose piece 3 because it gave
367 void calc_six_rotations(char piece, char index) {
373 if(piece != 3 || rotation < 3) {
374 calc_cell_indices(cell, piece, index);
375 if(cells_fit_on_board(cell, piece) && !has_island(cell, piece)) {
379 record_piece(piece, minimum, first_empty, piece_mask);
382 rotate_piece(piece);
386 /* Calculate every legal rotation for each piece at each board location. */
388 char piece, index;
390 for(piece = 0; piece < 10; piece++) {
392 calc_six_rotations(piece, index);
393 flip_piece(piece);
394 calc_six_rotations(piece, index);
450 * positive. One scenario is when 5 cells may be surrounded where piece 5
451 * or 7 can fit. The other scenario is when piece 2 creates a hook shape.
526 * Because the board is a bit mask, the piece number and bit mask must be saved
527 * at each successful piece placement. This data is used to create a 50 char
555 int piece, rotation, max_rots;
565 for(piece = 0; piece < 10; piece++) {
566 piece_no_mask = 1 << piece;
570 max_rots = piece_counts[piece][cell];
571 piece_mask = pieces[piece][cell];
574 sol_nums[depth] = piece;
583 if(!boardHasIslands(next_cell[piece][cell][rotation]))
584 solve(depth + 1, next_cell[piece][cell][rotation]);