1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Get rid of some locals in do_castle_move()

Rewrite the logic to get rid of kBefore and rBefore.

No functional change.
This commit is contained in:
Marco Costalba 2013-01-27 10:56:03 +01:00
parent 52cab06fff
commit 76a0d3c05a

View file

@ -1052,30 +1052,24 @@ void Position::do_castle_move(Move m) {
assert(is_ok(m)); assert(is_ok(m));
assert(type_of(m) == CASTLE); assert(type_of(m) == CASTLE);
Square kto, kfrom, rfrom, rto, kAfter, rAfter;
Color us = sideToMove; Color us = sideToMove;
Square kBefore = from_sq(m); Square kfrom, kto, rfrom, rto;
Square rBefore = to_sq(m);
// Find after-castle squares for king and rook bool kingSide = to_sq(m) > from_sq(m);
if (rBefore > kBefore) // O-O kfrom = kto = from_sq(m);
rfrom = rto = to_sq(m);
if (Do)
{ {
kAfter = relative_square(us, SQ_G1); kto = relative_square(us, kingSide ? SQ_G1 : SQ_C1);
rAfter = relative_square(us, SQ_F1); rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
} }
else // O-O-O else
{ {
kAfter = relative_square(us, SQ_C1); kfrom = relative_square(us, kingSide ? SQ_G1 : SQ_C1);
rAfter = relative_square(us, SQ_D1); rfrom = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
} }
kfrom = Do ? kBefore : kAfter;
rfrom = Do ? rBefore : rAfter;
kto = Do ? kAfter : kBefore;
rto = Do ? rAfter : rBefore;
assert(piece_on(kfrom) == make_piece(us, KING)); assert(piece_on(kfrom) == make_piece(us, KING));
assert(piece_on(rfrom) == make_piece(us, ROOK)); assert(piece_on(rfrom) == make_piece(us, ROOK));