Another class I’m taking this year is artificial opponents. Our first assignment is to write an AI for minesweeper, and in this post I’ll detail as to how I plan to write the AI. One thing to note is that I’ll never be able to win 100% of the time, so I need to write plans for different situations in order to increase my AI’s chance of winning.
- Start the game and choose a random space. (And pray that it uncovers a good amount)
- Scan the grid for any numbered spaces.
- Once a numbered space is found – check to see how many uncovered spaces surround it. If the amount of uncovered spaces matches the number on the space, we can determine that those spaces are mines.
- As a secondary check, if we find a numbered space that already has all its mines marked around it – we can safely say that all other spaces surrounding the original space are safe, so we’ll uncover those.
This plan will safely uncover a good amount of the game board, however, there will be situations in which there will be no clear solutions. That’s why there’s plan b.
Plan A just won’t cut it here
- Mark of a specific area of the grid, (this will probably be dynamic and determined by how many numbered spaces I have to work with)
- Once I have my space, I’ll need to run an algorithm that determines the chances of a space having a mine.
- Once I have my list of spaces, I’ll uncover the spot that has the lowest chance of having a mine. (If there are multiple with the same low chance I’ll just choose randomly.
- From there, proceed with plan A until the need for plan B arises again.
If I end up having more plans or improvements to the strategies I listed above while actually coding the AI, I’ll be sure to detail them in future blog posts.