/// Castle rights, encoded as bit fields
-enum CastleRights {
+enum CastleRight {
CASTLES_NONE = 0,
WHITE_OO = 1,
BLACK_OO = 2,
Square king_square(Color c) const;
// Castling rights
- bool can_castle_kingside(Color c) const;
- bool can_castle_queenside(Color c) const;
+ bool can_castle(CastleRight f) const;
bool can_castle(Color c) const;
- Square initial_kr_square(Color c) const;
- Square initial_qr_square(Color c) const;
+ Square castle_rook_square(CastleRight f) const;
// Bitboards for pinned pieces and discovered check candidates
Bitboard discovered_check_candidates(Color c) const;
void clear();
void detach();
void put_piece(Piece p, Square s);
- void set_castle_kingside(Color c);
- void set_castle_queenside(Color c);
+ void set_castle(int f, Square ksq, Square rsq);
void set_castling_rights(char token);
bool move_is_pl_slow(const Move m) const;
Color sideToMove;
Key history[MaxGameLength];
int castleRightsMask[64];
+ Square castleRookSquare[16]; // [CastleRights]
StateInfo startState;
- File initialKFile, initialKRFile, initialQRFile;
bool chess960;
int fullMoves;
int threadID;
return pieceList[c][KING][0];
}
-inline bool Position::can_castle_kingside(Color c) const {
- return st->castleRights & (WHITE_OO << c);
-}
-
-inline bool Position::can_castle_queenside(Color c) const {
- return st->castleRights & (WHITE_OOO << c);
+inline bool Position::can_castle(CastleRight f) const {
+ return st->castleRights & f;
}
inline bool Position::can_castle(Color c) const {
return st->castleRights & ((WHITE_OO | WHITE_OOO) << c);
}
-inline void Position::set_castle_kingside(Color c) {
- st->castleRights |= (WHITE_OO << c);
-}
-
-inline void Position::set_castle_queenside(Color c) {
- st->castleRights |= (WHITE_OOO << c);
-}
-
-inline Square Position::initial_kr_square(Color c) const {
- return relative_square(c, make_square(initialKRFile, RANK_1));
-}
-
-inline Square Position::initial_qr_square(Color c) const {
- return relative_square(c, make_square(initialQRFile, RANK_1));
+inline Square Position::castle_rook_square(CastleRight f) const {
+ return castleRookSquare[f];
}
template<>