lundi 11 novembre 2019

Generating unique position key for every chess position

I am trying to create a chess engine. I was told that we can generate unique key for any chess position by hashing individual piece keys. Its like a particular piece on a particular square has an unique 64 bit key. Then we are supposed to XOR the piece keys for every piece present in the position.

Ignoring the castling and the en Passant square information about a chess position, here is how I was told to generate a position key(in C language)

typedef unsigned long long U64;
#define RAND_64 (   (U64) rand() + \
                    (U64) rand() << 15 + \
                    (U64) rand() << 31 + \
                    (U64) rand() << 45 \
                )
U64 pieceKeys[12][64]; // For 12 pieces on every possible square.

My question is that here isn't there a possibility of generating the same piece key for 2 pieces on 2 squares. If that happens then there will be ambiguity when we create the position key by XOR ing the piece keys.

Am I right? If so then how can I solve this potential problem?




Aucun commentaire:

Enregistrer un commentaire