Minesweeper Solver Marina Maznikova Artificial Intelligence II Fall 2011

Minesweeper Solver
Marina Maznikova
Artificial Intelligence II Fall 2011
Agenda
1.
2.
3.
4.
5.
6.
The Minesweeper Game
Theoretical Background
Solving Agents
Evaluation
Extension
Summary
2
1. The Minesweeper Game
3
1. The Minesweeper Game
4
2. Theoretical Background

NP-completeness (8-SAT)

Solving approaches:
 Constraints
 Reinforcement
learning
5
3. Solving Agents

Random agent (RA)
6
3. Solving Agents

Random agent (RA)

Simple agent (SA)
 Only
mines remain around
a square => mark as mine
 All mines around a square
are marked => open
neighbors
7
3. Solving Agents

Greedy agent (GA)
 Start with (0, 0)
 Search for mine and safe squares
 If nothing found
2/3
 Calculate for each square the
density of mines on the squares
around it
 For each square, take the maximum
of the densities calculated for this
 If no opened neighbors => ½
2/3
 Open the square with the minimum
“probability” of mine
1/5
8
3. Solving Agents

Constraints agent (CA)
 Start
with (0, 0)
 Consider only the relevant squares
 Model the problem as constraints problem
Mine square => 1; opened square => 0
 Sum of mines around opened squares
 Number of mines in the game

9
3. Solving Agents

Constraints agent (CA)
 Backtracking
for 3000 results
 Calculate how many times
each square is mine
 Mark mine squares and open
safe squares
 If no such squares found,
open the square with the
lowest sum of mines
00100000
…
01111101
11111101
12322202
10
3. Solving Agents

Constraints agent (CA)
 Problem:
Exponential algorithm
Impossible to generate always all the solutions
 Time

11
3. Solving Agents

Constraints agent (CA)
 Problem:
Exponential algorithm
Impossible to generate always all the solutions
 Time


“Simple” constraints agent (SCA)
 Start
with (0, 0)
 Search for mine and safe squares
 If nothing found, use constraints
12
4. Evaluation

Observed variables
 Overall
result
 Average squares revealed per game
 Time

Tests (20.000 games)
 Agent
comparison on standard board
 Variation of board size
 Variation of mine density
13
4. Evaluation: Standard Game
Overall Result
5 000
98
748
0
-6 192
-5 000
50
45
46
SA
GA
56
40
-10 000
-15 000
60
Average Moves
55
30
20
-18 572
-20 000
-20 000
10
-25 000
0
RA
SA
GA
CA
SCA
14
RA
Problem of too
many solution
possibilities
CA
SCA
14
4. Evaluation: Standard Game
Backtracking
is expensive
Time (minutes)
60
50.72
50
40
30
20
13.74
7.02
10
0.09
0.44
RA
SA
0
GA
CA
SCA
15
4. Evaluation: Board Size
Overall Result
Better performance
on larger and
smaller boards
Average Moves
10 000
70
5 000
60
0
50
-5 000
40
-10 000
30
-15 000
20
-20 000
10
-25 000
0
RA
SA
Standard
GA
Small
CA
Large
SCA
RA
SA
Standard
Exception:
backtracking
GA
CA
Small
Large
SCA
16
4. Evaluation: Board Size
Larger boards require
more time, especially
when backtracking is
used
Time (minutes)
180
160
140
120
100
80
60
40
20
0
RA
SA
GA
Standard
Small
CA
SCA
Large
17
4. Evaluation: Mine Density
The higher the mine
density, the worse
the performance
Greedy strategy is
not good for few
mines
Average Moves
Overall Result
15 000
90
10 000
80
5 000
70
60
0
50
-5 000
40
-10 000
30
-15 000
20
-20 000
10
-25 000
0
RA
40 mines
SA
GA
20 mines
CA
60 mines
SCA
RA
40 mines
SA
GA
20 mines
CA
SCA
60 mines
18
4. Evaluation: Mine Density
Time (minutes)
300
CA and SCA:
More mines
require more time
250
200
150
100
50
0
RA
RA, SA, and GA:
More mines
require less time
SA
GA
40 mines
20 mines
CA
SCA
60 mines
19
5. Extension

Possibility to open 5% of the squares as
joker
 RA: At
the beginning of the game
 SA: In case no mine/safe squares are found
 GA: In case of two squares with the same
mine “probability”
 CA and SCA: On start, in case of too many
solutions of the problem, and when two
squares are “safest”
20
5. Extension: Evaluation
Overall Result
Jokers improve
the performance
20 000
Average Moves
100
90
80
70
60
50
40
30
20
10
0
15 000
10 000
5 000
0
-5 000
-10 000
-15 000
-20 000
-25 000
RA
SA
GA
CA
Without joker
With joker
SCA
RA
SA
GA
Without joker
… and make unsafe
strategies inefficient
CA
SCA
With joker
21
5. Extension: Evaluation
Time increases
because of the
more moves
Time (minutes)
100
90
80
70
60
50
40
30
20
10
0
RA
SA
GA
Without joker
CA
SCA
With joker
22
6. Summary

Backtracking is expensive
and for many solution
possibilities inefficient
 Solution:



Sets
The Greedy strategy is not
a good strategy
The higher the mine
density, the difficult the
game
Jokers help and make
unsafe move strategies
inefficient
23