We already generated Minesweeper fields, but someone really has to sweep those generated mines before PCG blows up!
Your task is to write a Minesweeper Solver that is compatible with a slightly modified version of the accepted solution of “Working Minesweeper” (actions are separated by spaces to allow for larger fields).
Input: A Minesweeper field, fields separated by spaces. The first line denotes the total number of mines.
x
: Untouched!
: Flag- Digit: Number of mines around that field
Example:
10
0 0 1 x x x x x
0 0 2 x x x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
Output: Your next step in the format action row column
(starting at zero)
Valid Actions:
0
: Open it1
: Place a flag
Example:
0 1 2
Rules:
- You write a complete program that takes a single field as input (either STDIN or command line arguments) and outputs a single action (STDOUT). Therefore, you cannot save states, except for
!
. - Your choice must follow the best odds for survival. (i.e. if there is a 100% safe move, take it)
- This is code-golf; the shortest solution (in UTF-8 bytes) wins
Tests:
These tests serve the purpose of testing for common clear situations; your program must work for every test field.
In:
4
x x x x
1 2 x x
0 1 2 x
0 0 1 x
Out (any of these):
1 1 2
0 0 2
0 1 3
In:
2
x x x
1 ! x
1 1 x
Out (any of these):
0 0 0
0 0 1
0 1 2
0 2 2
1 0 2
In:
10
x x x x x x x x
1 3 3 x x x x x
0 1 ! 3 3 4 x x
0 2 3 ! 2 3 x x
0 1 ! 2 2 ! x x
Out (any of these):
1 1 5
1 0 2
In:
2
x x x
2 3 1
! 1 0
Out (any of these):
0 0 1
1 0 0
1 0 2
0 0 2
or0 1 3
. I can't see how either one of the those would be considered safe. (I must not be good enough at minesweeper...) \$\endgroup\$F
orP
looks better flag than!
:) \$\endgroup\$