bool useNNUE;
string eval_file_loaded = "None";
- /// init_NNUE() tries to load a nnue network at startup time, or when the engine
+ /// NNUE::init() tries to load a nnue network at startup time, or when the engine
/// receives a UCI command "setoption name EvalFile value nn-[a-z0-9]{12}.nnue"
/// The name of the nnue network is always retrieved from the EvalFile option.
/// We search the given network in three locations: internally (the default
/// in the engine directory. Distro packagers may define the DEFAULT_NNUE_DIRECTORY
/// variable to have the engine search in a special directory in their distro.
- void init_NNUE() {
+ void NNUE::init() {
useNNUE = Options["Use NNUE"];
if (!useNNUE)
}
}
- /// verify_NNUE() verifies that the last net used was loaded successfully
- void verify_NNUE() {
+ /// NNUE::verify() verifies that the last net used was loaded successfully
+ void NNUE::verify() {
string eval_file = string(Options["EvalFile"]);
extern bool useNNUE;
extern std::string eval_file_loaded;
- void init_NNUE();
- void verify_NNUE();
// The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue
// for the build process (profile-build and fishtest) to work. Do not change the
namespace NNUE {
Value evaluate(const Position& pos);
- Value compute_eval(const Position& pos);
- void update_eval(const Position& pos);
- bool load_eval(std::string streamName, std::istream& stream);
+ bool load_eval(std::string name, std::istream& stream);
+ void init();
+ void verify();
} // namespace NNUE
Endgames::init();
Threads.set(size_t(Options["Threads"]));
Search::clear(); // After threads are up
- Eval::init_NNUE();
+ Eval::NNUE::init();
UCI::loop(argc, argv);
namespace Eval::NNUE {
- uint32_t kpp_board_index[PIECE_NB][COLOR_NB] = {
+ const uint32_t kpp_board_index[PIECE_NB][COLOR_NB] = {
// convention: W - us, B - them
// viewed from other side, W and B are reversed
{ PS_NONE, PS_NONE },
}
// Load eval, from a file stream or a memory stream
- bool load_eval(std::string streamName, std::istream& stream) {
+ bool load_eval(std::string name, std::istream& stream) {
Initialize();
- fileName = streamName;
+ fileName = name;
return ReadParameters(stream);
}
};
template <typename T>
- struct TtmemDeleter {
+ struct LargePageDeleter {
void operator()(T* ptr) const {
ptr->~T();
aligned_large_pages_free(ptr);
using AlignedPtr = std::unique_ptr<T, AlignedDeleter<T>>;
template <typename T>
- using LargePagePtr = std::unique_ptr<T, TtmemDeleter<T>>;
+ using LargePagePtr = std::unique_ptr<T, LargePageDeleter<T>>;
} // namespace Eval::NNUE
PS_END2 = 12 * SQUARE_NB + 1
};
- extern uint32_t kpp_board_index[PIECE_NB][COLOR_NB];
+ extern const uint32_t kpp_board_index[PIECE_NB][COLOR_NB];
// Type of input feature after conversion
using TransformedFeatureType = std::uint8_t;
Time.init(Limits, us, rootPos.game_ply());
TT.new_search();
- Eval::verify_NNUE();
+ Eval::NNUE::verify();
if (rootMoves.empty())
{
++failedHighCnt;
}
else
- {
- ++rootMoves[pvIdx].bestMoveCount;
break;
- }
delta += delta / 4 + 5;
}
else
{
- // Increase reduction for captures/promotions if late move and at low depth
- if (depth < 8 && moveCount > 2)
- r++;
-
- // Unless giving check, this capture is likely bad
- if ( !givesCheck
- && ss->staticEval + PieceValue[EG][pos.captured_piece()] + 213 * depth <= alpha)
- r++;
+ // Increase reduction for captures/promotions if late move and at low depth
+ if (depth < 8 && moveCount > 2)
+ r++;
+
+ // Unless giving check, this capture is likely bad
+ if ( !givesCheck
+ && ss->staticEval + PieceValue[EG][pos.captured_piece()] + 213 * depth <= alpha)
+ r++;
}
Depth d = std::clamp(newDepth - r, 1, newDepth);
[pos.moved_piece(move)]
[to_sq(move)];
+ // CounterMove based pruning
if ( !captureOrPromotion
&& moveCount
&& (*contHist[0])[pos.moved_piece(move)][to_sq(move)] < CounterMovePruneThreshold
Value previousScore = -VALUE_INFINITE;
int selDepth = 0;
int tbRank = 0;
- int bestMoveCount = 0;
Value tbScore;
std::vector<Move> pv;
};
votes[th->rootMoves[0].pv[0]] +=
(th->rootMoves[0].score - minScore + 14) * int(th->completedDepth);
- if (abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
- {
- // Make sure we pick the shortest mate / TB conversion or stave off mate the longest
- if (th->rootMoves[0].score > bestThread->rootMoves[0].score)
- bestThread = th;
- }
- else if ( th->rootMoves[0].score >= VALUE_TB_WIN_IN_MAX_PLY
- || ( th->rootMoves[0].score > VALUE_TB_LOSS_IN_MAX_PLY
- && votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]))
- bestThread = th;
+ if (abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
+ {
+ // Make sure we pick the shortest mate / TB conversion or stave off mate the longest
+ if (th->rootMoves[0].score > bestThread->rootMoves[0].score)
+ bestThread = th;
+ }
+ else if ( th->rootMoves[0].score >= VALUE_TB_WIN_IN_MAX_PLY
+ || ( th->rootMoves[0].score > VALUE_TB_LOSS_IN_MAX_PLY
+ && votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]))
+ bestThread = th;
}
return bestThread;
Position p;
p.set(pos.fen(), Options["UCI_Chess960"], &states->back(), Threads.main());
- Eval::verify_NNUE();
+ Eval::NNUE::verify();
sync_cout << "\n" << Eval::trace(p) << sync_endl;
}
void on_logger(const Option& o) { start_logger(o); }
void on_threads(const Option& o) { Threads.set(size_t(o)); }
void on_tb_path(const Option& o) { Tablebases::init(o); }
-void on_use_NNUE(const Option& ) { Eval::init_NNUE(); }
-void on_eval_file(const Option& ) { Eval::init_NNUE(); }
+void on_use_NNUE(const Option& ) { Eval::NNUE::init(); }
+void on_eval_file(const Option& ) { Eval::NNUE::init(); }
/// Our case insensitive less() function as required by UCI protocol
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {