Information Technology Reference
In-Depth Information
Figure 10.11.
The start of a game of Boxes
Max
Figure 10.12.
Naming the parts of the Boxes board
1
2
Square 1 has lines 1, 3, 4, 6
3
4
5
Square 2 has lines 2, 4, 5, 7
6
7
Square 3 has lines 6, 8, 9, 10
8
9
10
As for the states of Boxes, perhaps the simplest thing to do is to think in terms of
situations and fluents (see section 9.4.1). A state will be a list of terms of the form
draw( player , line ) , with the most recent drawings first. This allows calculating all the
fluents that are needed to decide if a move is legal and when the game is over.
The full specification of the Boxes game in Prolog appears in figure 10.13. To
summarize briefly how it works, the game is over if a player owns two squares.
The successor state clauses for owns say that a player owns a square in a situation
if either the player just drew a line that is the last available line for that square
or the player already owned that square in the previous situation. The predicate
last_available_line says that a line is the last one for a square in a situation if
it is available, and nothing is available for that square once the line is drawn. The
Search WWH ::




Custom Search