@@ -197,7 +197,6 @@ Value doSearch(
197197 if (alpha >= beta)
198198 return alpha;
199199
200- session.pv [ply][0 ] = Move::none ();
201200 if (board.is_draw (3 ) || board.is_insufficient_material ())
202201 return VALUE_DRAW ;
203202
@@ -215,20 +214,14 @@ Value doSearch(
215214
216215 if (flag == EXACT && ply > 0 ) {
217216 session.ttCutoffs ++;
218- session.pv [ply][0 ] = Move (entry->getMove ());
219- session.pv [ply][1 ] = Move::none ();
220217 return ttScore;
221218 }
222219 if (flag == LOWERBOUND && ttScore >= beta && ply > 0 ) {
223220 session.ttCutoffs ++;
224- session.pv [ply][0 ] = Move (entry->getMove ());
225- session.pv [ply][1 ] = Move::none ();
226221 return ttScore;
227222 }
228223 if (flag == UPPERBOUND && ttScore <= alpha && ply > 0 ) {
229224 session.ttCutoffs ++;
230- session.pv [ply][0 ] = Move (entry->getMove ());
231- session.pv [ply][1 ] = Move::none ();
232225 return ttScore;
233226 }
234227 }
@@ -326,7 +319,6 @@ Value doSearch(
326319 Movelist moves;
327320 board.legals (moves);
328321 if (!moves.size ()) {
329- session.pv [ply][0 ] = Move::none ();
330322 return board.checkers () ? mated_in (ply) : 0 ;
331323 }
332324 movepick::orderMoves (board, moves, ttMove, ply, session, prevMove);
@@ -364,6 +356,7 @@ Value doSearch(
364356 }
365357
366358 Value maxScore = -VALUE_INFINITE ;
359+ Move bestMove = Move::none ();
367360 int movesSearched = 0 ;
368361
369362 for (size_t i = 0 ; i < moves.size (); ++i) {
@@ -463,7 +456,7 @@ Value doSearch(
463456
464457 if (score > maxScore) {
465458 maxScore = score;
466- update_pv (session. pv [ply], move, session. pv [ply + 1 ]) ;
459+ bestMove = move ;
467460 }
468461
469462 if (score > alpha) {
@@ -501,7 +494,7 @@ Value doSearch(
501494 if (maxScore != -VALUE_INFINITE ) {
502495 TTFlag flag = maxScore >= beta ? LOWERBOUND : maxScore <= alphaOrig ? UPPERBOUND : EXACT ;
503496
504- tt.store (hash, session. pv [ply][ 0 ] , value_to_tt (maxScore, ply), depth, flag);
497+ tt.store (hash, bestMove , value_to_tt (maxScore, ply), depth, flag);
505498 }
506499 return maxScore;
507500}
@@ -544,7 +537,7 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
544537 session.tm .init (session.tc , board.side_to_move (), board.ply (), originalTimeAdjust);
545538 session.lastLogTime = session.tm .elapsed ();
546539 session.ogcolor = board.side_to_move ();
547- chess::Move lastPV[ MAX_PLY ] {};
540+ chess::Move lastBestMove {};
548541 Value prevScore = VALUE_NONE ;
549542
550543 if (!session.tc .searchmoves .empty ()) {
@@ -584,7 +577,7 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
584577 }
585578 board_.undoMove ();
586579 }
587- lastPV[ 0 ] = best;
580+ lastBestMove = best;
588581 }
589582
590583 for (int i = 1 ; i <= timecontrol.depth ; i++) {
@@ -647,64 +640,20 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
647640 size_t sp = pvStr.find (' ' );
648641 std::string firstMove = (sp == std::string::npos) ? pvStr : pvStr.substr (0 , sp);
649642 if (!firstMove.empty ())
650- lastPV[ 0 ] = chess::Move (chess::uci::uciToMove (board, firstMove).raw ());
643+ lastBestMove = chess::Move (chess::uci::uciToMove (board, firstMove).raw ());
651644 std::stringstream ss;
652645 ss << " qnodes " << session.qnodes << " lmrResearches " << session.lmrResearches << " ttHits " << session.ttHits
653646 << " ttCutoffs " << session.ttCutoffs << " nullCutoffs " << session.nullCutoffs ;
654647 info.extrainfo = ss.str ();
655648 report (info);
656649 }
657- if (lastPV[ 0 ] .is_ok ())
658- report (chess::uci::moveToUci (lastPV[ 0 ] , board.chess960 ()));
650+ if (lastBestMove .is_ok ())
651+ report (chess::uci::moveToUci (lastBestMove , board.chess960 ()));
659652 else {
660653 std::cerr << " info string Warning: Did not search\n " ;
661654 TTEntry *entry = tt.lookup (board.hash ());
662655 if (entry && entry->getMove () != Move::none ().raw ())
663656 report (chess::uci::moveToUci (Move (entry->getMove ()), board.chess960 ()));
664- else {
665- Movelist moves;
666- board.legals (moves);
667-
668- if (moves.size ()) {
669- Position board_ = board;
670- Move best = Move::none ();
671- Value bestScore = -VALUE_INFINITE ;
672- double unusedTimeAdjust = -1 ;
673- Session tmpSession;
674- tmpSession.tc = session.tc ;
675- tmpSession.tm .init (session.tc , board.side_to_move (), board.ply (), unusedTimeAdjust);
676- for (Move move : moves) {
677- if (!session.tc .searchmoves .empty () &&
678- std::find (session.tc .searchmoves .begin (),
679- session.tc .searchmoves .end (),
680- chess::uci::moveToUci (move, board.chess960 ())) == session.tc .searchmoves .end ())
681- continue ;
682- board_.doMove (move);
683- Value score = -qsearch (board_, -VALUE_INFINITE , VALUE_INFINITE , tmpSession, 0 );
684- if (score > bestScore) {
685- bestScore = score;
686- best = move;
687- }
688- board_.undoMove ();
689- }
690-
691- if (best.is_ok ()) {
692- InfoFull info{};
693- info.depth = 1 ;
694- info.nodes = 1 ;
695- info.score = 0 ;
696- info.multiPV = 1 ;
697- info.pv = std::string (chess::uci::moveToUci (best, board.chess960 ()));
698- report (info);
699-
700- report (chess::uci::moveToUci (best, board.chess960 ()));
701- } else {
702- report (" 0000" );
703- }
704- } else {
705- report (" 0000" );
706- }
707- }
708657 }
709658}
710659} // namespace engine::search
0 commit comments