Skip to content

Zobrist posstion hash in Chess #36

@HGMuller

Description

@HGMuller

I am trying to understand how the "board" hashing works in the context of the Jocly chessbase module. This in order to see what I would have to do to update the key for games involving dropping of captured pieces, so that capture-drop-spanning repetitions will also be correctly detected there.

Am I correct in that the zSign key is the (incrementally updated) XOR of all the 'seeds' for individual (pieceIndex, boardSquare) pairs? (I.e. (piece.i, piece.p)?) This seems wrong, in a way that badly backfires when a given piece can promote and demote, or toggle its color. Even without that it could go wrong: when two pieces of equal type swap places, it considers the positions different, while according to Chess rules it would have to be considered the same. The seeds should really depend on the (colored) piece type and the location (i.e. (piece.t, piece.s, piece.p)), and should be blind to the index the piece happens to have in the piece list.

I suppose this could be fixed by replacing the use of piece.i in the Zobrist.update everywhere by piece.t*(1+piece.s). This would even reduce the number of required seeds from 32 to 18 times the board size, in orthodox Chess, even though 1/3 of the seeds (for piece.s==0) would be wasted; there usually are significantly fewer types than pieces (because there are so many Pawns).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions