BenBot
1.7.5
A chess engine
Loading...
Searching...
No Matches
SearchStack.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 <array>
23
#include <cassert>
24
#include <cstddef>
// IWYU pragma: keep - for size_t & ptrdiff_t
25
#include <initializer_list>
26
#include <iterator>
27
#include <
libbenbot/eval/Score.hpp
>
28
#include <
libbenbot/search/Constants.hpp
>
29
#include <
libchess/moves/Move.hpp
>
30
#include <optional>
31
32
namespace
ben_bot
{
33
34
using
chess::moves::Move;
35
using
std::size_t;
36
42
struct
SearchStackEntry
final {
47
Move
move
{ };
48
54
std::optional<eval::Score>
staticEval
;
55
};
56
70
struct
SearchStack
final {
72
static
constexpr
auto
SENTINELS
{ 4uz };
73
78
[[nodiscard]]
auto
at
(
const
size_t
plyFromRoot)
noexcept
->
SearchStackEntry
*
79
{
80
assert(plyFromRoot <=
search::MAX_PLY
);
81
82
return
std::next(entries.data(),
static_cast<
std::ptrdiff_t
>
(
SENTINELS
+ plyFromRoot));
83
}
84
86
[[nodiscard]]
auto
at
(
const
size_t
plyFromRoot)
const
noexcept
->
const
SearchStackEntry
*
87
{
88
assert(plyFromRoot <=
search::MAX_PLY
);
89
90
return
std::next(entries.data(),
static_cast<
std::ptrdiff_t
>
(
SENTINELS
+ plyFromRoot));
91
}
92
93
private
:
94
// the search aborts when it reaches MAX_PLY, so that's the deepest node.
95
// The extra entry is for the child entry that a node at MAX_PLY would
96
// write if it ever recursed.
97
std::array<SearchStackEntry, SENTINELS + search::MAX_PLY + 2uz> entries { };
98
};
99
118
[[nodiscard]]
inline
auto
is_improving
(
const
SearchStackEntry
*
const
entry)
noexcept
->
bool
119
{
120
assert(entry !=
nullptr
);
121
122
const
auto
current = entry->staticEval;
123
124
if
(not current.has_value())
125
return
false
;
126
127
static_assert
(
SearchStack::SENTINELS
>= 4uz);
128
129
for
(
const
auto
pliesBack : { 2, 4 }) {
130
if
(
const
auto
previous = std::prev(entry, pliesBack)->staticEval)
131
return
*current > *previous;
132
}
133
134
return
true
;
135
}
136
137
}
// namespace ben_bot
Constants.hpp
Move.hpp
Score.hpp
ben_bot::SearchStack::is_improving
auto is_improving(const SearchStackEntry *const entry) noexcept -> bool
Definition
SearchStack.hpp:118
ben_bot::search::MAX_PLY
constexpr auto MAX_PLY
Definition
Constants.hpp:27
ben_bot
ben_bot::SearchStackEntry
Definition
SearchStack.hpp:42
ben_bot::SearchStackEntry::staticEval
std::optional< eval::Score > staticEval
Definition
SearchStack.hpp:54
ben_bot::SearchStackEntry::move
Move move
Definition
SearchStack.hpp:47
ben_bot::SearchStack
Definition
SearchStack.hpp:70
ben_bot::SearchStack::at
auto at(const size_t plyFromRoot) const noexcept -> const SearchStackEntry *
Definition
SearchStack.hpp:86
ben_bot::SearchStack::SENTINELS
static constexpr auto SENTINELS
Definition
SearchStack.hpp:72
ben_bot::SearchStack::at
auto at(const size_t plyFromRoot) noexcept -> SearchStackEntry *
Definition
SearchStack.hpp:78
chess::moves::Move
Definition
Move.hpp:75
libbenbot
include
libbenbot
data-structures
SearchStack.hpp
Generated on
for BenBot by
1.16.1