I've only looked at the source code of a couple of chess engines and they both use randomly-generated random numbers for Zobrist hashing. I came across a random number generator that generates the same list of numbers given the same random seeds for m_z and m_w:
Code: Select all
unsigned int GetUint(void)
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w;
}
Assuming that you use the same Zobrist keys all the time, it would be possible to rewrite the doZobrist() fun to encode ALL the castling changes in one go, both the King and Rooks moves, using pre-computed values:
Code: Select all
#define ZOB_W_OO_KEY 0x -- some pre-computed value
#define ZOB_W_OOO_KEY 0x...
#define ZOB_B_OO_KEY 0x...
#define ZOB_B_OOO_KEY 0x...
void doZobrist(mv m)
{
...
if(m.flags & CASTLE_F) // castling move
switch(m.to){
case G1: ZobristKey ^= ZOB_W_OO_KEY;
break;
case C1: ZobristKey ^= ZOB_W_OOO_KEY;
break;
case G8: ZobristKey ^= ZOB_B_OO_KEY;
break;
case C8: ZobristKey ^= ZOB_B_OOO_KEY;
}
else{ // here we do all the other moves!
}
// Step 1: Create an effective board representation.
Code: Select all
_~___--__~~__^__~~__...__
8 \ | | / ( | / ! \
7 / | ! \ \ | / \ /
6 | < \ ! | \ \ < >
5 ( | / \ \ } / \ |
4 < / / | > { \ / /
3 [ ] | / \ \ | | \
2 | > \ | / ] \ / < >
1 \ | } \ / / | \ /
---^--``--~~--...--``~~~-
a b c d e f g h
Computer plays: 1. Ng1i2