Belofte version 2.1.8
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
11// bit 1 - 0x8000 negative
12// bit 2 - 0x4000 draw
13// bit 3 - 16 : 0x2FFF real score
14
15constexpr bScore SCORE_INFINITE = 0x3FFF; // (or 0xBFFF for negative)
16constexpr bScore SCORE_POSITIVE = 0x7FFF;
17constexpr bScore SCORE_THEORETIC_DRAW = 0x4000;
18constexpr bScore SCORE_PRACTICAL_DRAW = SCORE_THEORETIC_DRAW | ~SCORE_POSITIVE; // negative draw score
19constexpr bScore SCORE_PUNDEFINED = 0x3FFE; // draw bit unset, positive (0xBFFE for positive)
20constexpr bScore SCORE_UNDEFINED = SCORE_PUNDEFINED | ~SCORE_POSITIVE;
21
22constexpr bScore SCORE_ALMOST_NORMAL = 0x2FFF; // 122.87
23constexpr bScore SCORE_MATE = 0x2F4F; // 121.11
24constexpr bScore SCORE_WINNING = 0x27FF; // 102.39 centipawns is maximum score
25constexpr bScore SCORE_RESIGN = 0x0578; // 14.00
26constexpr bScore SCORE_ALMOST_DRAW = 0x000A; // 0.10
27constexpr bScore SCORE_DRAW = 0x0000; // 0
28
29constexpr bScore SCORE_CONVERGE_BYDEPTH = 1; // 0.01
30constexpr bScore SCORE_BETAMARGIN = 80; // 0.80
31
32// attention, ordering is used in std::string bGame::getResult
40
42
43namespace belofte {
44 bScore realScore(bScore const sc);
45}
46
47//-----------------------------------------------------------------------
48
50public:
51 explicit bPositionEvaluation(std::string const& n);
52 virtual ~bPositionEvaluation();
53
54 // no copy or move ctor nor assignment defined
59
60 operator std::string() const& { return const_cast<std::string const&>(m_name); }
61
62 virtual bScore getEvaluation(bBoard const& b) const = 0;
63
64 gameResult_t isGameEnded(bBoard const& b) const;
65
66public:
67 static bScore pieceValue(piece_t const p);
68 static bScore mymove_pieceValue(piece_t const p);
69 static bScore centerplay_pieceValue(case_t const p);
70
71protected:
73
74private:
75 std::string getPieceList(bBoard const& b) const;
76 int8_t nFoldRepetition(bBoard const& b) const;
77 bool twoFoldRepetition(bBoard const& b) const;
78 bool threeFoldRepetition(bBoard const& b) const;
79 bool insufficientMaterial(bBoard const& b) const;
80 bool sameColorBishops(bBoard const& b) const;
81
82 std::string m_name;
83};
84
85//-----------------------------------------------------------------------
86
88public:
90 ~PosEvalPiecesOnly() override;
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 explicit PosEvalStaticBoard(std::string const& n);
107 ~PosEvalStaticBoard() override;
108
109 // no copy or move ctor nor assignment defined
114
115 bScore getEvaluation(bBoard const& b) const override;
116
117protected:
118 bScore getRelativeBoardEval(bBoard const& b) const;
119 bScore getEndgameEvaluation(bBoard const &b) const;
120 bScore getPawnEndingEvaluation(bBoard const &b) const;
121 bScore getMatingEvaluation(bBoard const &b) const;
122};
123
124//-----------------------------------------------------------------------
125
127public:
129 ~PosEvalPositionalBoard() override;
130
131 bScore getEvaluation(bBoard const& b) const override;
132
133private:
134 bScore getKingEvaluation(bBoard const& b) const;
135
136 bScore getPawnEvaluation(bBoard const& b) const;
137 bool whitePassed(bBoard const& b, column_t const iCol) const;
138 bool blackPassed(bBoard const& b, column_t const iCol) const;
139
140 bScore getRookEvaluation(bBoard const& b) const;
141 bool seesHorVer(bBoard const& b, column_t const iCol,
142 rank_t const iRank, piece_t const matchPiece) const;
143 bool sameRank(bBoard const& b, column_t const iCol, rank_t const iRank,
144 piece_t const matchPiece) const;
145 bool sameCol(bBoard const& b, column_t const iCol, rank_t const iRank,
146 piece_t const matchPiece) const;
147 bool whiteKingSameRankCol(bBoard const& b, column_t const iCol,
148 rank_t const iRank) const;
149 bool blackKingSameRankCol(bBoard const& b, column_t const iCol,
150 rank_t const iRank) const;
151 bScore openLineValWhite(bBoard const& b, column_t const iCol,
152 rank_t const iRank) const;
153 bScore openLineValBlack(bBoard const& b, column_t const iCol,
154 rank_t const iRank) const;
155 bScore rookRankValWhite(bBoard const& b, rank_t const iRank) const;
156 bScore rookRankValBlack(bBoard const& b, rank_t const iRank) const;
157
158 bScore getBishopEvaluation(bBoard const& b) const;
159 bool sameDiagonal(bBoard const& b, column_t const iCol,
160 rank_t const iRank, piece_t const matchPiece) const;
161 bool sameColour(bBoard const& b, case_t const c,
162 piece_t const matchPiece) const;
163 bool sameColourWhiteKing(bBoard const& b, case_t const iCol) const;
164 bool sameColourBlackKing(bBoard const& b, case_t const iCol) const;
165
166 bScore getQueenEvaluation(bBoard const& b) const;
167};
168
169#endif // defined EVAL_H
170
171// eof
int8_t rank_t
Definition belofte.h:104
int8_t column_t
Definition belofte.h:105
uint8_t case_t
Definition belofte.h:106
int16_t bScore
PosEvalPiecesOnly(PosEvalPiecesOnly &&)=delete
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:407
~PosEvalPiecesOnly() override
Definition eval.cpp:401
~PosEvalPositionalBoard() override
Definition eval.cpp:527
bScore getEvaluation(bBoard const &b) const override
get positional evaluation
Definition eval.cpp:533
bScore getMatingEvaluation(bBoard const &b) const
Definition eval.cpp:505
PosEvalStaticBoard(PosEvalStaticBoard &&)=delete
bScore getEndgameEvaluation(bBoard const &b) const
Definition eval.cpp:475
~PosEvalStaticBoard() override
Definition eval.cpp:434
bScore getRelativeBoardEval(bBoard const &b) const
Definition eval.cpp:457
bScore getEvaluation(bBoard const &b) const override
get material and case related modification of score
Definition eval.cpp:440
PosEvalStaticBoard(PosEvalStaticBoard const &)=delete
PosEvalStaticBoard & operator=(PosEvalStaticBoard &&)=delete
bScore getPawnEndingEvaluation(bBoard const &b) const
Definition eval.cpp:491
PosEvalStaticBoard & operator=(PosEvalStaticBoard const &)=delete
board
Definition board.h:147
virtual bScore getEvaluation(bBoard const &b) const =0
static bScore pieceValue(piece_t const p)
Definition eval.cpp:347
virtual ~bPositionEvaluation()
Definition eval.cpp:390
gameResult_t isGameEnded(bBoard const &b) const
See if board is in finite state, meaning game is ended.
Definition eval.cpp:38
bPositionEvaluation & operator=(bPositionEvaluation const &)=delete
bScore resultToScoreFlag(gameResult_t const sc) const
convert all draw scores to SCORE_THEORETIC_DRAW
Definition eval.cpp:64
bPositionEvaluation(bPositionEvaluation &&)=delete
static bScore centerplay_pieceValue(case_t const p)
Definition eval.cpp:357
bPositionEvaluation(bPositionEvaluation const &)=delete
static bScore mymove_pieceValue(piece_t const p)
Definition eval.cpp:352
bPositionEvaluation & operator=(bPositionEvaluation &&)=delete
constexpr bScore SCORE_ALMOST_NORMAL
Definition eval.h:22
gameResult
Definition eval.h:33
@ GR_DRAW_50
Definition eval.h:35
@ GR_DRAW_OTHER
Definition eval.h:36
@ GR_DRAW_FLAG
Definition eval.h:36
@ GR_WHITEWINS_ADJ
Definition eval.h:37
@ GR_DRAW_STALEMATE
Definition eval.h:35
@ GR_WHITEWINS_FLAG
Definition eval.h:37
@ GR_BLACKWINS_ADJ
Definition eval.h:38
@ GR_UNKNOWN
Definition eval.h:34
@ GR_WHITEMATES
Definition eval.h:37
@ GR_WHITERESIGNS
Definition eval.h:38
@ GR_BLACKMATES
Definition eval.h:38
@ GR_DRAW_LACKMATERIAL
Definition eval.h:35
@ GR_BLACKWINS_FLAG
Definition eval.h:38
@ GR_DRAW_THREEFOLD
Definition eval.h:35
@ GR_BLACKRESIGNS
Definition eval.h:37
@ GR_DRAW_ADJ
Definition eval.h:36
constexpr bScore SCORE_MATE
Definition eval.h:23
enum gameResult gameResult_t
Definition eval.h:41
constexpr bScore SCORE_PUNDEFINED
Definition eval.h:19
constexpr bScore SCORE_PRACTICAL_DRAW
Definition eval.h:18
constexpr bScore SCORE_ALMOST_DRAW
Definition eval.h:26
constexpr bScore SCORE_RESIGN
Definition eval.h:25
constexpr bScore SCORE_CONVERGE_BYDEPTH
Definition eval.h:29
constexpr bScore SCORE_WINNING
Definition eval.h:24
constexpr bScore SCORE_POSITIVE
Definition eval.h:16
constexpr bScore SCORE_UNDEFINED
Definition eval.h:20
constexpr bScore SCORE_DRAW
Definition eval.h:27
constexpr bScore SCORE_BETAMARGIN
Definition eval.h:30
constexpr bScore SCORE_THEORETIC_DRAW
Definition eval.h:17
constexpr bScore SCORE_INFINITE
Definition eval.h:15
Allow index mapper for char values of piece into int in 1-12 range to reduce space and easy initialis...
Definition eval.h:43
bScore realScore(bScore const sc)
Definition eval.cpp:23
enum tPiece piece_t
Definition piece.h:44