Showing posts with label Minesweeper. Show all posts
Showing posts with label Minesweeper. Show all posts

Friday, September 16, 2016

Minesweeper Postmortem Analysis Post

The minesweeper AI competition didn't go as I expected, my AI underachieved. It was confusing why it performed so poorly. The AI was checking for probability of where the mines could be and it was marking tiles that is knew was mines. So i was confused why it was so bad.

After the class I was talking to a friend about how my AI should have been better because I am using probability. Then I remembered that I assign a probability to every hidden tile. The probability is based on how many mines are adjacent to that tile. Which means if the hidden tile is surrounded by other hidden tiles, the probability that is will be a mine is low. So when the AI couldn't guarantee that the tile picked is free. It picked a random tile with a low probability. Since my probability was calculated incorrectly, my Algorithm was flawed.

Monday, September 12, 2016

Minesweeper Code Report

I used numerous techniques in my minesweeper AI, but the one that was utilized the most was one that marked mines. When a game starts it picks the tile in the middle, this way the AI will hopefully get a good number of open tiles. After the first turn the algorithm starts to go through its algorithm.



The algorithm starts at index zero and runs through all the tiles' indexes. If the index is hidden it is pushed into a hidden tile vector. Then the algorithm does its first big check to save time and cpu power. It checks to see if the current index is revealed and if the number of adjacent mines is bigger than zero. The AI doesn't care if the tile is hidden or if the number is zero because it can't do anything about those tiles.



The algorithm checks to see how many tiles are hidden. If the number of hidden tiles are equal to the number of adjacent mines, it knows that those tiles are all mines. The new tiles that are marked as mines are check to see if they are already in the mine index vector. If they are not in the vector they are pushed in. Once the mines are marked then it goes through the adjacent tiles of the index that it is at and see if any of them are are mines. If one of them isn't a mine then it returns that index.



If the algorithm goes through all that and it still can't guarantee a index that isn't a mine. It uses the vector that has all the hidden tiles and deletes all the indexes that are mines. Then it just picks a random tile.



The algorithm wins between 52-57 percent. If I have more time, I want to implement a feature that uses a vector to hold possible adjacent and mine-less hidden tiles. Then when it checks to see if a mine is in one of those tiles. It will just delete that index. Then if the vector size is greater than zero after checking all the adjacent hidden tiles, it will just return the first element. This will hopefully improve the win rate because it will be utilizing this method to make educated guesses instead of just random guesses.

Friday, September 2, 2016

Minesweeper Planning Post

The assignment is to make an artificial opponent that can beat minesweeper. Since I have never really beaten minesweeper, the first step is to learn how to play. So I looked up tutorials on how to play correctly. Then I was playing some games so that I can get the feel for what the AI will be attempting to accomplish.

The goal is to make an AI that can beat every game of minesweeper without taking a long time. The AI will be programmed to play the game just like a human. It will pick tiles that it knows aren't mines, while marking tiles it knows are mines. Even though the AI will follow an algorithm that follows the thought process of a human, it should be better because it won't make human mistakes.

The AI will basically be checking a whole bunch of cases to see what tile to pick. Even thought a computer can run over a billion calculations a second. I can't have the AI check each case on each tile. It will not only become a waste of time but it will also be a waste of the CPU. So the AI will check to see what tile is the best to run the numerous conditions on. Since minesweeper is a logic game one needs to have some evidence to pick a non-mine tile. Therefore the first pass of the algorithm the tiles that have open sides will be selected. If all the sides are opened or marked as mines, it will pass that tile. This will hopefully cut back on time and CPU power making the algorithm faster.