Square sq = make_square(file, rank);
Piece piece = piece_on(sq);
Square sq = make_square(file, rank);
Piece piece = piece_on(sq);
// En passant captures are a tricky special case. Because they are rather
// uncommon, we do it simply by testing whether the king is attacked after
// the move is made.
// En passant captures are a tricky special case. Because they are rather
// uncommon, we do it simply by testing whether the king is attacked after
// the move is made.
// square is attacked by the opponent. Castling moves are checked
// for legality during move generation.
if (type_of(piece_on(from)) == KING)
// square is attacked by the opponent. Castling moves are checked
// for legality during move generation.
if (type_of(piece_on(from)) == KING)
// 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.
// 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.
-/// Fast version of Position::move_is_pl() that takes a move and a bitboard
-/// of pinned pieces as input, and tests whether the move is pseudo legal.
+/// Position::is_pseudo_legal() takes a random move and tests whether the move
+/// is pseudo legal. It is used to validate moves from TT that can be corrupted
+/// due to SMP concurrent access or hash position key aliasing.
assert(ci.dcCandidates == discovered_check_candidates());
assert(color_of(piece_on(move_from(m))) == side_to_move());
assert(ci.dcCandidates == discovered_check_candidates());
assert(color_of(piece_on(move_from(m))) == side_to_move());
// 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.
// 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.
{
Square kfrom, kto, rfrom, rto;
kfrom = from;
{
Square kfrom, kto, rfrom, rto;
kfrom = from;
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
// When we have arrived here, some work has already been done by
// Position::undo_move. In particular, the side to move has been switched,
// When we have arrived here, some work has already been done by
// Position::undo_move. In particular, the side to move has been switched,
// As castle moves are implemented as capturing the rook, they have
// SEE == RookValueMidgame most of the times (unless the rook is under
// attack).
// As castle moves are implemented as capturing the rook, they have
// SEE == RookValueMidgame most of the times (unless the rook is under
// attack).