Information Technology Reference
In-Depth Information
Figure 10.8.
An entire game of tic-tac-toe
?- play_user(nobody).
The first player is x and the initial state is
[-, -, -, -, -, -, -, -, -]
Player x chooses move 1 and the new state is
[x, -, -, -, -, -, -, -, -]
Player o chooses move 5 and the new state is
[x, -, -, -, o, -, -, -, -]
Player x chooses move 2 and the new state is
[x, x, -, -, o, -, -, -, -]
Player o chooses move 3 and the new state is
[x, x, o, -, o, -, -, -, -]
Player x chooses move 7 and the new state is
[x, x, o, -, o, -, x, -, -]
Player o chooses move 4 and the new state is
[x, x, o, o, o, -, x, -, -]
Player x chooses move 6 and the new state is
[x, x, o, o, o, x, x, -, -]
Player o chooses move 8 and the new state is
[x, x, o, o, o, x, x, o, -]
Player x chooses move 9 and the new state is
[x, x, o, o, o, x, x, o, x]
-------- The winner is neither
Yes
A more interesting run appears in figure 10.9 where the user is player O . The first
move player O makes here (by typing a 2 and then a period) is not a good one. The
computer (playing X ) immediately capitalizes on it and ends up winning.
10.2.6 A third example: Boxes
Let us now turn attention to a more challenging game. The game is called Boxes
and its rules appear in figure 10.10. Figure 10.11 shows the first few moves of a
typical Boxes game, starting at the top left. Max (moving first) chooses the rightmost
vertical line, then Min chooses a vertical line beside it, then Max chooses an adjacent
horizontal line, then Min chooses a connecting horizontal line, and then in the move
depicted at the bottom left, Max chooses a horizontal line that completes the top right
square. At this point, Max owns that square (and writes his name in it) and in the
same move exercises his option to draw a second line, the bottom horizontal. The
game would then continue with Min from there.
Search WWH ::




Custom Search