blob: e1a10f1930ee55a9c928fbaa3251c16e58e7f42f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#ifndef TTABLE_H
#define TTABLE_H
#include "engine/moves.h"
#include "bitboard.h"
#include <stdatomic.h>
#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;
void zobrist_init();
u64 zobrist_hash(position_t position);
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];
// int items_filled;
} tbucket_t;
typedef struct {
tbucket_t* buckets;
u64 mask;
} ttable_t;
struct ttable_insert_args {
u64 key;
move_t move;
i16 score;
i16 eval;
u16 depth;
u16 generation;
u8 flag;
};
// if you want size 8, then size_in_binary_log = 3
// if you want size 4, then size_in_binary_log = 2
// you are forced to have powers of 2 for size
void ttable_init(ttable_t *table, size_t size_in_binary_log);
void ttable_deinit(ttable_t table);
void __ttable_insert(ttable_t table, struct ttable_insert_args args);
tentry_t *ttable_find(ttable_t table, u64 key);
#define ttable_insert(ttable, ...) __ttable_insert( \
ttable, \
(struct ttable_insert_args) { __VA_ARGS__ } \
)
#endif // TTABLE_H
|