From a0970bddbd9f6b97b6a12ba7f73fd1810a2e1e1b Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Sun, 19 Jul 2026 17:52:26 +0530 Subject: ttable lookup & probe --- include/engine/transposition_table.h | 16 -------------- include/engine/ttable.h | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 16 deletions(-) delete mode 100644 include/engine/transposition_table.h create mode 100644 include/engine/ttable.h (limited to 'include/engine') diff --git a/include/engine/transposition_table.h b/include/engine/transposition_table.h deleted file mode 100644 index f06ddbe..0000000 --- a/include/engine/transposition_table.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TRANSPOSITION_TABLE_H -#define TRANSPOSITION_TABLE_H - -#include "bitboard.h" - -static struct zobrist_keys { - u64 piece[PIECE_TYPE_COUNT][64]; - u64 castle[CASTLE_COUNT]; - u64 turn[TURN_COUNT]; - u64 en_passant[64]; -} zobrist_keys; - -void transposition_table_init(); -u64 zobrist_hash(position_t position); - -#endif // TRANSPOSITION_TABLE_H diff --git a/include/engine/ttable.h b/include/engine/ttable.h new file mode 100644 index 0000000..2ee1a5c --- /dev/null +++ b/include/engine/ttable.h @@ -0,0 +1,43 @@ +#ifndef TTABLE_H +#define TTABLE_H + +#include "bitboard.h" + +#define TABLE_BITS 24 +#define TABLE_SIZE (1ULL << TABLE_BITS) +#define MASK (TABLE_SIZE - 1) +#define TT_BUCKET_SIZE 4 + +static struct zobrist_keys { + u64 piece[PIECE_TYPE_COUNT][64]; + u64 castle[CASTLE_COUNT]; + u64 turn[TURN_COUNT]; + u64 en_passant[64]; +} zobrist_keys; + +enum { TT_EXACT, TT_LOWERBOUND, TT_UPPERBOUND }; +typedef struct { + atomic_uint_fast64_t key; + move_t best_move; + i16 score; // depth analysed + i16 eval; // non-depth analysed + u16 depth; + u16 generation; + u8 flag; +} tentry_t; + +typedef struct { + tentry_t entries[TT_BUCKET_SIZE]; +} tbucket_t; + +typedef tbucket_t* ttable_t; + +void ttable_init(); +u64 zobrist_hash(position_t position); +void ttable_store( + ttable_t *ttable, u64 key, move_t move, i16 score, + i16 eval, u16 depth, u16 generation, u8 flag +); +tentry_t *ttable_probe(ttable_t *table, u64 key); + +#endif // TTABLE_H -- cgit v1.2.3