Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
search.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: search.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(SEARCH_H)
9#define SEARCH_H
10
11class noMoveFoundException : public std::exception
12{
13 const char * what () const noexcept override {
14 return "Nothing found";
15 }
16};
17
18class searchAbortedException : public std::exception
19{
20 const char * what () const noexcept override {
21 return "Aborting search";
22 }
23};
24
25#if defined(_DEBUG)
26#define DEBUG_sendInfoSearching(b, depth, msg, sc) \
27 sendInfoSearching(b, depth, msg, sc)
28#define DEBUG_returnInfoSearching(b, depth, msg, sc) \
29 sendInfoSearching(b, depth, msg, sc)
30#else
31#define DEBUG_sendInfoSearching(b, depth, msg, sc)
32#define DEBUG_returnInfoSearching(b, depth, msg, sc) \
33 sc
34#endif
35
36//-----------------------------------------------------------------------
37
43
45
47public:
48 bSearchScore(bSearchScore const& sc) noexcept;
49 explicit bSearchScore(bSearchScore&& sc) noexcept;
50 explicit bSearchScore(bScore const& sc) noexcept;
51 explicit bSearchScore(bScore const& sc, scoretype_t const& st) noexcept;
53
54 bSearchScore& operator=(bSearchScore&& sc) noexcept;
55 bSearchScore& operator=(bScore const& sc) noexcept;
56 bSearchScore& operator=(bScore&& sc) noexcept;
57 bSearchScore operator-() const;
58
60
61 operator std::string() const;
62 bScore getScore() const { return m_score; }
63 bScore getRealScore() const { return belofte::realScore(m_score); }
64
65 friend std::string const operator+(std::string const& lhs, bSearchScore const& sc);
66 friend std::string const operator+(bSearchScore const& sc, std::string const& rhs);
67 friend bool operator>(bScore const& lhsc, bSearchScore const& rhsc);
68 friend bool operator>=(bScore const& lhsc, bSearchScore const& rhsc);
69 friend bool operator>(bSearchScore const& lhsc, bScore const& rhsc);
70 friend bool operator>(bSearchScore const& lhsc, bSearchScore const& rhsc);
71
72private:
73 bScore m_score = SCORE_UNDEFINED;
75};
76
77//-----------------------------------------------------------------------
78
80public:
81 bSearchAlgorithm(std::string const& n);
82 ~bSearchAlgorithm() override;
83
84 // no copy or move ctor nor assignment defined
89
90 operator std::string() const& { return const_cast<std::string const&>(m_name); }
91
92 int64_t getNodes() const { return m_nodes; }
93 int64_t getNonLeafNodes() const { return m_nonleafnodes; }
94
95 void StartSearch(bScore const m);
96 void StopSearch();
97 void InterruptSearch();
99
100 bScore sendInfoSearching(bBoard const& b, depth_t const nDepth,
101 std::string const& c,
102 bScore const sc) const;
103
105
107 int64_t m_nodes = 0LL;
108 int64_t m_nonleafnodes = 0LL;
109 bool m_iterativesearch = false; // access required from bench command
110
111protected:
112 virtual bScore CalcBestMove(bBoard& b) = 0;
113 void CheckIfAbortingSearch() const;
114 bScore attenuateScore(bScore const sc) const;
115
116 void setLevel(bLevel* l) { m_levelptr = l; }
117 bLevel* getLevel() { return m_levelptr; }
118
119 void sendInfoCurrMove(bBoard const& b, depth_t const nDepth,
120 movenum_t const moveid) const;
121 bScore sendInfoScore(bBoard const& b,
122 depth_t const nDepth,
123 bScore const) const;
124 void dumpMoveList(bBoard& b, depth_t const iDepth) const;
125
126private:
127 bBestMoveInfo SearchBestMoveIterative(bBoard& b);
128
129 int m_postlevel = 0;
130 bScore m_minimizing = 1; // set to -1 if searching started for black
131 std::atomic<bool> m_aborting;
132 std::string m_name;
133 bLevel* m_levelptr;
134};
135
136//-----------------------------------------------------------------------
137
138#endif // defined SEARCH_H
139
140// eof
uint_fast8_t movenum_t
Definition belofte.h:109
int_fast8_t depth_t
Definition belofte.h:112
int16_t bScore
Helper class for measuring execution time for functions Call ClockStart and ClockEnd at end of execut...
Definition util.h:17
board
Definition board.h:147
Definition level.h:49
void sendInfoCurrMove(bBoard const &b, depth_t const nDepth, movenum_t const moveid) const
Definition search.cpp:327
bScore attenuateScore(bScore const sc) const
converge score towards zero in order to force immediate best move first
Definition search.cpp:356
depth_t m_maxDepth
Definition search.h:106
bScore RetrieveBoardEvaluation(bBoard &b) const
Cache score of board.
Definition search.cpp:343
void StopSearch()
Definition search.cpp:267
bool m_iterativesearch
Definition search.h:109
void InterruptSearch()
Definition search.cpp:273
~bSearchAlgorithm() override
Definition search.cpp:139
virtual bScore CalcBestMove(bBoard &b)=0
bScore sendInfoScore(bBoard const &b, depth_t const nDepth, bScore const) const
Definition search.cpp:316
bLevel * getLevel()
Definition search.h:117
int64_t m_nonleafnodes
Definition search.h:108
bScore sendInfoSearching(bBoard const &b, depth_t const nDepth, std::string const &c, bScore const sc) const
Definition search.cpp:301
bSearchAlgorithm(bSearchAlgorithm const &)=delete
bSearchAlgorithm(bSearchAlgorithm &&)=delete
int64_t getNodes() const
Definition search.h:92
int64_t m_nodes
Definition search.h:107
void setLevel(bLevel *l)
Definition search.h:116
bSearchAlgorithm & operator=(bSearchAlgorithm const &)=delete
void CheckIfAbortingSearch() const
Definition search.cpp:278
bBestMoveInfo SearchBestMove(bBoard &b)
Generic search, will call (non-)recursive method per algorithm only when there are moves to be played...
Definition search.cpp:152
bSearchAlgorithm & operator=(bSearchAlgorithm &&)=delete
int64_t getNonLeafNodes() const
Definition search.h:93
void StartSearch(bScore const m)
Definition search.cpp:258
void dumpMoveList(bBoard &b, depth_t const iDepth) const
Definition search.cpp:288
bSearchScore operator-() const
Definition search.cpp:61
bSearchScore & operator=(bSearchScore &&sc) noexcept
Definition search.cpp:35
bSearchScore & operator=(bSearchScore const &)=delete
friend std::string const operator+(std::string const &lhs, bSearchScore const &sc)
Definition search.cpp:73
friend bool operator>(bScore const &lhsc, bSearchScore const &rhsc)
Definition search.cpp:83
bScore getRealScore() const
Definition search.h:63
bScore getScore() const
Definition search.h:62
friend bool operator>=(bScore const &lhsc, bSearchScore const &rhsc)
Definition search.cpp:88
constexpr bScore SCORE_UNDEFINED
Definition eval.h:20
bScore realScore(bScore const sc)
Definition eval.cpp:23
tScoreType
Definition search.h:38
@ SC_BETA
Definition search.h:40
@ SC_BEST
Definition search.h:40
@ SC_CHILD
Definition search.h:40
@ SC_SIZE
Definition search.h:41
@ SC_UNDEF
Definition search.h:39
@ SC_ALPHA
Definition search.h:40
enum tScoreType scoretype_t
Definition search.h:44