BitBully 0.0.78
A fast, perfect-play Connect-4 engine in modern C++
Loading...
Searching...
No Matches
TranspositionTable.h
Go to the documentation of this file.
1
6#ifndef BITBULLY__TRANSPOSITIONTABLE_H_
7#define BITBULLY__TRANSPOSITIONTABLE_H_
8
9#include <memory>
10
11#include "Board.h"
12
13namespace BitBully {
14
27 public:
29 // hash tables of size 2^n allow fast modulo operations since
30 // x mod 2^n = x & (2^n - 1)
31 // TODO: compute the effect of the hash table size on the long-term perf. of
32 // the BitBully solver
33 static constexpr int LOG_2_SIZE = 20;
34
38 struct Entry {
42 enum NodeType {
43 NONE = 0,
44 EXACT = 1,
45 LOWER = 2,
46 UPPER = 3
47 };
48 uint64_t b;
50 int value;
56 int8_t searchDepth{0};
57 };
58
64 TranspositionTable(const int log_2_size = LOG_2_SIZE) {
65 tableSize = UINT64_C(1) << log_2_size;
66 table = std::make_unique<Entry[]>(tableSize);
67 }
68
79 inline Entry* get(const Board& b) {
80 // Prefetching?:
81 // size_t index = b.hash() & (tableSize - 1);
82 // __builtin_prefetch(&table[index]); // GCC/Clang prefetching
83 // return &table[index];
84
85 return &table[b.hash() & (tableSize - 1)];
86 }
87
88 private:
89 std::unique_ptr<Entry[]> table;
90 size_t tableSize;
91};
92
93} // namespace BitBully
94
95#endif // BITBULLY__TRANSPOSITIONTABLE_H_
Bitboard-based representation of a Connect-4 position.
Connect-4 position represented as a pair of 64-bit bitboards.
Definition Board.h:204
static uint64_t hash(uint64_t x)
Splittable-mix-style hash for a 64-bit integer.
Definition Board.h:334
static constexpr int LOG_2_SIZE
Default log2 of the number of entries.
Entry * get(const Board &b)
Get the slot associated with b.
TranspositionTable(const int log_2_size=LOG_2_SIZE)
Allocate a transposition table with 2^log_2_size entries.
Top-level namespace for the BitBully Connect-4 engine.
Definition BitBully.h:26
One transposition-table slot.
NodeType flag
Type of bound stored in value.
int8_t searchDepth
Remaining search budget when the entry was stored.
uint64_t b
Position UID (see Board::uid()).
NodeType
Type of the bound stored in value.
@ LOWER
Lower bound (fail-high cut node).
@ UPPER
Upper bound (fail-low all node).