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.