X-Git-Url: http://winboard.nl/cgi-bin?p=polyglot.git;a=blobdiff_plain;f=hash.c;h=42051309123e962de7afc802c7cf5fe4a2112d8a;hp=4baa0aac68e6a150bcc81c82510e936f93ae455a;hb=ae338a820ef1c16d4399958613bbc0b908904b91;hpb=e516b96c20d27e7d86d3485b010d6d48cecec9f1 diff --git a/hash.c b/hash.c index 4baa0aa..4205130 100644 --- a/hash.c +++ b/hash.c @@ -1,128 +1,128 @@ - -// hash.c - -// includes - -#include "board.h" -#include "hash.h" -#include "piece.h" -#include "random.h" -#include "square.h" -#include "util.h" - -// variables - -static uint64 Castle64[16]; - -// prototypes - -static uint64 hash_castle_key_debug (int flags); - -// functions - -// hash_init() - -void hash_init() { - - int i; - - for (i = 0; i < 16; i++) Castle64[i] = hash_castle_key_debug(i); -} - -// hash_key() - -uint64 hash_key(const board_t * board) { - - uint64 key; - int colour; - const uint8 * ptr; - int sq, piece; - - ASSERT(board_is_ok(board)); - - // init - - key = 0; - - // pieces - - for (colour = 1; colour <= 2; colour++) { // HACK - for (ptr = board->list[colour]; (sq=*ptr) != SquareNone; ptr++) { - piece = board->square[sq]; - key ^= hash_piece_key(piece,sq); - } - } - - // castle flags - - key ^= hash_castle_key(board_flags(board)); - - // en-passant square - - sq = board->ep_square; - if (sq != SquareNone) key ^= hash_ep_key(sq); - - // turn - - key ^= hash_turn_key(board->turn); - - return key; -} - -// hash_piece_key() - -uint64 hash_piece_key(int piece, int square) { - - ASSERT(piece_is_ok(piece)); - ASSERT(square_is_ok(square)); - - return random_64(RandomPiece+piece_to_12(piece)*64+square_to_64(square)); -} - -// hash_castle_key() - -uint64 hash_castle_key(int flags) { - - ASSERT((flags&~0xF)==0); - - return Castle64[flags]; -} - -// hash_castle_key_debug() - -static uint64 hash_castle_key_debug(int flags) { - - uint64 key; - int i; - - ASSERT((flags&~0xF)==0); - - key = 0; - - for (i = 0; i < 4; i++) { - if ((flags & (1<list[colour]; (sq=*ptr) != SquareNone; ptr++) { + piece = board->square[sq]; + key ^= hash_piece_key(piece,sq); + } + } + + // castle flags + + key ^= hash_castle_key(board_flags(board)); + + // en-passant square + + sq = board->ep_square; + if (sq != SquareNone) key ^= hash_ep_key(sq); + + // turn + + key ^= hash_turn_key(board->turn); + + return key; +} + +// hash_piece_key() + +uint64 hash_piece_key(int piece, int square) { + + ASSERT(piece_is_ok(piece)); + ASSERT(square_is_ok(square)); + + return random_64(RandomPiece+piece_to_12(piece)*64+square_to_64(square)); +} + +// hash_castle_key() + +uint64 hash_castle_key(int flags) { + + ASSERT((flags&~0xF)==0); + + return Castle64[flags]; +} + +// hash_castle_key_debug() + +static uint64 hash_castle_key_debug(int flags) { + + uint64 key; + int i; + + ASSERT((flags&~0xF)==0); + + key = 0; + + for (i = 0; i < 4; i++) { + if ((flags & (1<