]> git.draconx.ca Git - rrace.git/commitdiff
Very slightly simplify game_reset implementation.
authorNick Bowler <nbowler@draconx.ca>
Wed, 9 Mar 2022 02:07:48 +0000 (21:07 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 9 Mar 2022 02:10:39 +0000 (21:10 -0500)
src/game.c
src/game.h

index ca03830545b7ee76392ce3087b66e8da9c417883..bdb18a1c20f1318f90e75fe348fd96699db36281 100644 (file)
@@ -134,34 +134,28 @@ void game_reset(struct board *board)
        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);
-
-               if (tiles[i] & 1)
-                       board->goal[0] |= position >> 6;
-               if (tiles[i] & 2)
-                       board->goal[1] |= position >> 6;
-               if (tiles[i] & 4)
-                       board->goal[2] |= position >> 6;
+               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;
        }
 
        tiles[24] = TILE_EMPTY;
        shuffle(tiles, 25);
-       memset(board->game, 0, sizeof board->game);
 
+       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;
+                       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] = 0x1ffffff ^ position;
+                       board->game[3] = ~position;
                        board->x = x;
                        board->y = y;
                }
index d17eb992f7fd3d86d19d521b537588c4e1dbe2c5..fb2fe9767135e8bfe97bab3cf2bfe46ab035a9a3 100644 (file)
@@ -45,8 +45,9 @@ struct board {
         *   game[0] - least significant bit of the tile's colour.
         *   game[1] - tile colour.
         *   game[2] - most significant bit of the tile's colour.
-        *   game[3] - the board mask, all bits set except one indicating the
-        *             absense of a tile at this position.
+        *   game[3] - No internal meaning.  The game_reset function will clear
+        *             the bit at the empty position and set all others, and
+        *             game_do_move will adjust it.
         */
        uint_least32_t game[4];