BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
HistoryTable.hpp
Go to the documentation of this file.
1/*
2 * ======================================================================================
3 *
4 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7 * ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11 *
12 * ======================================================================================
13 */
14
19
20#pragma once
21
22#include <algorithm>
23#include <array>
26
27namespace ben_bot {
28
29using chess::moves::Move;
30
38struct HistoryTable final {
40 static constexpr auto MAX_SCORE { 16384 };
41
43 void clear() noexcept { scores = { }; }
44
49 void age() noexcept
50 {
51 for (auto& color : scores)
52 for (auto& from : color)
53 std::ranges::transform(from, from.begin(), [](const int score) { return score / 2; });
54 }
55
60 void update(const bool whiteToMove, const Move move, const int bonus) noexcept
61 {
62 apply_history_gravity(get_ref(whiteToMove, move), bonus, MAX_SCORE);
63 }
64
66 [[nodiscard]] auto get(const bool whiteToMove, const Move move) const noexcept -> int
67 {
68 return scores[whiteToMove ? 1uz : 0uz][move.from().index()][move.to().index()];
69 }
70
71private:
72 [[nodiscard]] auto get_ref(const bool whiteToMove, const Move move) noexcept -> int&
73 {
74 return scores[whiteToMove ? 1uz : 0uz][move.from().index()][move.to().index()];
75 }
76
77 using Table = std::array<std::array<int, 64uz>, 64uz>;
78
79 std::array<Table, 2uz> scores { };
80};
81
82} // namespace ben_bot
void apply_history_gravity(Entry &entry, const int bonus, const int maxScore) noexcept
void clear() noexcept
void update(const bool whiteToMove, const Move move, const int bonus) noexcept
void age() noexcept
auto get(const bool whiteToMove, const Move move) const noexcept -> int
static constexpr auto MAX_SCORE