3 ms·
There is an even simpler approach: for maps with K total cells there would be always K-1 unclicked cells and a single clicked cell after the first click, so you
by lifthrasiir 6y ago
There is an even simpler approach: for maps with K total cells there would be always K-1 unclicked cells and a single clicked cell after the first click, so you can generate K-1 cells and insert a "gap" corresponding to the first clicked cell. This works because every unclicked cell has an equal probability to become a mine.
- mkl 6y agoEven simpler still is to just move any mine clicked on in the first move into an empty square before processing the clicked square as normal.
- lifthrasiir 6y agoThat needs a list of empty cells, otherwise you need to retry and get the same issue as the map-wide regeneration.
- mkl 6y agoWell you have all the cells in an array so that's easy enough. Pick a cell at random until you find an empty one, which won't take long. There's no regeneration, just moving one mine to an easy to find place.
- dmurray 6y agoThis is what actually happens in the Windows original (it doesn't look for a random empty square, it tries them in reading order starting from the top left).