CS 70
Discrete Mathematics for CS
Spring 2005
Clancy/Wagner
Notes 9
Lecture Notes 8 described methods for logical reasoning based on satisfiability testing and introduced
Minesweeper. In this lecture, we show how to construct a complete Minesweeper program. We show
that some aspects of Minesweeper are computationally intractable if handled na¨
ıvely. Methods for problem
decomposition can help.
Minesweeper in CNF
Lecture Notes 8 gave a simple example of how to formulate a logical description of a Minesweeper display
as a set of clauses. If
d
is a display,
CNF
(
d
)
denotes the corresponding CNF expression. We will now show
how to construct
CNF
(
d
)
systematically for any display.
CNF
(
d
)
consists of propositions arising from each of the known squares, plus the global constraint on the
total number of mines left. We begin with the known squares. Consider a known square, such as (2,1) in the
following example repeated from Lecture Notes 8:
2
1
1
1
1
1
2
3
(2,1) has 1 mine adjacent to it. There are 5 adjacent squares; 2 of them have been probed and are known
to be safe; 0 of them are marked as a mine already. There are
n
=
5

2

0
=
3 unknown adjacent squares,
of which
k
=
1

0
=
1 are mines. So we need to express in CNF the proposition that
k
of the
n
adjacent
unknown squares are mines. Call this proposition
KN
(
k
,
n
)
.
Let’s see what we have to work with. CNF requires a conjunction of disjunctions of literals. A disjunction
of literals means “at least one
...
,” i.e., an inequality. The literals can be either “(i,j) contains a mine” or
“(i,j) doesn’t contain a mine.” Because
KN
(
k
,
n
)
is entirely symmetric with respect to the unknown squares,
we might expect to generate clauses that are symmetric—for example, all positive literals or all negative
literals.
We begin by writing
KN
(
k
,
n
)
as two inequalities:
KN
(
k
,
n
)
≡
(
U
(
k
,
n
)
∧
L
(
k
,
n
))
where
U
(
k
,
n
)
means that
at most k
of the
n
squares contain a mine.
L
(
k
,
n
)
means that
at least k
of the
n
squares contain a mine.
So how do we express “at most
k
” using clauses that say “at least one”? Consider any subset of
k
+
1 squares
from the
n
unknown squares. If at most
k
are mines, then at least one is not a mine; the converse is also true.
So we have the following:
CS 70, Spring 2005, Notes 9
1