36 uint8_t
const black_rook_queen_side_moved = 1;
37 uint8_t
const black_rook_king_side_moved = 2;
38 uint8_t
const black_king_moved = 4;
39 uint8_t
const black_king_in_check = 8;
40 uint8_t
const white_king_in_check = 16;
41 uint8_t
const white_rook_queen_side_moved = 32;
42 uint8_t
const white_rook_king_side_moved = 64;
43 uint8_t
const white_king_moved = 128;
70 CastleFlags& operator=(uint8_t bits) { M_bits = bits;
return*
this; }
73 void clear(
void) { M_bits = 231; }
76 void update_removed(
Code const& code,
Index const& index)
81 M_bits |= white_rook_queen_side_moved;
82 else if (index ==
ih1)
83 M_bits |= white_rook_king_side_moved;
88 M_bits |= black_rook_queen_side_moved;
89 else if (index ==
ih8)
90 M_bits |= black_rook_king_side_moved;
95 M_bits |= white_king_moved;
100 M_bits |= black_king_moved;
105 void update_placed(
Code const& code,
Index const& index)
110 M_bits& = ~white_rook_queen_side_moved;
111 else if (index ==
ih1)
112 M_bits& = ~white_rook_king_side_moved;
117 M_bits& = ~black_rook_queen_side_moved;
118 else if (index ==
ih8)
119 M_bits& = ~black_rook_king_side_moved;
124 M_bits& = ~white_king_moved;
129 M_bits& = ~black_king_moved;
134 void piece_moved_from(
Piece const& piece,
Index const& from);
144 if (__builtin_expect((M_bits & (black_king_moved | white_king_moved)) == (black_king_moved | white_king_moved), 1))
147 uint8_t mask = color.
is_white() ? (white_king_moved | white_rook_king_side_moved) : (black_king_moved | black_rook_king_side_moved);
149 return !(M_bits & mask);
156 if (__builtin_expect((M_bits & (black_king_moved | white_king_moved)) == (black_king_moved | white_king_moved), 1))
159 uint8_t mask = color.
is_white() ? (white_king_moved | white_rook_queen_side_moved) : (black_king_moved | black_rook_queen_side_moved);
161 return !(M_bits & mask);
165 void set_check(
Color const& color,
bool check) { uint8_t flag = 8 + color();
if (check) M_bits |= flag;
else M_bits& = ~flag; }
168 bool in_check(
Color const& color)
const { uint8_t flag = 8 + color();
return (M_bits & flag); }
176 #endif // CASTLEFLAGS_H A namespace for all chess related objects that are not related to the GUI.
This file contains the declaration of class Index.
IndexData const ia1
A constant representing the index to square a1.
IndexData const ih1
A constant representing the index to square h1.
bool has_moved(Code const& code, Index const& index)
Return TRUE if code at index is marked as having moved.
IndexData const ih8
A constant representing the index to square h8.
IndexData const ia8
A constant representing the index to square a8.
CodeData const black_rook
A constant representing a black rook;.
The index of a chess square.
CodeData const white_rook
A constant representing a white rook.
A class to keep track of castling rights.
A particular piece on the board.
bool can_castle(Color const& color) const
Return TRUE if color is still allowed to castle at all (not taking into account checks).
bool is_white(void) const
Return TRUE if this color is white.
bool can_castle_long(Color const& color) const
Return TRUE if color is still allowed to castle long (not taking into account checks).
A chess piece type including color.
CodeData const black_king
A constant representing a black king;.
A color (black or white).
CodeData const white_king
A constant representing a white king.
IndexData const ie8
A constant representing the index to square e8.
This file contains the declaration of class Code.
This file contains the declaration of class Piece.
bool can_castle_short(Color const& color) const
Return TRUE if color is still allowed to castle short (not taking into account checks).
IndexData const ie1
A constant representing the index to square e1.
ColorData const black
A constant representing the color black.