Skip to content

Commit

Permalink
Introduce make_castle_right() helper
Browse files Browse the repository at this point in the history
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
  • Loading branch information
mcostalba committed Apr 8, 2012
1 parent e56342e commit d549497
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/movegen.cpp
Expand Up @@ -35,16 +35,14 @@ namespace {
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());
Expand Down
4 changes: 2 additions & 2 deletions src/pawns.cpp
Expand Up @@ -267,10 +267,10 @@ Score PawnEntry::update_safety(const Position& pos, Square ksq) {
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);
Expand Down
10 changes: 4 additions & 6 deletions src/position.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/types.h
Expand Up @@ -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);
}
Expand Down

0 comments on commit d549497

Please sign in to comment.