View
8
Download
0
Category
Preview:
Citation preview
How Complicated is Minesweeper?Richard Kaye
http://web.mat.bham.ac.uk/R.W.Kaye/
R.W.Kaye@bham.ac.uk
Birmingham University
ASE2003 – p. 1
Minesweeper
• Minesweeper is a familiar computer gamerequiring you to locate the mines in aminefield without being blown up.
• When skilfully played, the task can becompleted without having to take many riskyguesses!
ASE2003 – p. 2
Minesweeper
• Minesweeper is a familiar computer gamerequiring you to locate the mines in aminefield without being blown up.
• When skilfully played, the task can becompleted without having to take many riskyguesses!
• In fact the complexity of minesweeper is related to animportant unsolved problem in mathematics, which inturn relates to cracking codes on the internet.
ASE2003 – p. 2
Playing the game
Does (2,6) have a mine?
ASE2003 – p. 3
Playing the game
These must have mines
ASE2003 – p. 3
Playing the game
Does (5,2) have a mine?
ASE2003 – p. 3
Playing the game
If so, does (5,7) have a mine?
ASE2003 – p. 3
Playing the game
If (5,2) and (5,7) have mines
ASE2003 – p. 3
Playing the game
If (5,2) has a mine but (5,7) hasn’t
ASE2003 – p. 3
Playing the game
If (5,2) is clear
ASE2003 – p. 3
Playing the game
So (2,6) is clear!
ASE2003 – p. 3
A puzzle
Determine the location of all mines!
ASE2003 – p. 4
A puzzle
Can this be a mine?
ASE2003 – p. 4
A puzzle
If this is a mine the one next to it is clear. . .
ASE2003 – p. 4
A puzzle
So. . .
ASE2003 – p. 4
A puzzle
. . . which is impossible!
ASE2003 – p. 4
A puzzle
Therefore. . .
ASE2003 – p. 4
A puzzle
Solved!
ASE2003 – p. 4
What is the question?
• Minesweeper appears to be difficult to playwell. How difficult is it?
ASE2003 – p. 5
What is the question?
• Minesweeper appears to be difficult to playwell. How difficult is it?
• To formulate this question precisely we needto specify what we mean by playing ‘well’. Wecan at least assume a good player will nottake stupid risks:
ASE2003 – p. 5
What is the question?
• Minesweeper appears to be difficult to playwell. How difficult is it?
• To formulate this question precisely we needto specify what we mean by playing ‘well’. Wecan at least assume a good player will nottake stupid risks:
• We want to play in such a way that we nevermake a risky move when there is somesquare which can be uncovered safely.
ASE2003 – p. 5
The consistency problem
• Given a minesweeper configuration, is itconsistent? I.e., could it have arisen fromsome pattern of mines?
ASE2003 – p. 6
The consistency problem
• Given a minesweeper configuration, is itconsistent? I.e., could it have arisen fromsome pattern of mines?
• To determine if a square is free of any mineschange the configuration marking it with amine. Then ask if the result is consistent. Ifnot, it is safe to clear the square!
ASE2003 – p. 6
How might we solve it?
• Problems like this are quite general andrequire a computer algorithm or computerprogram as the solution.
ASE2003 – p. 7
How might we solve it?
• Problems like this are quite general andrequire a computer algorithm or computerprogram as the solution.
• There is an algorithm that solves this problemand solves the consistency problem. All youneed to do is go though all the differentcombinations for the mines on the minefield inturn.
ASE2003 – p. 7
So what’s the difficulty?
• Typical minesweeper configurations havemany squares. (The so-called ‘advanced’board has 99 mines in 480 squares, that’s5602209993374213454290589857758. . . 9570631168198385673295159633481600
or over 10100 possible ways of placing these99 mines.)
ASE2003 – p. 8
So what’s the difficulty?
• Typical minesweeper configurations havemany squares. (The so-called ‘advanced’board has 99 mines in 480 squares, that’s5602209993374213454290589857758. . . 9570631168198385673295159633481600
or over 10100 possible ways of placing these99 mines.)
• No known method can search through allthese possibilities in reasonable time.
ASE2003 – p. 8
Can we avoid this difficulty?
• Possibly. In fact no-one knows the answer tothis question.
ASE2003 – p. 9
Can we avoid this difficulty?
• Possibly. In fact no-one knows the answer tothis question.
• We can hope for a fast or efficient algorithmthat takes time proportional to a fixedpolynomial in the number of squares in theinput configuration (Polynomial Time) ratherthan Exponential Time.
ASE2003 – p. 9
Can we avoid this difficulty?
• Possibly. In fact no-one knows the answer tothis question.
• We can hope for a fast or efficient algorithmthat takes time proportional to a fixedpolynomial in the number of squares in theinput configuration (Polynomial Time) ratherthan Exponential Time.
• However, it seems unlikely that such analgorithm exists.
ASE2003 – p. 9
A wire
Minesweeper is complicated by the fact thatsomething in one part of the board can affect the
whole board.
ASE2003 – p. 10
A wire
Minesweeper is complicated by the fact thatsomething in one part of the board can affect the
whole board.
ASE2003 – p. 10
A wire
Minesweeper is complicated by the fact thatsomething in one part of the board can affect the
whole board.
ASE2003 – p. 10
A wire
Minesweeper is complicated by the fact thatsomething in one part of the board can affect the
whole board.
ASE2003 – p. 10
A splitter
Use this to split, bend, or ‘invert’ wires.
ASE2003 – p. 11
A splitter
Use this to split, bend, or ‘invert’ wires.
ASE2003 – p. 11
A crossover
Use this to cross two wires over!
ASE2003 – p. 12
A crossover
Use this to cross two wires over!
ASE2003 – p. 12
A crossover
Use this to cross two wires over!
ASE2003 – p. 12
A crossover
Use this to cross two wires over!
ASE2003 – p. 12
An XOR gate
ASE2003 – p. 13
An XOR gate
ASE2003 – p. 13
An XOR gate
ASE2003 – p. 13
An AND gate
An AND gate. . .ASE2003 – p. 14
An AND gate
. . . and its internal wires.ASE2003 – p. 14
An AND gate
If t is a mine. . .ASE2003 – p. 14
An AND gate
If t is not a mine. . .ASE2003 – p. 14
An OR gate
An OR gate. . .
ASE2003 – p. 15
An OR gate
. . . with the internal wires shown.
ASE2003 – p. 15
An OR gate
If r is free. . .
ASE2003 – p. 15
An OR gate
If r has a mine (case 1). . .
ASE2003 – p. 15
An OR gate
If r has a mine (case 2). . .
ASE2003 – p. 15
Minesweeper electronics
• Wire: allows us to carry signals around
ASE2003 – p. 16
Minesweeper electronics
• Wire: allows us to carry signals around• Splitter: allows us to bend, split and invert
signals in wires
ASE2003 – p. 16
Minesweeper electronics
• Wire: allows us to carry signals around• Splitter: allows us to bend, split and invert
signals in wires• Crossover: allows us to make arbitrary
circuits in the plain
ASE2003 – p. 16
Minesweeper electronics
• Wire: allows us to carry signals around• Splitter: allows us to bend, split and invert
signals in wires• Crossover: allows us to make arbitrary
circuits in the plain• Logic gates: NOT AND OR XOR, etc.
ASE2003 – p. 16
NP-completeness
• We can build any logic circuits inminesweeper, so. . .
ASE2003 – p. 17
NP-completeness
• We can build any logic circuits inminesweeper, so. . .
• An algorithm solving the minesweeperconsistency problem would allow us to solvequestions about simple (propositional) logic.
ASE2003 – p. 17
NP-completeness
• We can build any logic circuits inminesweeper, so. . .
• An algorithm solving the minesweeperconsistency problem would allow us to solvequestions about simple (propositional) logic.
• Many other problems can be phrased as logicproblems and therefore reduced tominesweeper consistency problems.
ASE2003 – p. 17
NP-completeness
• We can build any logic circuits inminesweeper, so. . .
• An algorithm solving the minesweeperconsistency problem would allow us to solvequestions about simple (propositional) logic.
• Many other problems can be phrased as logicproblems and therefore reduced tominesweeper consistency problems.
• The Minesweeper Consistency Problem isNP-complete.
ASE2003 – p. 17
Some interesting NP problems
• The travelling salesman problem
ASE2003 – p. 18
Some interesting NP problems
• The travelling salesman problem• Many other problems is scheduling, packing,
decision maths, etc.
ASE2003 – p. 18
Some interesting NP problems
• The travelling salesman problem• Many other problems is scheduling, packing,
decision maths, etc.• Other games, such as Tetris
ASE2003 – p. 18
Some interesting NP problems
• The travelling salesman problem• Many other problems is scheduling, packing,
decision maths, etc.• Other games, such as Tetris• Factorizing integers
ASE2003 – p. 18
Some interesting NP problems
• The travelling salesman problem• Many other problems is scheduling, packing,
decision maths, etc.• Other games, such as Tetris• Factorizing integers• Determining a computer user’s secret key
from his public key
ASE2003 – p. 18
The P equals NP question
• The ‘P equals NP question’ asks if every NPproblem has an efficient algorithm. No-oneknows the answer! A prize of $1,000,000 hasbeen offered for a proof either way.
ASE2003 – p. 19
The P equals NP question
• The ‘P equals NP question’ asks if every NPproblem has an efficient algorithm. No-oneknows the answer! A prize of $1,000,000 hasbeen offered for a proof either way.
• It would suffice to show• either that the minesweeper consistency
problem has and efficient solution• or that there is no such algorithm for the
minesweeper consistency problem
ASE2003 – p. 19
Recommended