X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fposition.cpp;h=9c91a0969e7ae0f9012cb3b973405803c4244448;hb=62a8f393f17fd8240315d4454fea1ddf5493687b;hp=462088e09c9dee5fc634f0d92fa38a2d5e306876;hpb=6709b01903b9122cf619e8469a0bea96097447e7;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index 462088e0..9c91a096 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -510,7 +510,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { // If the moving piece is a king, check whether the destination // square is attacked by the opponent. if (type_of_piece_on(from) == KING) - return !(square_is_attacked(move_to(m), opposite_color(us))); + return !attacks_to(move_to(m), opposite_color(us)); // A non-king move is legal if and only if it is not pinned or it // is moving along the ray towards or away from the king. @@ -704,7 +704,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { struct ReducedStateInfo { Key key, pawnKey, materialKey; int castleRights, rule50; - Square epSquare; + Square kingSquare[2], epSquare; Value mgValue, egValue; Value npMaterial[2]; }; @@ -786,7 +786,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { // If the moving piece was a king, update the king square if (pt == KING) - kingSquare[us] = to; + st->kingSquare[us] = to; // Update piece lists, note that index[from] is not updated and // becomes stale. This works as long as index[] is accessed just @@ -920,16 +920,15 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ // Update hash key key ^= zobrist[them][capture][capsq]; - // If the captured piece was a pawn, update pawn hash key - if (capture == PAWN) - st->pawnKey ^= zobrist[them][PAWN][capsq]; - // Update incremental scores st->mgValue -= pst(them, capture, capsq); st->egValue -= pst(them, capture, capsq); - // Update material - if (capture != PAWN) + // If the captured piece was a pawn, update pawn hash key, + // otherwise update non-pawn material. + if (capture == PAWN) + st->pawnKey ^= zobrist[them][PAWN][capsq]; + else st->npMaterial[them] -= piece_value_midgame(capture); // Update material hash key @@ -1007,7 +1006,7 @@ void Position::do_castle_move(Move m) { board[rto] = rook; // Update king square - kingSquare[us] = kto; + st->kingSquare[us] = kto; // Update piece lists pieceList[us][KING][index[kfrom]] = kto; @@ -1120,10 +1119,6 @@ void Position::undo_move(Move m) { board[from] = piece_of_color_and_type(us, pt); board[to] = EMPTY; - // If the moving piece was a king, update the king square - if (pt == KING) - kingSquare[us] = from; - // Update piece list index[from] = index[to]; pieceList[us][pt][index[from]] = from; @@ -1209,9 +1204,6 @@ void Position::undo_castle_move(Move m) { board[rfrom] = piece_of_color_and_type(us, ROOK); board[kfrom] = piece_of_color_and_type(us, KING); - // Update king square - kingSquare[us] = kfrom; - // Update piece lists pieceList[us][KING][index[kto]] = kfrom; pieceList[us][ROOK][index[rto]] = rfrom; @@ -1529,7 +1521,7 @@ void Position::put_piece(Piece p, Square s) { pieceCount[c][pt]++; if (pt == KING) - kingSquare[c] = s; + st->kingSquare[c] = s; } @@ -1931,7 +1923,7 @@ bool Position::is_ok(int* failedStep) const { Color us = side_to_move(); Color them = opposite_color(us); Square ksq = king_square(them); - if (square_is_attacked(ksq, us)) + if (attacks_to(ksq, us)) return false; }