Jan 12, 2007

[Other] Lot of work with Zobrist keys

While being a pretty straight forward concept there are a lot of things that can go wrong with the Zobrist keys. Not the basic implementation, but integrating it to the makeMove and unmakeMove methods.

It was a lot of hard work to get it to work right. The main problem is even a tiny coding error leads to a completely different key, and unless you catch it with testing where you actually see the keys you will end up with a flawed hash table later on.

I wrote a whole set of tests to try every eventuallity. I caught things like castling long for black, and promoting to bishop for white returned wrong keys.

If I had not caught those at this stage, the engine could start acting weird once the hash tables got implemented and you would have no idea where to look.

The way I tested was setting up a position with a FEN-string and printing the Zobrist key, then making and unmaking a move and see if the key matched after the moves.

This way you catch both making and unmaking errors as well as getting a simple way of checking the validity of the keys (instead of inserting the new position after a move and generating a new key).

Well, time to put it to use in the transposition table.

No comments: