BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Callbacks.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
23
24#include <functional>
26#include <string>
27
28namespace chess::game {
29struct Position;
30} // namespace chess::game
31
32namespace ben_bot::search {
33
34struct Options;
35struct Result;
36
37using chess::moves::Move;
38
46struct Callbacks final {
48 using Callback = std::function<void(const Result&)>;
49
51 std::function<void(const Options&)> onSearchStart;
52
55
60
65 std::function<void(Move, size_t)> onRootMove;
66
68 void search_start(const Options& options) const
69 {
70 if (onSearchStart != nullptr)
71 onSearchStart(options);
72 }
73
75 void search_complete(const Result& result) const
76 {
77 if (onSearchComplete != nullptr) {
78 [[likely]];
79 onSearchComplete(result);
80 }
81 }
82
84 void iteration_complete(const Result& result) const
85 {
86 if (onIteration != nullptr) {
87 [[likely]];
88 onIteration(result);
89 }
90 }
91
93 void root_move(const Move move, const size_t idx) const
94 {
95 if (onRootMove != nullptr) {
96 onRootMove(move, idx);
97 }
98 }
99
106 [[nodiscard]] static auto make_uci_printer(
107 std::function<bool()> isDebugMode)
108 -> Callbacks;
109
118 [[nodiscard]] static auto make_pretty_printer(
119 std::function<std::string(Move, const chess::game::Position&)>&& printMove)
120 -> Callbacks;
121};
122
123} // namespace ben_bot::search
std::function< void(const Result &)> Callback
Definition Callbacks.hpp:48
static auto make_uci_printer(std::function< bool()> isDebugMode) -> Callbacks
void root_move(const Move move, const size_t idx) const
Definition Callbacks.hpp:93
static auto make_pretty_printer(std::function< std::string(Move, const chess::game::Position &)> &&printMove) -> Callbacks
void search_complete(const Result &result) const
Definition Callbacks.hpp:75
void search_start(const Options &options) const
Definition Callbacks.hpp:68
std::function< void(const Options &)> onSearchStart
Definition Callbacks.hpp:51
std::function< void(Move, size_t)> onRootMove
Definition Callbacks.hpp:65
void iteration_complete(const Result &result) const
Definition Callbacks.hpp:84