Transcript
Page 1: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

How Complicated is Minesweeper?Richard Kaye

http://web.mat.bham.ac.uk/R.W.Kaye/

[email protected]

Birmingham University

ASE2003 – p. 1

Page 2: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 3: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 4: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

Does (2,6) have a mine?

ASE2003 – p. 3

Page 5: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

These must have mines

ASE2003 – p. 3

Page 6: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

Does (5,2) have a mine?

ASE2003 – p. 3

Page 7: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

If so, does (5,7) have a mine?

ASE2003 – p. 3

Page 8: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

If (5,2) and (5,7) have mines

ASE2003 – p. 3

Page 9: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

If (5,2) has a mine but (5,7) hasn’t

ASE2003 – p. 3

Page 10: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

If (5,2) is clear

ASE2003 – p. 3

Page 11: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Playing the game

So (2,6) is clear!

ASE2003 – p. 3

Page 12: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

Determine the location of all mines!

ASE2003 – p. 4

Page 13: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

Can this be a mine?

ASE2003 – p. 4

Page 14: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

If this is a mine the one next to it is clear. . .

ASE2003 – p. 4

Page 15: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

So. . .

ASE2003 – p. 4

Page 16: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

. . . which is impossible!

ASE2003 – p. 4

Page 17: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

Therefore. . .

ASE2003 – p. 4

Page 18: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A puzzle

Solved!

ASE2003 – p. 4

Page 19: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

What is the question?

• Minesweeper appears to be difficult to playwell. How difficult is it?

ASE2003 – p. 5

Page 20: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 21: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 22: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

The consistency problem

• Given a minesweeper configuration, is itconsistent? I.e., could it have arisen fromsome pattern of mines?

ASE2003 – p. 6

Page 23: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 24: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

How might we solve it?

• Problems like this are quite general andrequire a computer algorithm or computerprogram as the solution.

ASE2003 – p. 7

Page 25: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 26: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 27: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 28: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Can we avoid this difficulty?

• Possibly. In fact no-one knows the answer tothis question.

ASE2003 – p. 9

Page 29: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 30: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 31: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A wire

Minesweeper is complicated by the fact thatsomething in one part of the board can affect the

whole board.

ASE2003 – p. 10

Page 32: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A wire

Minesweeper is complicated by the fact thatsomething in one part of the board can affect the

whole board.

ASE2003 – p. 10

Page 33: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A wire

Minesweeper is complicated by the fact thatsomething in one part of the board can affect the

whole board.

ASE2003 – p. 10

Page 34: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A wire

Minesweeper is complicated by the fact thatsomething in one part of the board can affect the

whole board.

ASE2003 – p. 10

Page 35: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A splitter

Use this to split, bend, or ‘invert’ wires.

ASE2003 – p. 11

Page 36: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A splitter

Use this to split, bend, or ‘invert’ wires.

ASE2003 – p. 11

Page 37: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A crossover

Use this to cross two wires over!

ASE2003 – p. 12

Page 38: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A crossover

Use this to cross two wires over!

ASE2003 – p. 12

Page 39: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A crossover

Use this to cross two wires over!

ASE2003 – p. 12

Page 40: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

A crossover

Use this to cross two wires over!

ASE2003 – p. 12

Page 41: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An XOR gate

ASE2003 – p. 13

Page 42: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An XOR gate

ASE2003 – p. 13

Page 43: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An XOR gate

ASE2003 – p. 13

Page 44: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An AND gate

An AND gate. . .ASE2003 – p. 14

Page 45: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An AND gate

. . . and its internal wires.ASE2003 – p. 14

Page 46: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An AND gate

If t is a mine. . .ASE2003 – p. 14

Page 47: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An AND gate

If t is not a mine. . .ASE2003 – p. 14

Page 48: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An OR gate

An OR gate. . .

ASE2003 – p. 15

Page 49: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An OR gate

. . . with the internal wires shown.

ASE2003 – p. 15

Page 50: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An OR gate

If r is free. . .

ASE2003 – p. 15

Page 51: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An OR gate

If r has a mine (case 1). . .

ASE2003 – p. 15

Page 52: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

An OR gate

If r has a mine (case 2). . .

ASE2003 – p. 15

Page 53: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Minesweeper electronics

• Wire: allows us to carry signals around

ASE2003 – p. 16

Page 54: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Minesweeper electronics

• Wire: allows us to carry signals around• Splitter: allows us to bend, split and invert

signals in wires

ASE2003 – p. 16

Page 55: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 56: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 57: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

NP-completeness

• We can build any logic circuits inminesweeper, so. . .

ASE2003 – p. 17

Page 58: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 59: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 60: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 61: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Some interesting NP problems

• The travelling salesman problem

ASE2003 – p. 18

Page 62: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

Some interesting NP problems

• The travelling salesman problem• Many other problems is scheduling, packing,

decision maths, etc.

ASE2003 – p. 18

Page 63: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 64: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 65: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 66: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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

Page 67: How Complicated is Minesweeper?web.mat.bham.ac.uk/R.W.Kaye/minesw/ASE2003.pdf · Minesweeper • Minesweeper is a familiar computer game requiring you to locate the mines in a minefield

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