Java Reference
In-Depth Information
1 class TicTacToe
2 {
3 public static final int HUMAN = 0;
4 public static final int COMPUTER = 1;
5 public static final int EMPTY = 2;
6
7 public static final int HUMAN_WIN = 0;
8 public static final int DRAW = 1;
9 public static final int UNCLEAR = 2;
10 public static final int COMPUTER_WIN = 3;
11
12 // Constructor
13 public TicTacToe( )
14 { clearBoard( ); }
15
16 // Find optimal move
17 public Best chooseMove( int side )
18 { /* Implementation in Figure 7.29 */ }
19
20 // Compute static value of current position (win, draw, etc.)
21 private int positionValue( )
22 { /* Implementation in Figure 7.28 */ }
23
24 // Play move, including checking legality
25 public boolean playMove( int side, int row, int column )
26 { /* Implementation in online code */ }
27
28 // Make board empty
29 public void clearBoard( )
30 { /* Implementation in online code */ }
31
32 // Return true if board is full
33 public boolean boardIsFull( )
34 { /* Implementation in online code */ }
35
36 // Return true if board shows a win
37 public boolean isAWin( int side )
38 { /* Implementation in online code */ }
39
40 // Play a move, possibly clearing a square
41 private void place( int row, int column, int piece )
42 { board[ row ][ column ] = piece; }
43
44 // Test if a square is empty
45 private boolean squareIsEmpty( int row, int column )
46 { return board[ row ][ column ] == EMPTY; }
47
48 private int [ ] [ ] board = new int[ 3 ][ 3 ];
49 }
figure 7.27
Skeleton for class
TicTacToe
Search WWH ::




Custom Search