Belofte version 2.2.0
A promising chess program using the UCI or Winboard interface
searchscore.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: searchscore.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(SEARCHSCORE_H)
9#define SEARCHSCORE_H
10
11//-----------------------------------------------------------------------
12
18
20
21//-----------------------------------------------------------------------
22
24public:
32 : u_scoreInfo{std::move(sc.u_scoreInfo)}
33 {}
34 explicit bSearchScore(bScore const& score)
35 : m_score{score}
36 {}
37 explicit bSearchScore(bScore const& score, scoretype_t const& st)
38 : m_score{score}
39 , m_type{st}
40 {}
43
45 { m_score = score;
46 return *this;
47 }
48
49 bSearchScore operator-() const;
50
51 bool operator>(bScore const& rhsc)
52 { return realScore() > rhsc; }
53 bool operator>(bSearchScore const& rhsc)
54 { return realScore() > rhsc.realScore(); }
55 bool operator>=(bSearchScore const& rhsc)
56 { return realScore() >= rhsc.realScore(); }
57 bool operator<(bScore const& rhsc)
58 { return realScore() < rhsc; }
59 bool operator<(bSearchScore const& rhsc)
60 { return realScore() < rhsc.realScore(); }
61 bool operator<=(bSearchScore const& rhsc)
62 { return realScore() <= rhsc.realScore(); }
63
64 constexpr bScore getScore() const
65 { return m_score; }
66 constexpr bScore realScore() const
69 }
70 constexpr bool isUndefinedScore() const
71 { return (m_score == SCORE_UNDEFINED) || (m_score == -SCORE_UNDEFINED); }
72 constexpr bool isInfiniteScore() const
73 { return (m_score == SCORE_INFINITE) || (m_score == -SCORE_INFINITE); }
74 constexpr bool isRealScore() const
75 { return (!isUndefinedScore()) && (!isInfiniteScore()); }
76 constexpr bool isFakeScore() const
77 { return isUndefinedScore() || isInfiniteScore(); }
78 constexpr bool isWinning() const
79 { return (realScore() >= SCORE_INFINITE) && (realScore() <= SCORE_MATE); }
80 inline bool improvesOn(bSearchScore const& sc)
81 { return realScore() > sc.realScore(); }
82 inline bool improvesOn(bScore const &margin, bSearchScore const& sc) const
83 { return (realScore() - margin) >= sc.realScore(); }
84 inline bool improvesOn(bScore const& sc)
85 { return realScore() > realScore(sc); }
86 inline bool improvesOn(bScore const &margin, bScore const& sc) const
87 { return (realScore() - margin) >= realScore(sc); }
88
89 std::string const operator+(std::string const& rhs)
90 { return operator std::string() + rhs; }
91 friend std::string const operator+(std::string const& lhs, bSearchScore const& sc)
92 { return lhs + sc.operator std::string(); }
93
94 friend bool operator>(bScore const& lhsc, bSearchScore const& rhsc)
95 { return lhsc > rhsc.realScore(); }
96 friend bool operator>=(bScore const& lhsc, bSearchScore const& rhsc)
97 { return lhsc >= rhsc.realScore(); }
98 friend bool operator<(bScore const& lhsc, bSearchScore const& rhsc)
99 { return lhsc < rhsc.realScore(); }
100 friend bool operator<=(bScore const& lhsc, bSearchScore const& rhsc)
101 { return lhsc <= rhsc.realScore(); }
102
105 return m_score;
106 }
107
108public:
109 // class static
110 static bScore convergeScore(bScore const score);
111
112 constexpr static bScore realScore(bScore const score)
113 { return bSearchScore::isDrawScore(score) ? 0
114 : ((score == SCORE_UNDEFINED) ? -SCORE_UNDEFINED : score);
115 }
116 constexpr static bool isUndefinedScore(bScore const score)
117 { return ((score == SCORE_UNDEFINED) || (score == -SCORE_UNDEFINED)); }
118 constexpr static bool isInfiniteScore(bScore const score)
119 { return (score == SCORE_INFINITE) || (score == -SCORE_INFINITE); }
120 constexpr static bool isDrawScore(bScore const score)
121 { return (score == SCORE_THEORETIC_DRAW) || (score == SCORE_PRACTICAL_DRAW); }
122 constexpr static bool isRealScore(bScore const score)
123 { return (!isUndefinedScore(score)) && (!isInfiniteScore(score)); }
124 constexpr static bool isFakeScore(bScore const score)
125 { return isUndefinedScore(score) || isInfiniteScore(score); }
126
127 operator std::string() const;
128
129private:
130 union {
131 uint32_t u_scoreInfo;
132 struct {
135 };
136 };
137};
138
139//-----------------------------------------------------------------------
140
141#endif // defined SEARCHSCORE_H
142
143// eof
bSearchScore(bSearchScore const &sc)
Definition searchscore.h:28
static constexpr bool isInfiniteScore(bScore const score)
bSearchScore operator-() const
constexpr bScore realScore() const
Definition searchscore.h:66
constexpr bool isInfiniteScore() const
Definition searchscore.h:72
bSearchScore(bSearchScore &sc)
Definition searchscore.h:25
static constexpr bool isDrawScore(bScore const score)
constexpr bool isFakeScore() const
Definition searchscore.h:76
constexpr bScore getScore() const
Definition searchscore.h:64
bool operator>(bSearchScore const &rhsc)
Definition searchscore.h:53
bool improvesOn(bSearchScore const &sc)
Definition searchscore.h:80
friend std::string const operator+(std::string const &lhs, bSearchScore const &sc)
Definition searchscore.h:91
friend bool operator<=(bScore const &lhsc, bSearchScore const &rhsc)
static constexpr bool isRealScore(bScore const score)
bool improvesOn(bScore const &margin, bScore const &sc) const
Definition searchscore.h:86
bSearchScore(bSearchScore &&sc)
Definition searchscore.h:31
bool improvesOn(bScore const &margin, bSearchScore const &sc) const
Definition searchscore.h:82
bSearchScore(bScore const &score, scoretype_t const &st)
Definition searchscore.h:37
bool improvesOn(bScore const &sc)
Definition searchscore.h:84
bool operator>=(bSearchScore const &rhsc)
Definition searchscore.h:55
bool operator<(bScore const &rhsc)
Definition searchscore.h:57
bool operator>(bScore const &rhsc)
Definition searchscore.h:51
constexpr bool isWinning() const
Definition searchscore.h:78
friend bool operator>(bScore const &lhsc, bSearchScore const &rhsc)
Definition searchscore.h:94
friend bool operator<(bScore const &lhsc, bSearchScore const &rhsc)
Definition searchscore.h:98
static constexpr bScore realScore(bScore const score)
std::string const operator+(std::string const &rhs)
Definition searchscore.h:89
bool operator<=(bSearchScore const &rhsc)
Definition searchscore.h:61
bSearchScore(bScore const &score)
Definition searchscore.h:34
bScore convergeScore()
friend bool operator>=(bScore const &lhsc, bSearchScore const &rhsc)
Definition searchscore.h:96
bool operator<(bSearchScore const &rhsc)
Definition searchscore.h:59
static constexpr bool isUndefinedScore(bScore const score)
static constexpr bool isFakeScore(bScore const score)
uint32_t u_scoreInfo
scoretype_t m_type
constexpr bool isUndefinedScore() const
Definition searchscore.h:70
constexpr bool isRealScore() const
Definition searchscore.h:74
bSearchScore & operator=(bScore const &score)
Definition searchscore.h:44
constexpr bScore SCORE_MATE
Definition eval.h:19
int16_t bScore
Definition eval.h:11
constexpr bScore SCORE_PRACTICAL_DRAW
Definition eval.h:17
constexpr bScore SCORE_UNDEFINED
Definition eval.h:21
constexpr bScore SCORE_THEORETIC_DRAW
Definition eval.h:16
constexpr bScore SCORE_INFINITE
Definition eval.h:20
tScoreType
Definition searchscore.h:13
@ SC_BETA
Definition searchscore.h:15
@ SC_SIZE
Definition searchscore.h:16
@ SC_UNDEF
Definition searchscore.h:14
@ SC_ALPHA
Definition searchscore.h:15
enum tScoreType scoretype_t
Definition searchscore.h:19