Belofte version 2.2.0
A promising chess program using the UCI or Winboard interface
eval.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: eval.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(EVAL_H)
9#define EVAL_H
10
11typedef int16_t bScore;
12
13// bit 1 - 0x8000 negative
14// bit 3 - 16 : 0 < 0x371F real score
15
16constexpr bScore SCORE_THEORETIC_DRAW = 0x3EEF; // 161.11
17constexpr bScore SCORE_PRACTICAL_DRAW = -SCORE_THEORETIC_DRAW; // negative draw score
18
19constexpr bScore SCORE_MATE = 0x3E80; // 160.00
20constexpr bScore SCORE_INFINITE = 0x3A98; // 150.00
21constexpr bScore SCORE_UNDEFINED = 0x3A00; // 148.48
22constexpr bScore SCORE_ALMOST_NORMAL = 0x371F; // 141.11
23constexpr bScore SCORE_RESIGN = 0x1000; // 40.96 (5 queens)
24constexpr bScore SCORE_ALMOST_DRAW = 0x000B; // 0.11
25constexpr bScore SCORE_DRAW = 0x0000; // 0
26
27constexpr bScore SCORE_CONVERGE_BYDEPTH = 1; // 0.01
28constexpr bScore SCORE_BETAMARGIN = 80; // 0.80
29
30// attention, ordering is used in std::string bGame::getResult
39
41
42//-----------------------------------------------------------------------
43
45public:
47 : m_name{"None"}
48 {}
49 explicit bPositionEvaluation(std::string&& s);
51 {}
52
53 // no copy or move ctor nor assignment defined
58
59 virtual bScore getEvaluation(bBoard const& b, gameResult_t gr) const;
60
61 operator std::string() const&
62 { return const_cast<std::string const&>(m_name); }
63
64public:
65 static gameResult_t gameEndedResult(bBoard const& b);
66 static bScore resultToScoreFlag(gameResult_t const gr);
67 static inline bool isDrawResult(gameResult_t const gr)
68 { return (gr >= GR_DRAW_STALEMATE) && (gr <= GR_DRAW_OTHER); }
69
70private:
71 static int8_t nFoldRepetition(bBoard const& b);
72 static bool twoFoldRepetition(bBoard const& b);
73 static bool threeFoldRepetition(bBoard const& b);
74 static bool insufficientMaterial(bBoard const& b);
75
76 std::string m_name;
77};
78
79//-----------------------------------------------------------------------
80
82public:
84 : bPositionEvaluation("PiecesOnly")
85 {}
87 {}
88
89 // no copy or move ctor nor assignment defined
94
95 bScore getEvaluation(bBoard const& b, gameResult_t gr) const override;
96};
97
98//-----------------------------------------------------------------------
99
101public:
103 : bPositionEvaluation{"StaticBoard"}
104 {}
105 explicit PosEvalStaticBoard(std::string&& s)
106 : bPositionEvaluation{std::move(s)}
107 {}
109 {}
110
111 // no copy or move ctor nor assignment defined
116
117 bScore getEvaluation(bBoard const& b, gameResult_t gr) const override;
118
119protected:
120 static bScore getRelativeBoardEval(bBoard const& b);
121 static bScore getEndgameEvaluation(bBoard const &b);
122 static bScore getPawnEndingEvaluation(bBoard const &b);
123 static bScore getMatingEvaluation(bBoard const &b);
124};
125
126//-----------------------------------------------------------------------
127
129public:
131 : PosEvalStaticBoard("PositionalBoard")
132 {}
134 {}
135
136 bScore getEvaluation(bBoard const& b, gameResult_t gr) const override;
137
138private:
139 static bScore getKingEvaluation(bBoard const& b);
140
141 static bScore getPawnEvaluation(bBoard const& b);
142 static bool whitePassed(bBoard const& b, column_t const iCol);
143 static bool blackPassed(bBoard const& b, column_t const iCol);
144
145 static bScore getRookEvaluation(bBoard const& b);
146 static bool seesHorVer(bBoard const& b, column_t const iCol,
147 rank_t const iRank, piece_t const matchPiece);
148 static bool sameRank(bBoard const& b, column_t const iCol, rank_t const iRank,
149 piece_t const matchPiece);
150 static bool sameCol(bBoard const& b, column_t const iCol, rank_t const iRank,
151 piece_t const matchPiece);
152 static bool whiteKingSameRankCol(bBoard const& b, column_t const iCol,
153 rank_t const iRank);
154 static bool blackKingSameRankCol(bBoard const& b, column_t const iCol,
155 rank_t const iRank);
156 static bScore openLineValWhite(bBoard const& b, column_t const iCol,
157 rank_t iRank);
158 static bScore openLineValBlack(bBoard const& b, column_t const iCol,
159 rank_t iRank);
160 static bScore rookRankValWhite(bBoard const& b, rank_t const iRank);
161 static bScore rookRankValBlack(bBoard const& b, rank_t const iRank);
162
163 static bScore getBishopEvaluation(bBoard const& b);
164 static bool sameDiagonal(bBoard const& b, column_t const iCol,
165 rank_t const iRank, piece_t const matchPiece);
166 static bool sameColour(bBoard const& b, case_t const c,
167 piece_t const matchPiece);
168 static bool sameColourWhiteKing(bBoard const& b, case_t const iCol);
169 static bool sameColourBlackKing(bBoard const& b, case_t const iCol);
170
171 static bScore getQueenEvaluation(bBoard const& b);
172};
173
174#endif // defined EVAL_H
175
176// eof
int8_t rank_t
Definition belofte.h:97
int8_t column_t
Definition belofte.h:98
uint8_t case_t
Definition belofte.h:99
PosEvalPiecesOnly(PosEvalPiecesOnly &&)=delete
bScore getEvaluation(bBoard const &b, gameResult_t gr) const override
get pure material evaluation of score from whites view
Definition eval.cpp:442
PosEvalPiecesOnly()
Definition eval.h:83
PosEvalPiecesOnly & operator=(PosEvalPiecesOnly const &)=delete
PosEvalPiecesOnly & operator=(PosEvalPiecesOnly &&)=delete
PosEvalPiecesOnly(PosEvalPiecesOnly const &)=delete
~PosEvalPiecesOnly() override
Definition eval.h:86
~PosEvalPositionalBoard() override
Definition eval.h:133
bScore getEvaluation(bBoard const &b, gameResult_t gr) const override
get positional evaluation from whites view
Definition eval.cpp:547
PosEvalStaticBoard(PosEvalStaticBoard &&)=delete
static bScore getMatingEvaluation(bBoard const &b)
Definition eval.cpp:527
static bScore getEndgameEvaluation(bBoard const &b)
Definition eval.cpp:497
~PosEvalStaticBoard() override
Definition eval.h:108
static bScore getPawnEndingEvaluation(bBoard const &b)
Definition eval.cpp:513
static bScore getRelativeBoardEval(bBoard const &b)
Definition eval.cpp:479
PosEvalStaticBoard(PosEvalStaticBoard const &)=delete
PosEvalStaticBoard & operator=(PosEvalStaticBoard &&)=delete
bScore getEvaluation(bBoard const &b, gameResult_t gr) const override
get material and case related modification of score from whites view
Definition eval.cpp:462
PosEvalStaticBoard & operator=(PosEvalStaticBoard const &)=delete
PosEvalStaticBoard(std::string &&s)
Definition eval.h:105
board
Definition board.h:45
virtual ~bPositionEvaluation()
Definition eval.h:50
static bScore resultToScoreFlag(gameResult_t const gr)
Class static function convert all draw scores to SCORE_THEORETIC_DRAW.
Definition eval.cpp:74
static gameResult_t gameEndedResult(bBoard const &b)
Class static function See if board is in finite state, meaning game is ended.
Definition eval.cpp:42
static bool isDrawResult(gameResult_t const gr)
Definition eval.h:67
virtual bScore getEvaluation(bBoard const &b, gameResult_t gr) const
get final score (+-SCORE_MATE, SCORE_THEORETIC_DRAW) or 0
Definition eval.cpp:429
bPositionEvaluation & operator=(bPositionEvaluation const &)=delete
bPositionEvaluation(bPositionEvaluation &&)=delete
bPositionEvaluation(bPositionEvaluation const &)=delete
bPositionEvaluation & operator=(bPositionEvaluation &&)=delete
constexpr bScore SCORE_ALMOST_NORMAL
Definition eval.h:22
gameResult
Definition eval.h:31
@ GR_DRAW_50
Definition eval.h:34
@ GR_UNSET
Definition eval.h:32
@ GR_DRAW_OTHER
Definition eval.h:35
@ GR_DRAW_FLAG
Definition eval.h:35
@ GR_WHITEWINS_ADJ
Definition eval.h:36
@ GR_DRAW_STALEMATE
Definition eval.h:34
@ GR_WHITEWINS_FLAG
Definition eval.h:36
@ GR_BLACKWINS_ADJ
Definition eval.h:37
@ GR_UNKNOWN
Definition eval.h:33
@ GR_WHITEMATES
Definition eval.h:36
@ GR_WHITERESIGNS
Definition eval.h:37
@ GR_BLACKMATES
Definition eval.h:37
@ GR_DRAW_LACKMATERIAL
Definition eval.h:34
@ GR_BLACKWINS_FLAG
Definition eval.h:37
@ GR_DRAW_THREEFOLD
Definition eval.h:34
@ GR_BLACKRESIGNS
Definition eval.h:36
@ GR_DRAW_ADJ
Definition eval.h:35
constexpr bScore SCORE_MATE
Definition eval.h:19
enum gameResult gameResult_t
Definition eval.h:40
int16_t bScore
Definition eval.h:11
constexpr bScore SCORE_PRACTICAL_DRAW
Definition eval.h:17
constexpr bScore SCORE_ALMOST_DRAW
Definition eval.h:24
constexpr bScore SCORE_RESIGN
Definition eval.h:23
constexpr bScore SCORE_CONVERGE_BYDEPTH
Definition eval.h:27
constexpr bScore SCORE_UNDEFINED
Definition eval.h:21
constexpr bScore SCORE_DRAW
Definition eval.h:25
constexpr bScore SCORE_BETAMARGIN
Definition eval.h:28
constexpr bScore SCORE_THEORETIC_DRAW
Definition eval.h:16
constexpr bScore SCORE_INFINITE
Definition eval.h:20
enum tPiece piece_t
Definition piece.h:44