ASE2003
ASE2003
Richard Kaye
http://web.mat.bham.ac.uk/R.W.Kaye/
[email protected]
Birmingham University
ASE2003 – p. 1
Minesweeper
• Minesweeper is a familiar computer game
requiring you to locate the mines in a
minefield without being blown up.
• When skilfully played, the task can be
completed without having to take many risky
guesses!
ASE2003 – p. 2
Minesweeper
• Minesweeper is a familiar computer game
requiring you to locate the mines in a
minefield without being blown up.
• When skilfully played, the task can be
completed without having to take many risky
guesses!
• In fact the complexity of minesweeper is related to an
important unsolved problem in mathematics, which in
turn relates to cracking codes on the internet.
ASE2003 – p. 2
Playing the game
ASE2003 – p. 3
Playing the game
ASE2003 – p. 3
Playing the game
ASE2003 – p. 3
Playing the game
ASE2003 – p. 3
Playing the game
ASE2003 – p. 3
Playing the game
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
ASE2003 – p. 4
A puzzle
ASE2003 – p. 4
A puzzle
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 play
well. How difficult is it?
ASE2003 – p. 5
What is the question?
• Minesweeper appears to be difficult to play
well. How difficult is it?
• To formulate this question precisely we need
to specify what we mean by playing ‘well’. We
can at least assume a good player will not
take stupid risks:
ASE2003 – p. 5
What is the question?
• Minesweeper appears to be difficult to play
well. How difficult is it?
• To formulate this question precisely we need
to specify what we mean by playing ‘well’. We
can at least assume a good player will not
take stupid risks:
• We want to play in such a way that we never
make a risky move when there is some
square which can be uncovered safely.
ASE2003 – p. 5
The consistency problem
• Given a minesweeper configuration, is it
consistent? I.e., could it have arisen from
some pattern of mines?
ASE2003 – p. 6
The consistency problem
• Given a minesweeper configuration, is it
consistent? I.e., could it have arisen from
some pattern of mines?
• To determine if a square is free of any mines
change the configuration marking it with a
mine. Then ask if the result is consistent. If
not, it is safe to clear the square!
ASE2003 – p. 6
How might we solve it?
• Problems like this are quite general and
require a computer algorithm or computer
program as the solution.
ASE2003 – p. 7
How might we solve it?
• Problems like this are quite general and
require a computer algorithm or computer
program as the solution.
• There is an algorithm that solves this problem
and solves the consistency problem. All you
need to do is go though all the different
combinations for the mines on the minefield in
turn.
ASE2003 – p. 7
So what’s the difficulty?
• Typical minesweeper configurations have
many squares. (The so-called ‘advanced’
board has 99 mines in 480 squares, that’s
5602209993374213454290589857758. . . 9570631168198385673295159633481600
ASE2003 – p. 8
So what’s the difficulty?
• Typical minesweeper configurations have
many squares. (The so-called ‘advanced’
board has 99 mines in 480 squares, that’s
5602209993374213454290589857758. . . 9570631168198385673295159633481600
ASE2003 – p. 8
Can we avoid this difficulty?
• Possibly. In fact no-one knows the answer to
this question.
ASE2003 – p. 9
Can we avoid this difficulty?
• Possibly. In fact no-one knows the answer to
this question.
• We can hope for a fast or efficient algorithm
that takes time proportional to a fixed
polynomial in the number of squares in the
input configuration (Polynomial Time) rather
than Exponential Time.
ASE2003 – p. 9
Can we avoid this difficulty?
• Possibly. In fact no-one knows the answer to
this question.
• We can hope for a fast or efficient algorithm
that takes time proportional to a fixed
polynomial in the number of squares in the
input configuration (Polynomial Time) rather
than Exponential Time.
• However, it seems unlikely that such an
algorithm exists.
ASE2003 – p. 9
A wire
ASE2003 – p. 10
A wire
ASE2003 – p. 10
A wire
ASE2003 – p. 10
A wire
ASE2003 – p. 10
A splitter
ASE2003 – p. 11
A splitter
ASE2003 – p. 11
A crossover
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
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
If r is free. . .
ASE2003 – p. 15
An OR gate
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 in
minesweeper, so. . .
ASE2003 – p. 17
NP-completeness
• We can build any logic circuits in
minesweeper, so. . .
• An algorithm solving the minesweeper
consistency problem would allow us to solve
questions about simple (propositional) logic.
ASE2003 – p. 17
NP-completeness
• We can build any logic circuits in
minesweeper, so. . .
• An algorithm solving the minesweeper
consistency problem would allow us to solve
questions about simple (propositional) logic.
• Many other problems can be phrased as logic
problems and therefore reduced to
minesweeper consistency problems.
ASE2003 – p. 17
NP-completeness
• We can build any logic circuits in
minesweeper, so. . .
• An algorithm solving the minesweeper
consistency problem would allow us to solve
questions about simple (propositional) logic.
• Many other problems can be phrased as logic
problems and therefore reduced to
minesweeper consistency problems.
• The Minesweeper Consistency Problem is
NP-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 NP
problem has an efficient algorithm. No-one
knows the answer! A prize of $1,000,000 has
been offered for a proof either way.
ASE2003 – p. 19
The P equals NP question
• The ‘P equals NP question’ asks if every NP
problem has an efficient algorithm. No-one
knows the answer! A prize of $1,000,000 has
been 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