bool Position::is_pseudo_legal(const Move m) const {
Color us = sideToMove;
- Color them = ~sideToMove;
Square from = from_sq(m);
Square to = to_sq(m);
Piece pc = piece_moved(m);
return false;
// The destination square cannot be occupied by a friendly piece
- if (color_of(piece_on(to)) == us)
+ if (piece_on(to) != NO_PIECE && color_of(piece_on(to)) == us)
return false;
// Handle the special case of a pawn move
case DELTA_SE:
// Capture. The destination square must be occupied by an enemy
// piece (en passant captures was handled earlier).
- if (color_of(piece_on(to)) != them)
+ if (piece_on(to) == NO_PIECE || color_of(piece_on(to)) != ~us)
return false;
// From and to files must be one file apart, avoids a7h5
{
if (type_of(pc) != KING)
{
- Bitboard b = checkers();
- Square checksq = pop_lsb(&b);
-
- if (b) // double check ? In this case a king move is required
+ // Double check? In this case a king move is required
+ if (more_than_one(checkers()))
return false;
// Our move must be a blocking evasion or a capture of the checking piece
- if (!((between_bb(checksq, king_square(us)) | checkers()) & to))
+ if (!((between_bb(lsb(checkers()), king_square(us)) | checkers()) & to))
return false;
}
// In case of king moves under check we have to remove king so to catch
Color us = sideToMove;
Square ksq = king_square(~us);
- // Promotion with check ?
- if (type_of(m) == PROMOTION)
+ switch (type_of(m))
+ {
+ case PROMOTION:
return attacks_from(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
// need to handle is the unusual case of a discovered check through
// the captured pawn.
- if (type_of(m) == ENPASSANT)
+ case ENPASSANT:
{
Square capsq = file_of(to) | rank_of(from);
Bitboard b = (pieces() ^ from ^ capsq) | to;
return (attacks_bb< ROOK>(ksq, b) & pieces(us, QUEEN, ROOK))
| (attacks_bb<BISHOP>(ksq, b) & pieces(us, QUEEN, BISHOP));
}
-
- // Castling with check ?
- if (type_of(m) == CASTLE)
+ case CASTLE:
{
Square kfrom = from;
Square rfrom = to; // 'King captures the rook' notation
return attacks_bb<ROOK>(rto, b) & ksq;
}
-
- return false;
+ default:
+ assert(false);
+ return false;
+ }
}
PieceType capture = type_of(m) == ENPASSANT ? PAWN : type_of(piece_on(to));
assert(color_of(piece) == us);
- assert(color_of(piece_on(to)) != us);
+ assert(piece_on(to) == NO_PIECE || color_of(piece_on(to)) == them);
assert(capture != KING);
if (capture)
}
// Prefetch pawn and material hash tables
- prefetch((char*)thisThread->pawnTable.entries[st->pawnKey]);
- prefetch((char*)thisThread->materialTable.entries[st->materialKey]);
+ prefetch((char*)thisThread->pawnsTable[st->pawnKey]);
+ prefetch((char*)thisThread->materialTable[st->materialKey]);
// Update incremental scores
st->psqScore += psq_delta(piece, from, to);