Skip to content

Commit

Permalink
edded some new invalid positions for board setup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
squee72564 committed Jan 7, 2024
1 parent ce401f6 commit 9c607ad
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions views/minesweeper_game_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) ||

Check failure on line 163 in views/minesweeper_game_screen.c

View workflow job for this annotation

GitHub Actions / Build Minesweeper for release channel

unused variable 'is_invalid_position' [-Werror=unused-variable]
(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);

Check failure on line 171 in views/minesweeper_game_screen.c

View workflow job for this annotation

GitHub Actions / Build Minesweeper for release channel

'is_invalid_position' undeclared (first use in this function)

tiles[rand_pos] = MineSweeperGameScreenTileMine;
}
Expand Down

0 comments on commit 9c607ad

Please sign in to comment.