X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=20829da26f782ca52b8fef5c18ba9aced711183c;hp=8ec82bebf6d8680d2b8c9015359b80864e7a8f35;hb=049139d025b26a9fbc9cf87f51b578a4fab447cf;hpb=3863cd191c0bcc554ab17c6cd4642b354cec1403 diff --git a/src/position.cpp b/src/position.cpp index 8ec82beb..20829da2 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -384,8 +384,8 @@ Bitboard Position::discovered_check_candidates(Color c) const { Bitboard Position::attacks_to(Square s) const { - return (pawn_attacks(BLACK, s) & pieces(PAWN, WHITE)) - | (pawn_attacks(WHITE, s) & pieces(PAWN, BLACK)) + return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE)) + | (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK)) | (piece_attacks(s) & pieces(KNIGHT)) | (piece_attacks(s) & pieces(ROOK, QUEEN)) | (piece_attacks(s) & pieces(BISHOP, QUEEN)) @@ -402,8 +402,8 @@ bool Position::piece_attacks_square(Piece p, Square f, Square t) const { switch (p) { - case WP: return pawn_attacks_square(WHITE, f, t); - case BP: return pawn_attacks_square(BLACK, f, t); + case WP: return pawn_attacks_square(f, t, WHITE); + case BP: return pawn_attacks_square(f, t, BLACK); case WN: case BN: return piece_attacks_square(f, t); case WB: case BB: return piece_attacks_square(f, t); case WR: case BR: return piece_attacks_square(f, t); @@ -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. @@ -548,7 +548,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { { case PAWN: - if (bit_is_set(pawn_attacks(them, ksq), to)) // Normal check? + if (bit_is_set(pawn_attacks(ksq, them), to)) // Normal check? return true; if ( dcCandidates // Discovered check? @@ -667,7 +667,7 @@ inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square else if ( Piece != KING && !Slider - && bit_is_set(piece_attacks(ksq), to)) + && bit_is_set(Piece == PAWN ? pawn_attacks(ksq, opposite_color(sideToMove)) : piece_attacks(ksq), to)) set_bit(pCheckersBB, to); // Discovery checks @@ -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 @@ -806,7 +806,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { // Set en passant square, only if moved pawn can be captured if (abs(int(to) - int(from)) == 16) { - if (pawn_attacks(us, from + (us == WHITE ? DELTA_N : DELTA_S)) & pieces(PAWN, them)) + if (pawn_attacks(from + (us == WHITE ? DELTA_N : DELTA_S), us) & pieces(PAWN, them)) { st->epSquare = Square((int(from) + int(to)) / 2); key ^= zobEp[st->epSquare]; @@ -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; @@ -1370,8 +1362,8 @@ int Position::see(Square from, Square to) const { | (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN)) | (piece_attacks(to) & pieces(KNIGHT)) | (piece_attacks(to) & pieces(KING)) - | (pawn_attacks(WHITE, to) & pieces(PAWN, BLACK)) - | (pawn_attacks(BLACK, to) & pieces(PAWN, WHITE)); + | (pawn_attacks(to, WHITE) & pieces(PAWN, BLACK)) + | (pawn_attacks(to, BLACK) & pieces(PAWN, WHITE)); if (from != SQ_NONE) break; @@ -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; }