Skip to content

MoveGivesCheck() #6

Description

@nescitus

ICE has:

template ECheck TBoard::moveChecksSidesKing(TMove move)
{
TBitBoard abb = 0;
ESquare kSq = bb.sqOfKing[side], toSq = TMove_TO_SQUARE(move);
const EColor attacker = (side == WHITE ? BLACK : WHITE);

// start with an active check test
// does the moved piece check the king directly in its new position
switch (TMove_MOVED_PIECE(move))
{
case PIECE::PAWN : abb = bbPattern.PAWNS[attacker][toSq]; break;
case PIECE::KNIGHT : abb = bbPattern.KNIGHTS[toSq]; break;
case PIECE::BISHOP : abb = getBishopAttacks(toSq); break;
case PIECE::ROOK : abb = getRookAttacks(toSq); break;
case PIECE::QUEEN : abb = getBishopAttacks(toSq) | getRookAttacks(toSq); break;
case PIECE::KING : if (TMove_IS_CASTELING(move)) abb = FILE_NO[toSq] == C ? abb = getRookAttacks(ESquare(toSq+1)) : abb = getRookAttacks(ESquare(toSq-1));
}

if ((abb & BB_SQUARES[kSq]) != 0) return CHECK; // king is in the attack pattern of the moved piece on its target square, so this is a checking move

// look for a passive check when the moved piece opens a file or rank to the king
// test whether a discovered check is possible, otherwise early exit
if (!TMove_IS_ENPASSENT(move) && ((bbPattern.QUEENS[kSq] & BB_SQUARES[TMove_FROM_SQUARE(move)]) == 0)) return NO_CHECK;

// create a new occupied board pattern that simulates the move
abb = TMove_IS_CAPTURE(move) ? (bb.occupiedSquares & ~BB_SQUARES[TMove_FROM_SQUARE(move)] & ~BB_SQUARES[TMove_CAPTURED_SQUARE(move)]) | BB_SQUARES[toSq] :
(bb.occupiedSquares & ~BB_SQUARES[TMove_FROM_SQUARE(move)]) | BB_SQUARES[toSq];

if ((getBishopAttacks(kSq, abb) & (bb.pcs[PIECE::BISHOP] | bb.pcs[PIECE::QUEEN])) ||
(getRookAttacks(kSq, abb) & (bb.pcs[PIECE::ROOK] | bb.pcs[PIECE::QUEEN]))) return DISCOVERED_CHECK;

return NO_CHECK;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions