BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
KillerMoves.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>
24#include <cassert>
25#include <cstddef> // IWYU pragma: keep - for size_t
29#include <span>
30#include <vector>
31
32namespace ben_bot {
33
34using chess::moves::Move;
35using std::size_t;
36
44struct KillerMoves final {
46 static constexpr auto MAX_KILLERS { 2uz };
47
49 void clear()
50 {
51 for (auto& list : lists)
52 list.clear();
53 }
54
58 void store(const size_t plyFromRoot, const Move move)
59 {
60 assert(plyFromRoot < search::MAX_PLY);
61
62 auto& list = lists.at(plyFromRoot);
63
64 if (std::ranges::contains(list, move))
65 return;
66
67 list.insert(list.begin(), move);
68
69 if (list.size() > MAX_KILLERS)
70 list.pop_back();
71 }
72
74 [[nodiscard]] auto get(const size_t plyFromRoot) const noexcept -> std::span<const Move>
75 {
76 return lists.at(plyFromRoot);
77 }
78
79private:
80 using Killers = std::vector<Move>;
81
82 std::array<Killers, search::MAX_PLY + 1uz> lists { };
83};
84
85} // namespace ben_bot
constexpr auto MAX_PLY
Definition Constants.hpp:27
void store(const size_t plyFromRoot, const Move move)
auto get(const size_t plyFromRoot) const noexcept -> std::span< const Move >
static constexpr auto MAX_KILLERS