1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Convert to sync_cout and sync_endl

Serialize access to std::cout all over the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-08-29 13:28:59 +02:00
parent 92e759a676
commit 0a003d3ba1
4 changed files with 28 additions and 25 deletions

View file

@ -23,6 +23,7 @@
#include "bitboard.h" #include "bitboard.h"
#include "bitcount.h" #include "bitcount.h"
#include "misc.h"
#include "rkiss.h" #include "rkiss.h"
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
@ -137,6 +138,8 @@ Square msb(Bitboard b) {
void Bitboards::print(Bitboard b) { void Bitboards::print(Bitboard b) {
sync_cout;
for (Rank rank = RANK_8; rank >= RANK_1; rank--) for (Rank rank = RANK_8; rank >= RANK_1; rank--)
{ {
std::cout << "+---+---+---+---+---+---+---+---+" << '\n'; std::cout << "+---+---+---+---+---+---+---+---+" << '\n';
@ -146,7 +149,7 @@ void Bitboards::print(Bitboard b) {
std::cout << "|\n"; std::cout << "|\n";
} }
std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; std::cout << "+---+---+---+---+---+---+---+---+" << sync_endl;
} }

View file

@ -363,6 +363,8 @@ void Position::print(Move move) const {
string brd = twoRows + twoRows + twoRows + twoRows + dottedLine; string brd = twoRows + twoRows + twoRows + twoRows + dottedLine;
sync_cout;
if (move) if (move)
{ {
Position p(*this); Position p(*this);
@ -373,7 +375,7 @@ void Position::print(Move move) const {
if (piece_on(sq) != NO_PIECE) if (piece_on(sq) != NO_PIECE)
brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)]; brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << endl; cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << sync_endl;
} }

View file

@ -47,8 +47,6 @@ namespace Search {
} }
using std::string; using std::string;
using std::cout;
using std::endl;
using Eval::evaluate; using Eval::evaluate;
using namespace Search; using namespace Search;
@ -237,8 +235,8 @@ void Search::think() {
if (RootMoves.empty()) if (RootMoves.empty())
{ {
cout << "info depth 0 score " sync_cout << "info depth 0 score "
<< score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << endl; << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << sync_endl;
RootMoves.push_back(MOVE_NONE); RootMoves.push_back(MOVE_NONE);
goto finalize; goto finalize;
@ -272,7 +270,7 @@ void Search::think() {
<< " time: " << Limits.time[pos.side_to_move()] << " time: " << Limits.time[pos.side_to_move()]
<< " increment: " << Limits.inc[pos.side_to_move()] << " increment: " << Limits.inc[pos.side_to_move()]
<< " moves to go: " << Limits.movestogo << " moves to go: " << Limits.movestogo
<< endl; << std::endl;
} }
Threads.wake_up(); Threads.wake_up();
@ -301,7 +299,7 @@ void Search::think() {
StateInfo st; StateInfo st;
pos.do_move(RootMoves[0].pv[0], st); pos.do_move(RootMoves[0].pv[0], st);
log << "\nPonder move: " << move_to_san(pos, RootMoves[0].pv[1]) << endl; log << "\nPonder move: " << move_to_san(pos, RootMoves[0].pv[1]) << std::endl;
pos.undo_move(RootMoves[0].pv[0]); pos.undo_move(RootMoves[0].pv[0]);
} }
@ -314,8 +312,8 @@ finalize:
pos.this_thread()->wait_for_stop_or_ponderhit(); pos.this_thread()->wait_for_stop_or_ponderhit();
// Best move could be MOVE_NONE when searching on a stalemate position // Best move could be MOVE_NONE when searching on a stalemate position
cout << "bestmove " << move_to_uci(RootMoves[0].pv[0], Chess960) sync_cout << "bestmove " << move_to_uci(RootMoves[0].pv[0], Chess960)
<< " ponder " << move_to_uci(RootMoves[0].pv[1], Chess960) << endl; << " ponder " << move_to_uci(RootMoves[0].pv[1], Chess960) << sync_endl;
} }
@ -401,7 +399,7 @@ namespace {
// Send full PV info to GUI if we are going to leave the loop or // Send full PV info to GUI if we are going to leave the loop or
// if we have a fail high/low and we are deep in the search. // if we have a fail high/low and we are deep in the search.
if ((bestValue > alpha && bestValue < beta) || SearchTime.elapsed() > 2000) if ((bestValue > alpha && bestValue < beta) || SearchTime.elapsed() > 2000)
cout << uci_pv(pos, depth, alpha, beta) << endl; sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
// In case of failing high/low increase aspiration window and // In case of failing high/low increase aspiration window and
// research, otherwise exit the fail high/low loop. // research, otherwise exit the fail high/low loop.
@ -434,7 +432,7 @@ namespace {
{ {
Log log(Options["Search Log Filename"]); Log log(Options["Search Log Filename"]);
log << pretty_pv(pos, depth, bestValue, SearchTime.elapsed(), &RootMoves[0].pv[0]) log << pretty_pv(pos, depth, bestValue, SearchTime.elapsed(), &RootMoves[0].pv[0])
<< endl; << std::endl;
} }
// Filter out startup noise when monitoring best move stability // Filter out startup noise when monitoring best move stability
@ -830,9 +828,9 @@ split_point_start: // At split points actual search starts from here
Signals.firstRootMove = (moveCount == 1); Signals.firstRootMove = (moveCount == 1);
if (thisThread == Threads.main_thread() && SearchTime.elapsed() > 2000) if (thisThread == Threads.main_thread() && SearchTime.elapsed() > 2000)
cout << "info depth " << depth / ONE_PLY sync_cout << "info depth " << depth / ONE_PLY
<< " currmove " << move_to_uci(move, Chess960) << " currmove " << move_to_uci(move, Chess960)
<< " currmovenumber " << moveCount + PVIdx << endl; << " currmovenumber " << moveCount + PVIdx << sync_endl;
} }
isPvMove = (PvNode && moveCount <= 1); isPvMove = (PvNode && moveCount <= 1);

