And another quick question if i may, i know that after making a move (an actual one) i should empty the table and start fresh (please correct me if i am wrong) .
But what about if there is no depth limit..e.g if i am doing a complete tree search. Do i still need to reinitialize the table after each move?
EDIT: while the random numbers part is rather easy for me to understand. from what i understood, one of the advantages of zobrist is that instead of hashing the entire board every time, one can update it's hash value by means of using XOR. but i can't figure out how exactly should i do it in connect 4. I would like to get some example if possible.
Or maybe this is not relevant in connect 4 since unlike chess, the pieces are not moving on the board,just being added to it..??
EDIT2: what do you say about those two functions. one is initializing the table with random numbers and the other produce the hash code. I need some review here
zobrist is a long [42] [2] array defined in the begining of this class
private void initZobrist(){
Random r = new Random();
for(int i = 0; i<42; i++){
for(int j = 0; j<2; j++){
zobrist[j] = r.nextLong();
}
}
}
public long hash(long[]board){
long hashValue = 0;
long y1 = board[0]; //white's bitBoard
long y2 = board[1]; //black's bitBoard
for(int i = 0; i<42; i++){
if((y1 & (1L<<i)) !=0){
hashValue ^= zobrist[0];
}
else if((y2 & (1L<<i)) !=0){
hashValue ^= zobrist[1];
}
}
return hashValue;
}