maiohuman.blogg.se

Simple minesweeper python code
Simple minesweeper python code













simple minesweeper python code

You find the numbered tiles with that number of discovered mines around it so you know the rest around it are not mines.Ĭonstraint satisfaction takes longer, but it can achieve better results.

simple minesweeper python code

You will require random guessing for any solution you implement.įinding solutions w an exact answer is what you already do in minesweeper. finding solutions that definitely had a right answer To get you started, some of the techniques I used was:Ģ. That means that there is a chance that you click on a mine no matter what algorithm you choose. You probably realize this, but minesweeper is actually not a deterministic game. Figure out what states and attributes you have for the board as well as for each tile. I actually built this for one of my classes and made a GUI from it.ĭraw out the representation of the board. If you get that far and get stuck come back and update us and ask for more. If it hits a mine that's game over, start again. To start you can either have it use a predetermined set of moves or randomly choose locations until it has something to work with. Then you'll be able to visually check that it's all working as it should up to this point.įrom there you can begin to work on the AI. Figure out how to do that, and print that out. Then you'll want to be able to place numbers in locations, which show how many mines there are adjacent to any given location. That will just show you the location of the mines. So make a routine that takes the board state and prints it out. To keep things simple you'll probably want to make a simple console program. Ideally parameterize it so that you can create a minefield of any given dimensions with any number of mines.įor debugging you'll almost certainly want to be able to view the state of the board. 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. Then figure out how to randomly assign mines to slots in the array. As has been said, figure out how to represent the state of the game in memory.















Simple minesweeper python code