View file

@ -97,7 +97,7 @@ void UCI::loop(const string& args) {
TT.clear(); TT.clear();
else if (token == "isready") else if (token == "isready")
cout << "readyok" << endl; sync_cout << "readyok" << sync_endl;
else if (token == "position") else if (token == "position")
set_position(pos, is); set_position(pos, is);
@ -112,20 +112,20 @@ void UCI::loop(const string& args) {
pos.flip(); pos.flip();
else if (token == "eval") else if (token == "eval")
cout << Eval::trace(pos) << endl; sync_cout << Eval::trace(pos) << sync_endl;
else if (token == "bench") else if (token == "bench")
benchmark(pos, is); benchmark(pos, is);
else if (token == "key") else if (token == "key")
cout << "key: " << hex << pos.key() sync_cout << "key: " << hex << pos.key()
<< "\nmaterial key: " << pos.material_key() << "\nmaterial key: " << pos.material_key()
<< "\npawn key: " << pos.pawn_key() << endl; << "\npawn key: " << pos.pawn_key() << sync_endl;
else if (token == "uci") else if (token == "uci")
cout << "id name " << engine_info(true) sync_cout << "id name " << engine_info(true)
<< "\n" << Options << "\n" << Options
<< "\nuciok" << endl; << "\nuciok" << sync_endl;
else if (token == "perft" && (is >> token)) // Read depth else if (token == "perft" && (is >> token)) // Read depth
{ {
@ -138,7 +138,7 @@ void UCI::loop(const string& args) {
} }
else else
cout << "Unknown command: " << cmd << endl; sync_cout << "Unknown command: " << cmd << sync_endl;
if (!args.empty()) // Command line arguments have one-shot behaviour if (!args.empty()) // Command line arguments have one-shot behaviour
{ {
@ -206,7 +206,7 @@ namespace {
if (Options.count(name)) if (Options.count(name))
Options[name] = value; Options[name] = value;
else else
cout << "No such option: " << name << endl; sync_cout << "No such option: " << name << sync_endl;
} }