From: Marco Costalba Date: Mon, 17 Oct 2011 19:41:27 +0000 (+0100) Subject: Use newly added log facility instead of LogFile X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=e7cfe42d3f5bf385bcfafebeabd9eb887f0f21ce Use newly added log facility instead of LogFile As a side effect now log file is open and closed every time it is used instead of remaining open for the whole thinking time. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/search.cpp b/src/search.cpp index b893fdce..c163e8ea 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -166,9 +165,6 @@ namespace { TimeManager TimeMgr; SearchLimits Limits; - // Log file - std::ofstream LogFile; - // Skill level adjustment int SkillLevel; bool SkillLevelEnabled; @@ -433,17 +429,14 @@ bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]) { // Write to log file and keep it open to be accessed during the search if (Options["Use Search Log"].value()) { - string name = Options["Search Log Filename"].value(); - LogFile.open(name.c_str(), std::ios::out | std::ios::app); - - if (LogFile.is_open()) - LogFile << "\nSearching: " << pos.to_fen() - << "\ninfinite: " << Limits.infinite - << " ponder: " << Limits.ponder - << " time: " << Limits.time - << " increment: " << Limits.increment - << " moves to go: " << Limits.movesToGo - << endl; + Log log(Options["Search Log Filename"].value()); + log << "\nSearching: " << pos.to_fen() + << "\ninfinite: " << Limits.infinite + << " ponder: " << Limits.ponder + << " time: " << Limits.time + << " increment: " << Limits.increment + << " moves to go: " << Limits.movesToGo + << endl; } // We're ready to start thinking. Call the iterative deepening loop function @@ -451,19 +444,19 @@ bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]) { Move bestMove = id_loop(pos, searchMoves, &ponderMove); // Write final search statistics and close log file - if (LogFile.is_open()) + if (Options["Use Search Log"].value()) { int t = current_search_time(); - LogFile << "Nodes: " << pos.nodes_searched() - << "\nNodes/second: " << (t > 0 ? pos.nodes_searched() * 1000 / t : 0) - << "\nBest move: " << move_to_san(pos, bestMove); + Log log(Options["Search Log Filename"].value()); + log << "Nodes: " << pos.nodes_searched() + << "\nNodes/second: " << (t > 0 ? pos.nodes_searched() * 1000 / t : 0) + << "\nBest move: " << move_to_san(pos, bestMove); StateInfo st; pos.do_move(bestMove, st); - LogFile << "\nPonder move: " << move_to_san(pos, ponderMove) << endl; + log << "\nPonder move: " << move_to_san(pos, ponderMove) << endl; pos.undo_move(bestMove); // Return from think() with unchanged position - LogFile.close(); } // This makes all the threads to go to sleep @@ -641,8 +634,11 @@ namespace { if (SkillLevelEnabled && depth == 1 + SkillLevel) do_skill_level(&skillBest, &skillPonder); - if (LogFile.is_open()) - LogFile << pretty_pv(pos, depth, value, current_search_time(), &Rml[0].pv[0]) << endl; + if (Options["Use Search Log"].value()) + { + Log log(Options["Search Log Filename"].value()); + log << pretty_pv(pos, depth, value, current_search_time(), &Rml[0].pv[0]) << endl; + } // Init easyMove at first iteration or drop it if differs from the best move if (depth == 1 && (Rml.size() == 1 || Rml[0].score > Rml[1].score + EasyMoveMargin))