From 9c607adb676ac808818a0ea4b46f78715d05373c Mon Sep 17 00:00:00 2001 From: squee72564 Date: Sat, 6 Jan 2024 17:03:17 -0800 Subject: [PATCH] edded some new invalid positions for board setup I added the adjacent cells to the 0,0 cell; this means that when opening up 0,0 the user will always see a valid move to make This along with the other corners will help the solver find a unambiguous map in a shorter time --- views/minesweeper_game_screen.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/views/minesweeper_game_screen.c b/views/minesweeper_game_screen.c index 64bcac5..84711f8 100644 --- a/views/minesweeper_game_screen.c +++ b/views/minesweeper_game_screen.c @@ -147,7 +147,7 @@ static void setup_board(MineSweeperGameScreen* instance) { MineSweeperGameScreenTileType tiles[MINESWEEPER_BOARD_MAX_TILES]; memset(&tiles, MineSweeperGameScreenTileNone, sizeof(tiles)); - // Place tiles everywhere randomly except the corners to help the solver + // Randomly place tiles except in the corners to help guarantee solvability for (uint16_t i = 0; i < num_mines; i++) { uint16_t rand_pos; @@ -160,11 +160,15 @@ static void setup_board(MineSweeperGameScreen* instance) { x = rand_pos / board_width; y = rand_pos % board_width; - } while (tiles[rand_pos] == MineSweeperGameScreenTileMine || - (rand_pos == 0) || - (x==0 && y==board_width-1) || - (x==board_height-1 && y==0) || - (rand_pos == board_tile_count-1)); + bool is_invalid_position = ((rand_pos == 0) || + (x==0 && y==1) || + (x==1 && y==0) || + rand_pos == board_tile_count-1 || + (x==0 && y==board_width-1) || + (x==board_height-1 && y==0)); + + + } while (tiles[rand_pos] == MineSweeperGameScreenTileMine || is_invalid_position); tiles[rand_pos] = MineSweeperGameScreenTileMine; }