From d549497144ee2a704057e005d2bbe1fbc666ca7e Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 8 Apr 2012 17:07:56 +0100 Subject: [PATCH] Introduce make_castle_right() helper No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 6 ++---- src/pawns.cpp | 4 ++-- src/position.cpp | 10 ++++------ src/types.h | 4 ++++ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index ed204672..154e69e2 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -35,16 +35,14 @@ namespace { template MoveStack* generate_castle(const Position& pos, MoveStack* mlist, Color us) { - CastleRight cr = CastleRight((Side == KING_SIDE ? WHITE_OO : WHITE_OOO) << us); - - if (pos.castle_impeded(us, Side) || !pos.can_castle(cr)) + if (pos.castle_impeded(us, Side) || !pos.can_castle(make_castle_right(us, Side))) return mlist; // After castling, the rook and king final positions are the same in Chess960 // as they would be in standard chess. Square kfrom = pos.king_square(us); - Square kto = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1); Square rfrom = pos.castle_rook_square(us, Side); + Square kto = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1); Bitboard enemies = pos.pieces(~us); assert(!pos.in_check()); diff --git a/src/pawns.cpp b/src/pawns.cpp index 795e31e2..7fd4ac07 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -267,10 +267,10 @@ Score PawnEntry::update_safety(const Position& pos, Square ksq) { Value bonus = shelter_storm(pos, ksq); // If we can castle use the bonus after the castle if is bigger - if (pos.can_castle(Us == WHITE ? WHITE_OO : BLACK_OO)) + if (pos.can_castle(make_castle_right(Us, KING_SIDE))) bonus = std::max(bonus, shelter_storm(pos, relative_square(Us, SQ_G1))); - if (pos.can_castle(Us == WHITE ? WHITE_OOO : BLACK_OOO)) + if (pos.can_castle(make_castle_right(Us, QUEEN_SIDE))) bonus = std::max(bonus, shelter_storm(pos, relative_square(Us, SQ_C1))); return kingSafety[Us] = make_score(bonus, 0); diff --git a/src/position.cpp b/src/position.cpp index 60c5380d..8b043af8 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -240,7 +240,7 @@ void Position::set_castle_right(Color c, Square rfrom) { Square kfrom = king_square(c); CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE; - int cr = (cs == KING_SIDE ? WHITE_OO : WHITE_OOO) << c; + CastleRight cr = make_castle_right(c, cs); st->castleRights |= cr; castleRightsMask[kfrom] |= cr; @@ -1727,15 +1727,13 @@ bool Position::pos_is_ok(int* failedStep) const { if (failedStep) (*failedStep)++; if (debugCastleSquares) for (Color c = WHITE; c <= BLACK; c++) - for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s+1)) + for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1)) { - CastleRight cr = CastleRight((s == KING_SIDE ? WHITE_OO : WHITE_OOO) << c); - - if (!can_castle(cr)) + if (!can_castle(make_castle_right(c, s))) continue; if ( piece_on(castleRookSquare[c][s]) != make_piece(c, ROOK) - || castleRightsMask[castleRookSquare[c][s]] != cr) + || castleRightsMask[castleRookSquare[c][s]] != make_castle_right(c, s)) return false; } diff --git a/src/types.h b/src/types.h index a9b95a0a..5b5bc1f2 100644 --- a/src/types.h +++ b/src/types.h @@ -347,6 +347,10 @@ inline Piece make_piece(Color c, PieceType pt) { return Piece((c << 3) | pt); } +inline CastleRight make_castle_right(Color c, CastlingSide s) { + return CastleRight((s == KING_SIDE ? WHITE_OO : WHITE_OOO) << c); +} + inline PieceType type_of(Piece p) { return PieceType(p & 7); } -- 2.39.2