From 00fc61020ca7982ee506d9fde1cec9b9c5f43fa9 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Thu, 6 Jun 2024 07:38:01 +0200 Subject: [PATCH] "#define key_t" -> hkey_t type --- src/hash.c | 4 ++-- src/hash.h | 14 +++++++------- src/move-do.c | 6 +++--- src/position.h | 10 +++++++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/hash.c b/src/hash.c index f9b4112..5f3756e 100644 --- a/src/hash.c +++ b/src/hash.c @@ -66,9 +66,9 @@ void zobrist_init(void) * * @return: @pos Zobrist key */ -key_t zobrist_calc(pos_t *pos) +hkey_t zobrist_calc(pos_t *pos) { - key_t key = 0; + hkey_t key = 0; if (pos->turn == BLACK) key ^= zobrist_turn; diff --git a/src/hash.h b/src/hash.h index 438ffee..a270c47 100644 --- a/src/hash.h +++ b/src/hash.h @@ -24,7 +24,7 @@ #define HASH_SIZE_MIN 4 #define HASH_SIZE_MAX 32768 /* 32Gb */ -#define key_t u64 /* cannot use typedef for key_t */ +typedef u64 hkey_t; /* cannot use typedef for key_t */ /** * hentry_t: hashtable bucket. @@ -33,7 +33,7 @@ * 16 bytes in future, it should be updated to be exactly 32 bytes. */ typedef struct { - key_t key; /* zobrist */ + hkey_t key; /* zobrist */ union { u64 data; struct { @@ -81,15 +81,15 @@ typedef struct { */ #define EP_ZOBRIST_IDX(ep) ( ( (ep) >> 3 ) | sq_file(ep) ) -extern key_t zobrist_pieces[16][64]; -extern key_t zobrist_castling[4 * 4 + 1]; -extern key_t zobrist_turn; /* for black, XOR each ply */ -extern key_t zobrist_ep[9]; /* 0-7: ep file, 8: SQUARE_NONE */ +extern hkey_t zobrist_pieces[16][64]; +extern hkey_t zobrist_castling[4 * 4 + 1]; +extern hkey_t zobrist_turn; /* for black, XOR each ply */ +extern hkey_t zobrist_ep[9]; /* 0-7: ep file, 8: SQUARE_NONE */ extern hasht_t hash_tt; /* main transposition table */ void zobrist_init(void); -key_t zobrist_calc(pos_t *pos); +hkey_t zobrist_calc(pos_t *pos); #ifdef ZOBRIST_VERIFY bool zobrist_verify(pos_t *pos); diff --git a/src/move-do.c b/src/move-do.c index 8fbf9e4..cc4c333 100644 --- a/src/move-do.c +++ b/src/move-do.c @@ -61,7 +61,7 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state) piece_type_t ptype = PIECE(piece); piece_t new_piece = piece; int up = sq_up(us); - key_t key = pos->key; + hkey_t key = pos->key; /* update key: switch turn, reset castling and ep */ key ^= zobrist_turn; @@ -146,7 +146,7 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state) pos->castle = clr_oo(pos->castle, them); } - /* update castle key */ + /* update castling rights key */ key ^= zobrist_castling[pos->castle]; pos->key = key; @@ -168,7 +168,7 @@ pos_t *move_do2(pos_t *pos, const move_t move, state_t *state) piece_type_t ptype = PIECE(piece); piece_t new_piece = piece; int up = sq_up(us); - key_t key = pos->key; + hkey_t key = pos->key; *state = pos->state; /* save irreversible changes */ diff --git a/src/position.h b/src/position.h index 8a8b8a9..a3eeb67 100644 --- a/src/position.h +++ b/src/position.h @@ -28,6 +28,13 @@ #include "move.h" #include "board.h" +#define REPEAT_SIZE 1024 + +typedef struct { + hkey_t key[REPEAT_SIZE]; + int moves; +} repeat_t; + typedef struct __pos_s { u64 node_count; /* evaluated nodes */ int turn; /* WHITE or BLACK */ @@ -43,7 +50,7 @@ typedef struct __pos_s { * This allows a memcpy on this data (to save/restore position state). */ struct_group_tagged(state_s, state, - key_t key; + hkey_t key; square_t en_passant; castle_rights_t castle; int clock_50; @@ -57,6 +64,7 @@ typedef struct __pos_s { piece_t board[BOARDSIZE]; bitboard_t bb[2][PIECE_TYPE_MAX]; /* bb[0][PAWN], bb[1][ALL_PIECES] */ square_t king[2]; /* dup with bb, faster retrieval */ + repeat_t repeat; /* for repetition detection */ } pos_t; typedef struct state_s state_t;