Java Reference
In-Depth Information
1
final class Position
2
{
3
private int [ ][ ] board;
4
5
public Position( int [ ][ ] theBoard )
6
{
7
board = new int[ 3 ][ 3 ];
8
for( int i = 0; i < 3; i++ )
9
for( int j = 0; j < 3; j++ )
10
board[ i ][ j ] = theBoard[ i ][ j ];
11
}
12
13
public boolean equals( Object rhs )
14
{
15
if( ! (rhs instanceof Position ) )
16
return false;
17
18
Position other = (Position) rhs;
19
20
for( int i = 0; i < 3; i++ )
21
for( int j = 0; j < 3; j++ )
22
if( board[ i ][ j ] != ( (Position) rhs ).board[ i ][ j ] )
23
return false;
24
return true;
25
}
26
27
public int hashCode( )
28
{
29
int hashVal = 0;
30
31
for( int i = 0; i < 3; i++ )
32
for( int j = 0; j < 3; j++ )
33
hashVal = hashVal * 4 + board[ i ][ j ];
34
35
return hashVal;
36
}
37
}
figure 10.13
The
Position
class
Figures 10.15 and 10.16 show the new
chooseMove
. At line 8, we declare a
Position
object,
thisPosition
. When the time comes it will be placed in the
transposition table.
tableDepth
tells us how deep in the search to allow posi-
tions to be placed in the transposition table. By experimenting we found that
depth 5 was optimal. Allowing positions at depth 6 to be saved hurt because
Search WWH ::
Custom Search