![]() ![]() To see an actual example of this, look at the two 1's at the end of the first row. A key strategy is to look at the cells that are shared between different cells that contain numbers, and use this to either work out cells that must be placed, or perhaps, and equally useful, cells that must not be placed with a mine. Sometimes when solving minesweepers you will see there are certain cells that must be placed. With the 0 in Row 1 Column 1 (R1C1) you can mark three X's around it, there four to mark around the 0 in R5C8 and there are the maximum eight X's to mark around the 0 in cell R7C4. You must use logic alone to work out where all the mines are and locate them.įirst off, it is easy to work out what to do with 0s: there can't be mines in any of the touching cells, so mark these off with a cross. This tells you how many of the cells surrounding that number that touch it (including diagonals) contain mines. In minesweeper, some cells contain numbers in the start of the puzzle. Minesweeper is quite a well known logic puzzle because it has been one of the games that comes with PCs in various guises for quite some time. If we calculate all possible combinations in each group separately, we certainly gain some performance boost.We have lots of fantastic puzzle magazines for you to play here at Puzzle Magazines, and since writing this guide we've added a Minesweeper Magazine too! That means we can group them into sections: You might notice, that some of these cells are located closely to each other, while some of them do not even have common neighbours. Considering we need not only to calculate all possible variations, but apply each of them on the field and check whether they satisfy game conditions, then processing could take hours! Can we somehow reduce this number? Let's analyse this case further. According to formula, it will result inĬombinations. Thus all of them can be taken into account while calculating of combinations of possible mines placement. There are 27 closed cells which border to one or more opened ones. Readability and simplicity are one of the most crucial qualities of the code imo, so we need to pay some attention to this aspect as well. Very often it is even challenging to understand what exactly such algorithm is doing after coming back to it after some time. Though for sure, it is possible to create such algorithm ourselves, but even after putting significant efforts there, most probably it will result in something we won't be happy to work with in future. One can just imagine the amount of "for" loops we might need for this. And then finally commit a decision (make a move). Then based on remaining combinations for each cell we need to calculate probability of whether it is empty or contains a mine. Then filter out the list of combinations based on applying each combination and checking whether it fits the field conditions or not. To begin we need to find all possible combinations. Secondly, it will certainly introduce some programmatic complexity. According to our indispensable Big O Cheat Sheet it is horrible :) However it faces several problems.įirst of all, the number of all possible combinations can be (and on a large field often will be) too huge. How exactly are we going to implement this? At first sight, the idea of calculating all possible combinations of mines placement and picking the most reasonable one seems as the way to go. So let's "teach" our Computer player how to handle these cases! Actually there are plenty of similar cases, and those who play Minesweeper often don't even bother to calculate them each time, they simply instantly recognise familiar patterns. But after calculating all possible combinations of mines placements at these three closed cells, it becomes clear that only one combination is possible (as flagged in the picture). When looking at every opened cell one by one, it is impossible to determine where exactly is the mine(s) in the neighbour cells. Every Minesweeper player knows that there are many cases when one must consider two or more cells at a time to make their next decision. However it appeared, it's solving abilities are limited - it can analyse individual cells only. We ended with a program which can efficiently iterate through cells on a field and make a decision which of their neighbours contains a mine or not. In the first article of the series we've implemented a basic Minesweeper solving algorithm for Minesweeper Battle game. ![]()
0 Comments
Leave a Reply. |