// Follow the PV until we hit an illegal move.
std::stack<Move> pv;
std::set<Key> seen;
- while (found && is_ok(entry->move())) {
+ while (found && is_ok(entry->move()) &&
+ pos->pseudo_legal(entry->move()) &&
+ pos->legal(entry->move())) {
FillMove(entry->move(), response->add_pv());
if (seen.count(pos->key())) break;
pv.push(entry->move());