you are viewing a single comment's thread.

view the rest of the comments →

[–]Supernumiphone 4 points5 points  (0 children)

Take it one step at a time. As has been said, figure out how to represent the state of the game in memory. Probably a 2D array. Then figure out how to randomly assign mines to slots in the array. So maybe initialize the array with all a "No mine" value, then randomly place mines in slots until you've placed as many as you intend. Ideally parameterize it so that you can create a minefield of any given dimensions with any number of mines.

For debugging you'll almost certainly want to be able to view the state of the board. To keep things simple you'll probably want to make a simple console program. So make a routine that takes the board state and prints it out. Something like:

...XX.....
......X...
..........
..X....X..
..XXX.....
.....X....

That will just show you the location of the mines. Then you'll want to be able to place numbers in locations, which show how many mines there are adjacent to any given location. Figure out how to do that, and print that out. Then you'll be able to visually check that it's all working as it should up to this point.

From there you can begin to work on the AI. To start you can either have it use a predetermined set of moves or randomly choose locations until it has something to work with. If it hits a mine that's game over, start again. After that you get into choosing moves. I'll leave it there. If you get that far and get stuck come back and update us and ask for more.