![]() ![]() Often Minesweeper games will make it so that you can't lose on your first move. When you start out with the board completely covered, you could end up uncovering a mine on your first square and losing the game immediately. I mentioned that in more advanced games, some guessing might be necessary, and that is also the case with the first square that you uncover in game. One reason why programmers like Minesweeper is because it is mostly a game of logic and you can use the numbered squares to figure out where the mines are. This code creates a consistent Minesweeper board with randomly placed mines. Just iterate through the mine_coordinates and assign the cell at each mine coordinate in the board matrix a 9, and then look at each of its neighbors in and increment the value in that square by one, as long as it's not a mine. If 0 <= n <= cols-1 and 0 <= n <= rows-1 and n not in mine_coordinates: We'll create a 9 x 9 board with 10 mines. In the next post on playing Minesweeper we will get into this more, but for now we are just going to generate the board. In more difficult games, there may be an element of guessing involved, when you are left with squares that could equally likely be mines or safe squares. The game continues, and in some games you will be able to win just by using this strategy. If there is a square that is obviously not a mine, then it can be safely uncovered. You can see that the red stars have to be mines because the 1 squares diagonal to each of them have no other adjacent neighbors that could be a mine except for the one covered square, so therefore, that square must be a mine. Here the purple dot is the starting point, and then the two red stars are covered squares that have to be mines. ![]() So then you can go around that perimeter and see if you can identify any unknown squares that would definitely be mines, or definitely be safe. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |