Belofte version 2.1.9
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 2 - 0x4000 draw
15// bit 3 - 16 : 0x2FFF real score
16
17constexpr bScore SCORE_THEORETIC_DRAW = 0x4000; // 163.84
18constexpr bScore SCORE_PRACTICAL_DRAW = -SCORE_THEORETIC_DRAW; // negative draw score
19constexpr bScore SCORE_INFINITE = 0x3FFF; // 163.83 (or 0xBFFF for negative)
20constexpr bScore SCORE_PUNDEFINED = 0x3FF0; // 163.68 (or 0xBFF0 for negative)
22
23constexpr bScore SCORE_ALMOST_NORMAL = 0x2FFF; // 122.87
24constexpr bScore SCORE_MATE = 0x2F4F; // 121.11
25constexpr bScore SCORE_WINNING = 0x27FF; // 102.39 centipawns is maximum score
26constexpr bScore SCORE_RESIGN = 0x0578; // 14.00
27constexpr bScore SCORE_ALMOST_DRAW = 0x000A; // 0.10
28constexpr bScore SCORE_DRAW = 0x0000; // 0
29
30constexpr bScore SCORE_CONVERGE_BYDEPTH = 1; // 0.01
31constexpr bScore SCORE_BETAMARGIN = 80; // 0.80
32
33// attention, ordering is used in std::string bGame::getResult
42
44
45//-----------------------------------------------------------------------
46
48public:
50 : m_name{"None"}
51 {}
52 explicit bPositionEvaluation(std::string const& s);
54 {}
55
56 // no copy or move ctor nor assignment defined
61
62 virtual bScore getEvaluation(bBoard const& b) const;
63
64 operator std::string() const&
65 { return const_cast<std::string const&>(m_name); }
66
67public:
68 static gameResult_t gameEndedResult(bBoard const& b);
69 static bScore resultToScoreFlag(gameResult_t const gr);
70 static inline bool isDrawResult(gameResult_t const gr)
71 { return (gr >= GR_DRAW_STALEMATE) && (gr <= GR_DRAW_OTHER); }
72
73private:
74 static int8_t nFoldRepetition(bBoard const& b);
75 static bool twoFoldRepetition(bBoard const& b);
76 static bool threeFoldRepetition(bBoard const& b);
77 static bool insufficientMaterial(bBoard const& b);
78
79 std::string m_name;
80};
81
82//-----------------------------------------------------------------------
83
85public:
87 : bPositionEvaluation("PiecesOnly")
88 {}
90 {}
91
92 // no copy or move ctor nor assignment defined
97
98 bScore getEvaluation(bBoard const& b) const override;
99};
100
101//-----------------------------------------------------------------------
102
104public:
106 : bPositionEvaluation("StaticBoard")
107 {}
108 explicit PosEvalStaticBoard(std::string const& s)
110 {}
112 {}
113
114 // no copy or move ctor nor assignment defined
119
120 bScore getEvaluation(bBoard const& b) const override;
121
122protected:
123 bScore getRelativeBoardEval(bBoard const& b) const;
124 bScore getEndgameEvaluation(bBoard const &b) const;
125 bScore getPawnEndingEvaluation(bBoard const &b) const;
126 bScore getMatingEvaluation(bBoard const &b) const;
127};
128
129//-----------------------------------------------------------------------
130
132public:
134 : PosEvalStaticBoard("PositionalBoard")
135 {}
137 {}
138
139 bScore getEvaluation(bBoard const& b) const override;
140
141private:
142 bScore getKingEvaluation(bBoard const& b) const;
143
144 bScore getPawnEvaluation(bBoard const& b) const;
145 bool whitePassed(bBoard const& b, column_t const iCol) const;
146 bool blackPassed(bBoard const& b, column_t const iCol) const;
147
148 bScore getRookEvaluation(bBoard const& b) const;
149 bool seesHorVer(bBoard const& b, column_t const iCol,
150 rank_t const iRank, piece_t const matchPiece) const;
151 bool sameRank(bBoard const& b, column_t const iCol, rank_t const iRank,
152 piece_t const matchPiece) const;
153 bool sameCol(bBoard const& b, column_t const iCol, rank_t const iRank,
154 piece_t const matchPiece) const;
155 bool whiteKingSameRankCol(bBoard const& b, column_t const iCol,
156 rank_t const iRank) const;
157 bool blackKingSameRankCol(bBoard const& b, column_t const iCol,
158 rank_t const iRank) const;
159 bScore openLineValWhite(bBoard const& b, column_t const iCol,
160 rank_t iRank) const;
161 bScore openLineValBlack(bBoard const& b, column_t const iCol,
162 rank_t iRank) const;
163 bScore rookRankValWhite(bBoard const& b, rank_t const iRank) const;
164 bScore rookRankValBlack(bBoard const& b, rank_t const iRank) const;
165
166 bScore getBishopEvaluation(bBoard const& b) const;
167 bool sameDiagonal(bBoard const& b, column_t const iCol,
168 rank_t const iRank, piece_t const matchPiece) const;
169 bool sameColour(bBoard const& b, case_t const c,
170 piece_t const matchPiece) const;
171 bool sameColourWhiteKing(bBoard const& b, case_t const iCol) const;
172 bool sameColourBlackKing(bBoard const& b, case_t const iCol) const;
173
174 bScore getQueenEvaluation(bBoard const& b) const;
175};
176
177#endif // defined EVAL_H
178
179// eof
int8_t rank_t
Definition belofte.h:94
int8_t column_t
Definition belofte.h:95
uint8_t case_t
Definition belofte.h:96
PosEvalPiecesOnly(PosEvalPiecesOnly &&)=delete
PosEvalPiecesOnly()
Definition eval.h:86
PosEvalPiecesOnly & operator=(PosEvalPiecesOnly const &)=delete
PosEvalPiecesOnly & operator=(PosEvalPiecesOnly &&)=delete
PosEvalPiecesOnly(PosEvalPiecesOnly const &)=delete
bScore getEvaluation(bBoard const &b) const override
get pure material evaluation of score
Definition eval.cpp:446
~PosEvalPiecesOnly() override
Definition eval.h:89
~PosEvalPositionalBoard() override
Definition eval.h:136
bScore getEvaluation(bBoard const &b) const override
get positional evaluation
Definition eval.cpp:551
bScore getMatingEvaluation(bBoard const &b) const
Definition eval.cpp:531
PosEvalStaticBoard(PosEvalStaticBoard &&)=delete
bScore getEndgameEvaluation(bBoard const &b) const
Definition eval.cpp:501
PosEvalStaticBoard(std::string const &s)
Definition eval.h:108
~PosEvalStaticBoard() override
Definition eval.h:111
bScore getRelativeBoardEval(bBoard const &b) const
Definition eval.cpp:483
bScore getEvaluation(bBoard const &b) const override
get material and case related modification of score
Definition eval.cpp:466
PosEvalStaticBoard(PosEvalStaticBoard const &)=delete
PosEvalStaticBoard & operator=(PosEvalStaticBoard &&)=delete
bScore getPawnEndingEvaluation(bBoard const &b) const
Definition eval.cpp:517
PosEvalStaticBoard & operator=(PosEvalStaticBoard const &)=delete
board
Definition board.h:45
virtual ~bPositionEvaluation()
Definition eval.h:53
static bScore resultToScoreFlag(gameResult_t const gr)
Class static function convert all draw scores to SCORE_THEORETIC_DRAW.
Definition eval.cpp:77
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:70
bPositionEvaluation & operator=(bPositionEvaluation const &)=delete
bPositionEvaluation(bPositionEvaluation &&)=delete
bPositionEvaluation(bPositionEvaluation const &)=delete
bPositionEvaluation & operator=(bPositionEvaluation &&)=delete
virtual bScore getEvaluation(bBoard const &b) const
get final score or 0
Definition eval.cpp:433
constexpr bScore SCORE_ALMOST_NORMAL
Definition eval.h:23
gameResult
Definition eval.h:34
@ GR_DRAW_50
Definition eval.h:37
@ GR_UNSET
Definition eval.h:35
@ GR_DRAW_OTHER
Definition eval.h:38
@ GR_DRAW_FLAG
Definition eval.h:38
@ GR_WHITEWINS_ADJ
Definition eval.h:39
@ GR_DRAW_STALEMATE
Definition eval.h:37
@ GR_WHITEWINS_FLAG
Definition eval.h:39
@ GR_BLACKWINS_ADJ
Definition eval.h:40
@ GR_UNKNOWN
Definition eval.h:36
@ GR_WHITEMATES
Definition eval.h:39
@ GR_WHITERESIGNS
Definition eval.h:40
@ GR_BLACKMATES
Definition eval.h:40
@ GR_DRAW_LACKMATERIAL
Definition eval.h:37
@ GR_BLACKWINS_FLAG
Definition eval.h:40
@ GR_DRAW_THREEFOLD
Definition eval.h:37
@ GR_BLACKRESIGNS
Definition eval.h:39
@ GR_DRAW_ADJ
Definition eval.h:38
constexpr bScore SCORE_MATE
Definition eval.h:24
enum gameResult gameResult_t
Definition eval.h:43
constexpr bScore SCORE_PUNDEFINED
Definition eval.h:20
int16_t bScore
Definition eval.h:11
constexpr bScore SCORE_PRACTICAL_DRAW
Definition eval.h:18
constexpr bScore SCORE_ALMOST_DRAW
Definition eval.h:27
constexpr bScore SCORE_RESIGN
Definition eval.h:26
constexpr bScore SCORE_CONVERGE_BYDEPTH
Definition eval.h:30
constexpr bScore SCORE_WINNING
Definition eval.h:25
constexpr bScore SCORE_UNDEFINED
Definition eval.h:21
constexpr bScore SCORE_DRAW
Definition eval.h:28
constexpr bScore SCORE_BETAMARGIN
Definition eval.h:31
constexpr bScore SCORE_THEORETIC_DRAW
Definition eval.h:17
constexpr bScore SCORE_INFINITE
Definition eval.h:19
enum tPiece piece_t
Definition piece.h:44