-->

Wednesday, November 2, 2011

How minesweeper works so that the first click you make is not on a mine?


Suppose the box you click first contain a mine, the mine is automatically moved to the upper left corner of the board. If the upper-left corner is occupied the mine is moved to the right of it.
The crucial code is embedded in the StepSquare function. Thedisassembled code can be viewed here.
The StepSquare function is invoked by Minesweeper every time an unmarked square is clicked. The function checks if it is the first click, and that the square being clicked is a mine. It then tries to move the mine to the upper-left corner. If unsuccessful it tries the square to the right of it. If all of the first row is occupied by mines, the function tries to put the mine in the leftmost square of the row below, and so on.

No comments:

Post a Comment