@@ -67,7 +67,7 @@ Value value_from_tt(Value v, int ply, int r50c) {
6767 return v;
6868}
6969} // namespace
70- Value qsearch (Board &board, Value alpha, Value beta, search::Session &session, int ply) {
70+ Value qsearch (Position &board, Value alpha, Value beta, search::Session &session, int ply) {
7171 session.nodes ++;
7272 session.qnodes ++;
7373 session.seldepth = std::max (session.seldepth , ply);
@@ -179,7 +179,7 @@ Value qsearch(Board &board, Value alpha, Value beta, search::Session &session, i
179179 return best;
180180}
181181Value doSearch (
182- Board &board, int depth, Value alpha, Value beta, search::Session &session, int ply = 0 , Move prevMove = Move::none()) {
182+ Position &board, int depth, Value alpha, Value beta, search::Session &session, int ply = 0 , Move prevMove = Move::none()) {
183183 session.nodes ++;
184184 session.seldepth = std::max (session.seldepth , ply);
185185 if (ply >= MAX_PLY - 1 )
@@ -504,9 +504,9 @@ Value doSearch(
504504 }
505505 return maxScore;
506506}
507- std::string extract_pv (const chess::Board &root, int maxPly) {
507+ std::string extract_pv (const chess::Position &root, int maxPly) {
508508 std::string pv;
509- chess::Board pos = root;
509+ chess::Position pos = root;
510510 std::unordered_set<uint64_t > visited;
511511 visited.insert (pos.hash ());
512512 for (int ply = 0 ; ply < maxPly; ply++) {
@@ -538,7 +538,7 @@ std::string extract_pv(const chess::Board &root, int maxPly) {
538538 return pv;
539539}
540540
541- void search (const chess::Board &board, const timeman::LimitsType timecontrol) {
541+ void search (const chess::Position &board, const timeman::LimitsType timecontrol) {
542542 stopSearch = false ;
543543 tt.newSearch ();
544544 static double originalTimeAdjust = -1 ;
@@ -564,10 +564,27 @@ void search(const chess::Board &board, const timeman::LimitsType timecontrol) {
564564 }
565565
566566 {
567- Movelist legal;
568- board.legals (legal);
569- if (legal.size ())
570- lastPV[0 ] = legal[0 ];
567+ Movelist moves;
568+ board.legals (moves);
569+ Position board_ = board;
570+ Move best = Move::none ();
571+ Value bestScore = -VALUE_INFINITE ;
572+ Session tmpSession{};
573+ for (Move move : moves) {
574+ if (!session.tc .searchmoves .empty () &&
575+ std::find (session.tc .searchmoves .begin (),
576+ session.tc .searchmoves .end (),
577+ chess::uci::moveToUci (move, board.chess960 ())) == session.tc .searchmoves .end ())
578+ continue ;
579+ board_.doMove (move);
580+ Value score = -qsearch (board_, -VALUE_INFINITE , VALUE_INFINITE , tmpSession, 0 );
581+ if (score > bestScore) {
582+ bestScore = score;
583+ best = move;
584+ }
585+ board_.undoMove ();
586+ }
587+ lastPV[0 ]=best;
571588 }
572589
573590 for (int i = 1 ; i <= timecontrol.depth ; i++) {
@@ -649,7 +666,7 @@ void search(const chess::Board &board, const timeman::LimitsType timecontrol) {
649666 board.legals (moves);
650667
651668 if (moves.size ()) {
652- Board board_ = board;
669+ Position board_ = board;
653670 Move best = Move::none ();
654671 Value bestScore = -VALUE_INFINITE ;
655672 Session tmpSession{};
0 commit comments