No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
template<CastlingSide Side, bool OnlyChecks>
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());
Value bonus = shelter_storm<Us>(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<Us>(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<Us>(pos, relative_square(Us, SQ_C1)));
return kingSafety[Us] = make_score(bonus, 0);
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;
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;
}
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);
}