along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <deque>
#include <iostream>
+#include <stack>
#include <thread>
#include "bitboard.h"
Status HashProbeImpl::Probe(ServerContext* context,
const HashProbeRequest* request,
HashProbeResponse *response) {
- Position pos(request->fen(), /*isChess960=*/false, Threads.main());
+ Position pos;
+ StateInfo st;
+ pos.set(request->fen(), /*isChess960=*/false, &st, Threads.main());
if (!pos.pos_is_ok()) {
return Status(StatusCode::INVALID_ARGUMENT, "Invalid FEN");
}
bool invert = (pos.side_to_move() == BLACK);
- Search::StateStackPtr setup_states = Search::StateStackPtr(new std::stack<StateInfo>);
+ StateListPtr setup_states = StateListPtr(new std::deque<StateInfo>(1));
ProbeMove(&pos, setup_states.get(), invert, response->mutable_root());
for (const ExtMove* em = moves.begin(); em != moves.end(); ++em) {
HashProbeLine *line = response->add_line();
FillMove(em->move, line->mutable_move());
- setup_states->push(StateInfo());
- pos.do_move(em->move, setup_states->top(), pos.gives_check(em->move, CheckInfo(pos)));
+ setup_states->push_back(StateInfo());
+ pos.do_move(em->move, setup_states->back(), pos.gives_check(em->move));
ProbeMove(&pos, setup_states.get(), !invert, line);
pos.undo_move(em->move);
}
}
}
-void HashProbeImpl::ProbeMove(Position* pos, std::stack<StateInfo>* setup_states, bool invert, HashProbeLine* response) {
+void HashProbeImpl::ProbeMove(Position* pos, std::deque<StateInfo>* setup_states, bool invert, HashProbeLine* response) {
bool found;
TTEntry *entry = TT.probe(pos->key(), found);
response->set_found(found);
// 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());
seen.insert(pos->key());
- setup_states->push(StateInfo());
- pos->do_move(entry->move(), setup_states->top(), pos->gives_check(entry->move(), CheckInfo(*pos)));
+ setup_states->push_back(StateInfo());
+ pos->do_move(entry->move(), setup_states->back(), pos->gives_check(entry->move()));
entry = TT.probe(pos->key(), found);
}