diff --git a/src/evaluate.cpp b/src/evaluate.cpp index f38acc29..58319cb5 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -30,6 +30,10 @@ #include "pawns.h" #include "thread.h" +namespace Eval { + bool useNNUE; +} + namespace Trace { enum Tracing { NO_TRACE, TRACE }; @@ -900,7 +904,7 @@ make_v: /// evaluation of the position from the point of view of the side to move. Value Eval::evaluate(const Position& pos) { - if (pos.use_nnue()) + if (Eval::useNNUE) return NNUE::evaluate(pos); else return Evaluation(pos).value(); @@ -921,7 +925,7 @@ std::string Eval::trace(const Position& pos) { Value v; - if (pos.use_nnue()) + if (Eval::useNNUE) { v = NNUE::evaluate(pos); } diff --git a/src/evaluate.h b/src/evaluate.h index 942cccbd..293b4ce4 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -31,6 +31,7 @@ namespace Eval { std::string trace(const Position& pos); Value evaluate(const Position& pos); +extern bool useNNUE; namespace NNUE { diff --git a/src/position.cpp b/src/position.cpp index 2705e812..16ca225f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -80,7 +80,7 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) { { StateInfo st; Position p; - p.set(pos.fen(), pos.is_chess960(), pos.use_nnue(), &st, pos.this_thread()); + p.set(pos.fen(), pos.is_chess960(), &st, pos.this_thread()); Tablebases::ProbeState s1, s2; Tablebases::WDLScore wdl = Tablebases::probe_wdl(p, &s1); int dtz = Tablebases::probe_dtz(p, &s2); @@ -154,7 +154,7 @@ void Position::init() { /// This function is not very robust - make sure that input FENs are correct, /// this is assumed to be the responsibility of the GUI. -Position& Position::set(const string& fenStr, bool isChess960, bool useNnue, StateInfo* si, Thread* th) { +Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Thread* th) { /* A FEN string defines a particular position using only the ASCII character set. @@ -219,7 +219,7 @@ Position& Position::set(const string& fenStr, bool isChess960, bool useNnue, Sta auto pc = Piece(idx); put_piece(pc, sq); - if (useNnue) + if (Eval::useNNUE) { // Kings get a fixed ID, other pieces get ID in order of placement piece_id = @@ -295,7 +295,6 @@ Position& Position::set(const string& fenStr, bool isChess960, bool useNnue, Sta gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == BLACK); chess960 = isChess960; - nnue = useNnue; thisThread = th; set_state(st); @@ -404,7 +403,7 @@ Position& Position::set(const string& code, Color c, StateInfo* si) { string fenStr = "8/" + sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/" + sides[1] + char(8 - sides[1].length() + '0') + "/8 w - - 0 10"; - return set(fenStr, false, false, si, nullptr); + return set(fenStr, false, si, nullptr); } @@ -776,7 +775,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) { else st->nonPawnMaterial[them] -= PieceValue[MG][captured]; - if (use_nnue()) + if (Eval::useNNUE) { dp.dirty_num = 2; // 2 pieces moved dp1 = piece_id_on(capsq); @@ -823,7 +822,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) { // Move the piece. The tricky Chess960 castling is handled earlier if (type_of(m) != CASTLING) { - if (use_nnue()) + if (Eval::useNNUE) { dp0 = piece_id_on(from); dp.pieceId[0] = dp0; @@ -855,7 +854,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) { remove_piece(to); put_piece(promotion, to); - if (use_nnue()) + if (Eval::useNNUE) { dp0 = piece_id_on(to); evalList.put_piece(dp0, to, promotion); @@ -951,10 +950,9 @@ void Position::undo_move(Move m) { } else { - move_piece(to, from); // Put the piece back at the source square - if (use_nnue()) + if (Eval::useNNUE) { PieceId dp0 = st->dirtyPiece.pieceId[0]; evalList.put_piece(dp0, from, pc); @@ -977,7 +975,7 @@ void Position::undo_move(Move m) { put_piece(st->capturedPiece, capsq); // Restore the captured piece - if (use_nnue()) + if (Eval::useNNUE) { PieceId dp1 = st->dirtyPiece.pieceId[1]; assert(evalList.piece_with_id(dp1).from[WHITE] == PS_NONE); @@ -1005,7 +1003,7 @@ void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Squ rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1); to = relative_square(us, kingSide ? SQ_G1 : SQ_C1); - if (use_nnue()) + if (Eval::useNNUE) { PieceId dp0, dp1; auto& dp = st->dirtyPiece; @@ -1048,7 +1046,8 @@ void Position::do_null_move(StateInfo& newSt) { assert(!checkers()); assert(&newSt != st); - if (use_nnue()) { + if (Eval::useNNUE) + { std::memcpy(&newSt, st, sizeof(StateInfo)); st->accumulator.computed_score = false; } @@ -1321,7 +1320,7 @@ void Position::flip() { std::getline(ss, token); // Half and full moves f += token; - set(f, is_chess960(), use_nnue(), st, this_thread()); + set(f, is_chess960(), st, this_thread()); assert(pos_is_ok()); } diff --git a/src/position.h b/src/position.h index 19642f6d..13af2bfd 100644 --- a/src/position.h +++ b/src/position.h @@ -86,7 +86,7 @@ public: Position& operator=(const Position&) = delete; // FEN string input/output - Position& set(const std::string& fenStr, bool isChess960, bool useNnue, StateInfo* si, Thread* th); + Position& set(const std::string& fenStr, bool isChess960, StateInfo* si, Thread* th); Position& set(const std::string& code, Color c, StateInfo* si); const std::string fen() const; @@ -157,7 +157,6 @@ public: Color side_to_move() const; int game_ply() const; bool is_chess960() const; - bool use_nnue() const; Thread* this_thread() const; bool is_draw(int ply) const; bool has_game_cycle(int ply) const; @@ -376,10 +375,6 @@ inline bool Position::is_chess960() const { return chess960; } -inline bool Position::use_nnue() const { - return nnue; -} - inline bool Position::capture_or_promotion(Move m) const { assert(is_ok(m)); return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m)); diff --git a/src/thread.cpp b/src/thread.cpp index d72bef81..a0ee2b25 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -216,7 +216,7 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states, th->nodes = th->tbHits = th->nmpMinPly = th->bestMoveChanges = 0; th->rootDepth = th->completedDepth = 0; th->rootMoves = rootMoves; - th->rootPos.set(pos.fen(), pos.is_chess960(), pos.use_nnue(), &setupStates->back(), th); + th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th); } setupStates->back() = tmp; diff --git a/src/uci.cpp b/src/uci.cpp index eaf020fa..552beecb 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -68,7 +68,7 @@ namespace { return; states = StateListPtr(new std::deque(1)); // Drop old and create a new one - pos.set(fen, Options["UCI_Chess960"], Options["Use NNUE"], &states->back(), Threads.main()); + pos.set(fen, Options["UCI_Chess960"], &states->back(), Threads.main()); // Parse move list (if any) while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE) @@ -236,7 +236,7 @@ void UCI::loop(int argc, char* argv[]) { string token, cmd; StateListPtr states(new std::deque(1)); - pos.set(StartFEN, false, Options["Use NNUE"], &states->back(), Threads.main()); + pos.set(StartFEN, false, &states->back(), Threads.main()); if (argc > 1) init_nnue(Options["EvalFile"]); diff --git a/src/ucioption.cpp b/src/ucioption.cpp index aa07dc73..a163c49d 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -48,8 +48,9 @@ void on_use_nnue(const Option& o) { if (o) std::cout << "info string NNUE eval used" << std::endl; else - std::cout << "info string Standard eval used" << std::endl; + std::cout << "info string classic eval used" << std::endl; + Eval::useNNUE = o; init_nnue(Options["EvalFile"]); }