Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrectly Implementing Zobrist Hashing
    primarykey
    data
    text
    <p>I'm currently adding transposition tables in my chess engine, and I'm having issues with incrementally updating Zobrist keys. I <a href="http://chessprogramming.wikispaces.com/Zobrist+Hashing" rel="nofollow">did some research</a> and implemented the basic idea, but it's not behaving as I expect. The problem I encountered was that equivalent board positions do not always have the same keys. For example, in the starting position, if both players just moved a knight and then moved it back, the key would be different from that of the starting position. However, doing this again (moving the knights) and returning to the starting position <em>would</em> result in the original key. So it seems that the period for such sequence is 4 moves for each player, when it should just be 2. </p> <p>Has anyone encountered such a problem or can think of solution? I've included the relevant portions of my make/unmake methods. I don't include side-to-move, castling rights, etc; they shouldn't affect the particular case I brought up. HashValue stores the random values, with the first index being the piece type and second being the square. </p> <pre><code>void Make(Move m) { ZobristKey ^= HashValue[Piece[m.From].Type][m.From]; ZobristKey ^= HashValue[Piece[m.From].Type][m.To]; ZobristKey ^= HashValue[Piece[m.To].Type][m.To]; //rest of make move } void Unmake(Move m) { ZobristKey ^= HashValue[m.Captured.Type][m.To]; ZobristKey ^= HashValue[Element[m.To].Type][m.To]; ZobristKey ^= HashValue[Element[m.To].Type][m.From]; //rest of unmake } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload