X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/4c08507a26fbe96d3978191a8dea26c1dc4e3d55..f6be82664a5b8e8bc34c048b56417b591dcd5a5e:/src/game.c diff --git a/src/game.c b/src/game.c index 47adc9f..eefafe5 100644 --- a/src/game.c +++ b/src/game.c @@ -119,6 +119,12 @@ void game_reseed(unsigned long long seed) rng_state[3] = splitmix64(&seed); } +#define assign_tile(planes, tile, bit) do { \ + 0[planes] |= (((tile)>>0) & 1ul) << (bit); \ + 1[planes] |= (((tile)>>1) & 1ul) << (bit); \ + 2[planes] |= (((tile)>>2) & 1ul) << (bit); \ +} while (0) + void game_reset(struct board *board) { unsigned char tiles[25]; @@ -141,31 +147,26 @@ void game_reset(struct board *board) shuffle(tiles, 24); memset(board->goal, 0, sizeof board->goal); - for (i = 0; i < 9; i++) { - uint_fast32_t position = board_position(i/3+1, i%3+1) >> 6; - - if (tiles[i] & 1) board->goal[0] |= position; - if (tiles[i] & 2) board->goal[1] |= position; - if (tiles[i] & 4) board->goal[2] |= position; + /* + * Goal bitmap has 2-tile "gaps" between rows; it doesn't matter what + * these are set to and since we have a random permutation it doesn't + * matter which of the 24 nonempty tiles we pick for the actual goal. + */ + for (i = 0; i < 13; i++) { + assign_tile(board->goal, tiles[i], i); } tiles[24] = TILE_EMPTY; shuffle(tiles, 25); - memset(board->game, 0, sizeof board->game); + for (i = 0; i < 25; i++) { - unsigned x = i/5, y = i%5; - uint_fast32_t position; - - position = board_position(x, y); - if (tiles[i] != TILE_EMPTY) { - if (tiles[i] & 1) board->game[0] |= position; - if (tiles[i] & 2) board->game[1] |= position; - if (tiles[i] & 4) board->game[2] |= position; - } else { - board->game[3] = ~position; - board->x = x; - board->y = y; + assign_tile(board->game, tiles[i], i); + + if (tiles[i] == TILE_EMPTY) { + board->game[3] = (1ul<x = i%5; + board->y = i/5; } }