From a0af2394f25fa36cdf70c99c0f435622c5a8435b Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 11 Jun 2022 22:57:55 -0400 Subject: [PATCH] Add a debug mode to make the game stupidly easy. Implement an alternate version of game_reset, selectable by editing the code, which always produces games that are winnable in just one move. This makes it much faster to manually test behaviour after game end. --- src/game.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/game.c b/src/game.c index 2ad3a7e..4946f8d 100644 --- a/src/game.c +++ b/src/game.c @@ -168,6 +168,33 @@ void game_reset(struct board *board) board->y = y; } } + +/* Uncomment to make every game stupidly easy -- winnable in 1 move */ +#if 0 + /* Force empty space to the border */ + if (board_position(board->x, board->y) & GOAL_MASK) { + switch (rng_uniform_int(4)) { + case 0: game_do_move(board, board->x, 0); break; + case 1: game_do_move(board, board->x, 4); break; + case 2: game_do_move(board, 0, board->y); break; + case 3: game_do_move(board, 4, board->y); break; + } + } + + /* Force goal to match the current board */ + for (i = 0; i < 3; i++) { + board->goal[i] = (board->game[i] & GOAL_MASK) >> GOAL_SHIFT; + } + + /* Move empty space back to the centre */ + if (board->x == 0 || board->x == 4) { + game_do_move(board, 1+rng_uniform_int(3), board->y); + } + + if (board->y == 0 || board->y == 4) { + game_do_move(board, board->x, 1+rng_uniform_int(3)); + } +#endif } uint_fast32_t game_do_move(struct board *board, int x, int y) -- 2.43.2