Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
move.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: move.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(MOVE_H)
9#define MOVE_H
10
11/** move */
13public:
14 explicit bBasicMove(bBasicMove const& bm);
15 explicit bBasicMove(bBasicMove&& bm);
16 explicit bBasicMove(basicmove_t const bmt);
17 explicit bBasicMove(case_t cf, case_t ct);
18 virtual ~bBasicMove();
19
22
23 operator std::string() const;
24
26 return static_cast<case_t>(m_bmove ? (m_bmove & 0x00FF) : 0xFF);
27 }
28
30 return static_cast<case_t>(m_bmove ? ((m_bmove >> 8) & 0x00FF) : 0xFF);
31 }
32
33 rank_t fromrank() const { return bCase::rank(from()); }
34 column_t fromcolumn() const { return bCase::column(from()); }
35 rank_t torank() const { return bCase::rank(to()); }
36 column_t tocolumn() const { return bCase::column(to()); }
37
38 basicmove_t getBasicMoveT() const { return m_bmove; }
39 ppiece_t getPromotion() const { return m_promotion; }
40
41protected:
42 union {
43 uint32_t u_bmove = 0UL; // initialise all subsequent fields to 0
44 struct {
46 uint8_t m_flag;
47 // 0b00000000 some flags are not set in basicmove
48 // ^ capture move - 0x80 - 128
49 // ^ pawn move - 0x40 - 64
50 // ^ ep move - 0x20 - 32
51 // ^ double pawn move - 0x10 - 16
52 // ^ long castle move - 0x08 - 8
53 // ^ short castle - 0x04 - 4
54 // ^ check move - 0x02 - 2
55 // ^ game end - 0x01 - 1
56 ppiece_t m_promotion; // 0 for no promotion
57 };
58 };
59
60private:
61 std::string const getPromotionDecorationStr() const;
62
63private:
64 friend std::ostream& operator<<(std::ostream& os, bBasicMove const& m);
65};
66
67//-----------------------------------------------------------------------
68
69class bMove : public bBasicMove {
70public:
71 bMove(bMove const& m);
72 explicit bMove(bMove&& m);
73 explicit bMove(case_t cf, case_t ct);
74 ~bMove() override;
75
76 bMove& operator=(bMove&& m);
77 bool operator>(bMove const& r) const;
78
79 bMove& operator=(bMove const&) = delete;
80
83 bool isPromotion() const { return m_promotion; }
84 bool isMajorPromotion() const;
85 void setPromotion(const ppiece_t p) { m_promotion = p; }
86
87 bool isCapture() const { return m_flag & 0x80; }
88 void setCapture() { m_flag |= 0x80; }
89 bool isPawnMove() const { return m_flag & 0x40; }
90 void setPawnMove() { m_flag |= 0x40; }
91 bool isCastleMove() const { return m_flag & (0x08 | 0x04); }
92 void setShortCastleMove() { m_flag |= 0x04; }
93 void setLongCastleMove() { m_flag |= 0x08; }
94 bool isLongCastleMove() const { return m_flag & 0x08; }
95 bool isCheck() const { return m_flag & 0x02; }
96 void setCheck() { m_flag |= 0x02; }
97 void setGameEnd() { m_flag |= 0x01; }
98 bool getGameEnd() const { return m_flag & 0x01; }
99 bool isEndOfGame() const;
100 bool isEPPossible() const { return m_flag & 0x10; }
101 void setEPPossible() { m_flag |= 0x10; }
102 bool isEPMove() const { return m_flag & 0x20; }
103 void setEPMove() { m_flag |= 0x20; }
104 bool isNonSilent() const { return isCapture() || isMajorPromotion() || isEPMove(); }
105
106 void setScore(bScore const s) { m_score = s; }
107 bScore getScore() const { return m_score; }
108 std::string getMoveEvalStr() const;
109
110private:
111 bScore m_score = SCORE_UNDEFINED;
112};
113
114#endif // defined MOVE_H
115
116// eof
int8_t rank_t
Definition belofte.h:104
uint16_t basicmove_t
Definition belofte.h:107
int8_t column_t
Definition belofte.h:105
uint8_t case_t
Definition belofte.h:106
int16_t bScore
move
Definition move.h:12
ppiece_t m_promotion
Definition move.h:56
basicmove_t getBasicMoveT() const
Definition move.h:38
MEMBER_CONSTEXPR case_t to() const
Definition move.h:29
uint8_t m_flag
Definition move.h:46
MEMBER_CONSTEXPR case_t from() const
Definition move.h:25
rank_t fromrank() const
Definition move.h:33
column_t fromcolumn() const
Definition move.h:34
bBasicMove & operator=(bBasicMove &&bm)
Definition move.cpp:45
basicmove_t m_bmove
Definition move.h:45
friend std::ostream & operator<<(std::ostream &os, bBasicMove const &m)
Definition move.cpp:73
uint32_t u_bmove
Definition move.h:43
virtual ~bBasicMove()
Definition move.cpp:35
rank_t torank() const
Definition move.h:35
ppiece_t getPromotion() const
Definition move.h:39
column_t tocolumn() const
Definition move.h:36
column_t column() const
Definition case.h:37
rank_t rank() const
Definition case.h:38
Definition move.h:69
void setCheck()
Definition move.h:96
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 & operator=(bMove const &)=delete
bool getGameEnd() const
Definition move.h:98
bool isCastleMove() const
Definition move.h:91
bool isNonSilent() const
Definition move.h:104
bool isEPPossible() const
Definition move.h:100
bool isPromotion() const
Definition move.h:83
bool isCheck() const
Definition move.h:95
void setEPMove()
Definition move.h:103
bScore getScore() const
Definition move.h:107
void setCapture()
Definition move.h:88
std::string getMoveEvalStr() const
Definition move.cpp:116
piece_t getWhitePromotionPiece() const
Definition move.cpp:159
void setGameEnd()
Definition move.h:97
void setPawnMove()
Definition move.h:90
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
void setPromotion(const ppiece_t p)
Definition move.h:85
bool isPawnMove() const
Definition move.h:89
~bMove() override
Definition move.cpp:99
void setScore(bScore const s)
Definition move.h:106
void setShortCastleMove()
Definition move.h:92
bool isLongCastleMove() const
Definition move.h:94
void setLongCastleMove()
Definition move.h:93
void setEPPossible()
Definition move.h:101
constexpr bScore SCORE_UNDEFINED
Definition eval.h:20
#define MEMBER_CONSTEXPR
Definition myplatform.h:188
enum tPPiece ppiece_t
Definition piece.h:52
enum tPiece piece_t
Definition piece.h:44