Skip to content

Commit

Permalink
use a single info struct
Browse files Browse the repository at this point in the history
  • Loading branch information
bftjoe committed Jan 26, 2025
1 parent 86ceb98 commit ebbd38c
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 161 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# net file
nn.net

# Prerequisites
*.d

Expand Down
5 changes: 2 additions & 3 deletions src/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const char* benchmarkfens[52] = {
void StartBench(int depth) {
// init all
UciOptions uciOptions;
ThreadData* td(new ThreadData());
ThreadData* td = &mainTD;
uint64_t totalNodes = 0;
InitTT(64);
InitNewGame(td);
Expand All @@ -75,13 +75,12 @@ void StartBench(int depth) {
ParseFen(benchmarkfens[positions], &td->pos);
std::cout << "\nPosition: " << positions + 1 << " fen: " << benchmarkfens[positions] << std::endl;
RootSearch(depth, td, &uciOptions);
totalNodes += td->info.nodes;
totalNodes += td->nodes;
}
auto end = std::chrono::steady_clock::now();
auto totalTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cout << "\n";
std::cout << totalNodes << " nodes " << signed(totalNodes / (totalTime + 1) * 1000) << " nps" << std::endl;
delete td;
}

void BenchInference() {
Expand Down
10 changes: 4 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ void InitNewGame(ThreadData* td) {
// Extract data structures from ThreadData
Position* pos = &td->pos;
SearchData* sd = &td->sd;
SearchInfo* info = &td->info;

CleanHistories(sd);

Expand All @@ -232,11 +231,10 @@ void InitNewGame(ThreadData* td) {

std::memset(sd->counterMoves, NOMOVE, sizeof(sd->counterMoves));

// Reset plies and search info
info->starttime = GetTimeMs();
info->stopped = 0;
info->nodes = 0;
info->seldepth = 0;
// Reset plies and search info
info.starttime = GetTimeMs();
setStop(false);
info.seldepth = 0;
// Clear TT
ClearTT();

Expand Down
22 changes: 11 additions & 11 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,27 @@ std::string Pick_color(int score) {
}

// Prints the uci output
void PrintUciOutput(const int score, const int depth, const ThreadData* td, const UciOptions* options) {
void PrintUciOutput(const int score, const int depth, const UciOptions* options) {
// We are benching the engine and we don't care about the output
if (tryhardmode)
return;
// This handles the basic console output
long time = GetTimeMs() - td->info.starttime;
uint64_t nodes = td->info.nodes + GetTotalNodes();
long time = GetTimeMs() - info.starttime;
uint64_t nodes = mainTD.nodes + GetTotalNodes();

uint64_t nps = nodes / (time + !time) * 1000;
if (print_uci) {
if (score > -MATE_SCORE && score < -MATE_FOUND)
std::cout << "info score mate " << -(score + MATE_SCORE) / 2 << " depth " << depth << " seldepth " << td->info.seldepth << " multipv " << options->MultiPV << " nodes " << nodes <<
" nps " << nps << " time " << GetTimeMs() - td->info.starttime << " pv ";
std::cout << "info score mate " << -(score + MATE_SCORE) / 2 << " depth " << depth << " seldepth " << info.seldepth << " multipv " << options->MultiPV << " nodes " << nodes <<
" nps " << nps << " time " << GetTimeMs() - info.starttime << " pv ";

else if (score > MATE_FOUND && score < MATE_SCORE)
std::cout << "info score mate " << (MATE_SCORE - score) / 2 + 1 << " depth " << depth << " seldepth " << td->info.seldepth << " multipv " << options->MultiPV << " nodes " << nodes <<
" nps " << nps << " time " << GetTimeMs() - td->info.starttime << " pv ";
std::cout << "info score mate " << (MATE_SCORE - score) / 2 + 1 << " depth " << depth << " seldepth " << info.seldepth << " multipv " << options->MultiPV << " nodes " << nodes <<
" nps " << nps << " time " << GetTimeMs() - info.starttime << " pv ";

else
std::cout << "info score cp " << score << " depth " << depth << " seldepth " << td->info.seldepth << " multipv " << options->MultiPV << " nodes " << nodes <<
" nps " << nps << " hashfull "<< GetHashfull() << " time " << GetTimeMs() - td->info.starttime << " pv ";
std::cout << "info score cp " << score << " depth " << depth << " seldepth " << info.seldepth << " multipv " << options->MultiPV << " nodes " << nodes <<
" nps " << nps << " hashfull "<< GetHashfull() << " time " << GetTimeMs() - info.starttime << " pv ";

// loop over the moves within a PV line
for (int count = 0; count < std::max(pvTable.pvLength[0], 1); count++) {
Expand Down Expand Up @@ -262,7 +262,7 @@ void PrintUciOutput(const int score, const int depth, const ThreadData* td, cons

// Pretty print search info
std::cout << std::setw(3) << depth << "/";
std::cout << std::left << std::setw(3) << td->info.seldepth;
std::cout << std::left << std::setw(3) << info.seldepth;

std::cout << std::right << std::setw(8) << time_string;
std::cout << std::right << std::setw(10) << node_string;
Expand All @@ -279,4 +279,4 @@ void PrintUciOutput(const int score, const int depth, const ThreadData* td, cons
// print new line
std::cout << std::endl;
}
}
}
2 changes: 1 addition & 1 deletion src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ void PrintMoveList(const MoveList* list);

[[nodiscard]] char* FormatMove(const Move move);

void PrintUciOutput(const int score, const int depth, const ThreadData* td, const UciOptions* options);
void PrintUciOutput(const int score, const int depth, const UciOptions* options);
24 changes: 12 additions & 12 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "magic.h"
#include "init.h"
#include "cuckoo.h"
#include "search.h"

NNUE nnue = NNUE();

Expand All @@ -27,17 +28,16 @@ void ResetBoard(Position* pos) {
pos->state.plyFromNull = 0;
}

void ResetInfo(SearchInfo* info) {
info->depth = 0;
info->nodes = 0;
info->starttime = 0;
info->stoptimeOpt = 0;
info->stoptimeMax = 0;
info->movestogo = -1;
info->stopped = false;
info->timeset = false;
info->movetimeset = false;
info->nodeset = false;
void ResetInfo() {
info.depth = 0;
info.starttime = 0;
info.stoptimeOpt = 0;
info.stoptimeMax = 0;
info.movestogo = -1;
info.timeset = false;
info.movetimeset = false;
info.nodeset = false;
setStop(false);
}

// Generates zobrist key from scratch
Expand Down Expand Up @@ -522,4 +522,4 @@ bool hasGameCycle(Position* pos, int ply) {
}
}
return false;
}
}
2 changes: 1 addition & 1 deletion src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void ParseFen(const std::string& command, Position* pos);
// Parse a string of moves in coordinate format and plays them
void parse_moves(const std::string& moves, Position* pos);

void ResetInfo(SearchInfo* info);
void ResetInfo();

// Retrieve a generic piece (useful when we don't know what type of piece we are dealing with
[[nodiscard]] Bitboard GetPieceBB(const Position* pos, const int piecetype);
Expand Down
Loading

0 comments on commit ebbd38c

Please sign in to comment.