Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
move.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: move.cpp
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#include "belofte.h"
9
10//-----------------------------------------------------------------------
11// bBasicMove functions
12
14 : u_bmove{bm.u_bmove}
15{
16}
17
19 : u_bmove{std::move(bm.u_bmove)}
20{
21}
22
24 : m_bmove{bmt}
25{
26 // TODO: add initial sorting score
27}
28
30{
31 // TODO: add initial sorting score
32 m_bmove = static_cast<basicmove_t>((ct << 8) | cf);
33}
34
38
40{
41 u_bmove = bm.u_bmove;
42 return *this;
43}
44
46{
47 u_bmove = std::move(bm.u_bmove);
48 return *this;
49}
50
51bBasicMove::operator std::string() const
52{
53 return bCase(from()).operator std::string()
54 + bCase(to()).operator std::string()
55 + getPromotionDecorationStr();
56}
57
58std::string const bBasicMove::getPromotionDecorationStr() const
59{
60 if (!m_promotion) {
61 return "";
62 } else if (m_promotion == tPPiece::N_P_QUEEN) {
63 return "q";
64 } else if (m_promotion == tPPiece::N_P_KNIGHT) {
65 return "n";
66 } else if (m_promotion == tPPiece::N_P_ROOK) {
67 return "r";
68 } else {
69 return "b";
70 }
71}
72
73std::ostream& operator<<(std::ostream& os, bBasicMove const& m)
74{
75 os << m.operator std::string();
76 return os;
77}
78
79//-----------------------------------------------------------------------
80// bMove functions
81
83 : bBasicMove{m}
84 , m_score{m.m_score}
85{
86}
87
89 : bBasicMove{std::move(m)}
90 , m_score{std::move(m.m_score)}
91{
92}
93
95 : bBasicMove{cf, ct}
96{
97}
98
100{
101}
102
104{
105 bBasicMove::operator=(std::move(m));
106 m_score = std::move(m.m_score);
107 return *this;
108}
109
110bool bMove::operator>(bMove const& r) const
111{
112 return belofte::realScore(m_score) > belofte::realScore(r.m_score);
113}
114
115// TODO: convert to move annotation to be used in PgnMove as well
116std::string bMove::getMoveEvalStr() const
117{
118 std::string str;
119 if (isCheck()) {
120 if (((m_score & SCORE_POSITIVE) != SCORE_THEORETIC_DRAW)
121 && isEndOfGame())
122 str = "#";
123 else
124 str = "+";
125 }
126 if (isEPMove()) str += (str != "") ? " e.p." : "e.p.";
127 else if (isCapture()) str += (str != "") ? " x" : "x";
128 if ((m_score & SCORE_POSITIVE) != SCORE_PUNDEFINED) {
129 if (str != "") str += " ";
130 str += belofte::scoreAsStr(m_score);
131 }
132 if (str != "") return " {" + str + "}";
133 return "";
134}
135
136/**
137 * Flag if mated
138 * @return true if game ended
139 */
141{
142 if (getGameEnd()) return true;
143 if (((m_score & SCORE_POSITIVE) != SCORE_PUNDEFINED) && isCheck()) {
144 if ((m_score & SCORE_POSITIVE) >= (SCORE_MATE - SCORE_CONVERGE_BYDEPTH)) return true;
145 }
146 return false;
147}
148
149/** test if major promotion or mating promotion (queen, knight)
150 * if minor promotion, move is considered as silent
151 */
153{
155 || (m_promotion == tPPiece::N_P_KNIGHT)) return true;
156 return false;
157}
158
160{
162 return tPiece::W_QUEEN;
163 } else if (m_promotion == tPPiece::N_P_KNIGHT) {
164 return tPiece::W_KNIGHT;
165 } else if (m_promotion == tPPiece::N_P_ROOK) {
166 return tPiece::W_ROOK;
167 } else if (m_promotion == tPPiece::N_P_BISHOP) {
168 return tPiece::W_BISHOP;
169 }
170 throw std::logic_error("getWhitePromotionPiece called with tPiece::FIELD_EMPTY");
171}
172
174{
176 return tPiece::B_QUEEN;
177 } else if (m_promotion == tPPiece::N_P_KNIGHT) {
178 return tPiece::B_KNIGHT;
179 } else if (m_promotion == tPPiece::N_P_ROOK) {
180 return tPiece::B_ROOK;
181 } else if (m_promotion == tPPiece::N_P_BISHOP) {
182 return tPiece::B_BISHOP;
183 }
184 throw std::logic_error("getBlackPromotionPiece called with tPiece::FIELD_EMPTY");
185}
186
187// eof
This is the main include file, needs to be included before any other include.
uint16_t basicmove_t
Definition belofte.h:107
uint8_t case_t
Definition belofte.h:106
move
Definition move.h:12
ppiece_t m_promotion
Definition move.h:56
bBasicMove(bBasicMove const &bm)
Definition move.cpp:13
bBasicMove & operator=(bBasicMove &&bm)
Definition move.cpp:45
basicmove_t m_bmove
Definition move.h:45
uint32_t u_bmove
Definition move.h:43
virtual ~bBasicMove()
Definition move.cpp:35
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
Definition case.h:17
Definition move.h:69
piece_t getBlackPromotionPiece() const
Definition move.cpp:173
bool isCapture() const
Definition move.h:87
bool isMajorPromotion() const
test if major promotion or mating promotion (queen, knight) if minor promotion, move is considered as...
Definition move.cpp:152
bMove(bMove const &m)
Definition move.cpp:82
bool getGameEnd() const
Definition move.h:98
bool isCheck() const
Definition move.h:95
std::string getMoveEvalStr() const
Definition move.cpp:116
piece_t getWhitePromotionPiece() const
Definition move.cpp:159
bMove & operator=(bMove &&m)
Definition move.cpp:103
bool operator>(bMove const &r) const
Definition move.cpp:110
bool isEndOfGame() const
Flag if mated.
Definition move.cpp:140
bool isEPMove() const
Definition move.h:102
~bMove() override
Definition move.cpp:99
constexpr bScore SCORE_MATE
Definition eval.h:23
constexpr bScore SCORE_PUNDEFINED
Definition eval.h:19
constexpr bScore SCORE_CONVERGE_BYDEPTH
Definition eval.h:29
constexpr bScore SCORE_POSITIVE
Definition eval.h:16
constexpr bScore SCORE_THEORETIC_DRAW
Definition eval.h:17
std::ostream & operator<<(std::ostream &os, bBasicMove const &m)
Definition move.cpp:73
bScore realScore(bScore const sc)
Definition eval.cpp:23
@ W_KNIGHT
Definition piece.h:39
@ B_BISHOP
Definition piece.h:40
@ W_ROOK
Definition piece.h:39
@ B_ROOK
Definition piece.h:40
@ W_QUEEN
Definition piece.h:39
@ B_KNIGHT
Definition piece.h:40
@ B_QUEEN
Definition piece.h:40
@ W_BISHOP
Definition piece.h:39
enum tPiece piece_t
Definition piece.h:44
@ N_P_KNIGHT
Definition piece.h:48
@ N_P_QUEEN
Definition piece.h:48
@ N_P_ROOK
Definition piece.h:48
@ N_P_BISHOP
Definition piece.h:48