From: Marco Costalba Date: Thu, 13 Mar 2014 11:53:03 +0000 (+0100) Subject: Reformat do_castling() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=6571acffaa08755fe83292a84ba4c762632bed82;ds=inline Reformat do_castling() No functional change. --- diff --git a/src/position.cpp b/src/position.cpp index 3f019770..d4a84ed2 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -739,14 +739,10 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI { assert(pc == make_piece(us, KING)); - bool kingSide = to > from; - Square rfrom = to; // Castling is encoded as "king captures friendly rook" - Square rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1); - to = relative_square(us, kingSide ? SQ_G1 : SQ_C1); - captured = NO_PIECE_TYPE; - - do_castling(from, to, rfrom, rto); + Square rfrom, rto; + do_castling(from, to, rfrom, rto); + captured = NO_PIECE_TYPE; st->psq += psq[us][ROOK][rto] - psq[us][ROOK][rfrom]; k ^= Zobrist::psq[us][ROOK][rfrom] ^ Zobrist::psq[us][ROOK][rto]; } @@ -933,13 +929,11 @@ void Position::undo_move(Move m) { if (type_of(m) == CASTLING) { - bool kingSide = to > from; - Square rfrom = to; // Castling is encoded as "king captures friendly rook" - Square rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1); - to = relative_square(us, kingSide ? SQ_G1 : SQ_C1); + Square rfrom, rto; + do_castling(from, to, rfrom, rto); + captured = NO_PIECE_TYPE; pt = KING; - do_castling(to, from, rto, rfrom); } else move_piece(to, from, us, pt); // Put the piece back at the source square @@ -971,15 +965,20 @@ void Position::undo_move(Move m) { /// Position::do_castling() is a helper used to do/undo a castling move. This /// is a bit tricky, especially in Chess960. +template +void Position::do_castling(Square from, Square& to, Square& rfrom, Square& rto) { -void Position::do_castling(Square kfrom, Square kto, Square rfrom, Square rto) { + bool kingSide = to > from; + rfrom = to; // Castling is encoded as "king captures friendly rook" + rto = relative_square(sideToMove, kingSide ? SQ_F1 : SQ_D1); + to = relative_square(sideToMove, kingSide ? SQ_G1 : SQ_C1); // Remove both pieces first since squares could overlap in Chess960 - remove_piece(kfrom, sideToMove, KING); - remove_piece(rfrom, sideToMove, ROOK); - board[kfrom] = board[rfrom] = NO_PIECE; // Since remove_piece doesn't do it for us - put_piece(kto, sideToMove, KING); - put_piece(rto, sideToMove, ROOK); + remove_piece(Do ? from : to, sideToMove, KING); + remove_piece(Do ? rfrom : rto, sideToMove, ROOK); + board[Do ? from : to] = board[Do ? rfrom : rto] = NO_PIECE; // Since remove_piece doesn't do it for us + put_piece(Do ? to : from, sideToMove, KING); + put_piece(Do ? rto : rfrom, sideToMove, ROOK); } diff --git a/src/position.h b/src/position.h index 935d86b2..34c427d4 100644 --- a/src/position.h +++ b/src/position.h @@ -174,11 +174,12 @@ private: void set_state(StateInfo* si) const; // Helper functions - void do_castling(Square kfrom, Square kto, Square rfrom, Square rto); Bitboard check_blockers(Color c, Color kingColor) const; void put_piece(Square s, Color c, PieceType pt); void remove_piece(Square s, Color c, PieceType pt); void move_piece(Square from, Square to, Color c, PieceType pt); + template + void do_castling(Square from, Square& to, Square& rfrom, Square& rto); // Board and pieces Piece board[SQUARE_NB];