X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=2f3c62f552ac8fec90ef1e1bb3fa1d8f7600702e;hp=fade3cbab49d1f27a03912659099a2b3c98097ba;hb=dd4e5db2be2eb5631d739af634cb33bea2f3fddd;hpb=549b5c478f0f455186945033559c4affe8f940ed diff --git a/src/position.cpp b/src/position.cpp index fade3cba..2f3c62f5 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "bitcount.h" @@ -34,8 +33,6 @@ #include "tt.h" using std::string; -using std::cout; -using std::endl; static const string PieceToChar(" PNBRQK pnbrqk"); @@ -98,7 +95,7 @@ CheckInfo::CheckInfo(const Position& pos) { Color them = ~pos.side_to_move(); ksq = pos.king_square(them); - pinned = pos.pinned_pieces(); + pinned = pos.pinned_pieces(pos.side_to_move()); dcCandidates = pos.discovered_check_candidates(); checkSq[PAWN] = pos.attacks_from(ksq, them); @@ -422,7 +419,7 @@ const string Position::pretty(Move move) const { /// pieces, according to the call parameters. Pinned pieces protect our king, /// discovery check pieces attack the enemy king. -Bitboard Position::hidden_checkers(Square ksq, Color c) const { +Bitboard Position::hidden_checkers(Square ksq, Color c, Color toMove) const { Bitboard b, pinners, result = 0; @@ -435,7 +432,7 @@ Bitboard Position::hidden_checkers(Square ksq, Color c) const { b = between_bb(ksq, pop_lsb(&pinners)) & pieces(); if (!more_than_one(b)) - result |= b & pieces(sideToMove); + result |= b & pieces(toMove); } return result; } @@ -455,29 +452,12 @@ Bitboard Position::attackers_to(Square s, Bitboard occ) const { } -/// Position::attacks_from() computes a bitboard of all attacks of a given piece -/// put in a given square. Slider attacks use occ bitboard as occupancy. - -Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) { - - assert(is_ok(s)); - - switch (type_of(p)) - { - case BISHOP: return attacks_bb(s, occ); - case ROOK : return attacks_bb(s, occ); - case QUEEN : return attacks_bb(s, occ) | attacks_bb(s, occ); - default : return StepAttacksBB[p][s]; - } -} - - /// Position::legal() tests whether a pseudo-legal move is legal bool Position::legal(Move m, Bitboard pinned) const { assert(is_ok(m)); - assert(pinned == pinned_pieces()); + assert(pinned == pinned_pieces(sideToMove)); Color us = sideToMove; Square from = from_sq(m); @@ -515,7 +495,7 @@ bool Position::legal(Move m, Bitboard pinned) const { // is moving along the ray towards or away from the king. return !pinned || !(pinned & from) - || squares_aligned(from, to_sq(m), king_square(us)); + || aligned(from, to_sq(m), king_square(us)); } @@ -653,14 +633,11 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const { if (ci.checkSq[pt] & to) return true; - // Discovery check ? - if (unlikely(ci.dcCandidates) && (ci.dcCandidates & from)) - { - // For pawn and king moves we need to verify also direction - if ( (pt != PAWN && pt != KING) - || !squares_aligned(from, to, king_square(~sideToMove))) - return true; - } + // Discovered check ? + if ( unlikely(ci.dcCandidates) + && (ci.dcCandidates & from) + && !aligned(from, to, king_square(~sideToMove))) + return true; // Can we skip the ugly special cases ? if (type_of(m) == NORMAL) @@ -672,7 +649,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const { switch (type_of(m)) { case PROMOTION: - return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq; + return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & ksq; // En passant capture with check ? We have already handled the case // of direct checks and ordinary discovered check, the only case we