Skip to content

Commit

Permalink
Nicer output
Browse files Browse the repository at this point in the history
  • Loading branch information
rn5f107s2 committed Nov 16, 2024
1 parent ef7f1b6 commit 29326ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 26 additions & 10 deletions src/Datagen/Newgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@ void start(const std::string &filePrefix, u64 initialSeed, int batchSize) {
}

void loop(SearchState &state, Position &pos, const std::string &filePrefix, std::mt19937 &random, int batchSize) {
int batch = 0;
int batch = 1;

while (true) {
std::string fileName = filePrefix + "_b" + std::to_string(batch);
std::ofstream out(fileName);
auto begin = std::chrono::steady_clock::now();
int fens = 0;

for (int i = 0; i < batchSize; i++) {
std::cout << "Starting Batch " << batch << std::endl;

for (int i = 1; i <= batchSize; i++) {
createExit(state, pos, random);
playGame(state, pos, out);
fens += playGame(state, pos, out);

u64 timeTaken = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - begin).count();
u64 fps = (fens * 1000) / std::max(timeTaken, uint64_t(1));

std::cout << "\r[" << i << " / " << batchSize << "] Games played at " << fps << " fens/second" << std::flush;
}

out.close();
batch++;

std::cout << std::endl;
}

}

void createExit(SearchState &state, Position &pos, std::mt19937 &random) {
Expand Down Expand Up @@ -66,7 +76,7 @@ bool verifyExit(SearchState &state, Position &pos) {
return abs(state.startSearch(pos, state.si.st, MAXDEPTH)) <= MAX_UNBALANCE;
}

void playGame(SearchState &state, Position &pos, std::ofstream &out) {
int playGame(SearchState &state, Position &pos, std::ofstream &out) {
state.clearHistory();
state.si.st.nodeLimit = SEARCH_NODES;

Expand All @@ -88,6 +98,14 @@ void playGame(SearchState &state, Position &pos, std::ofstream &out) {
break;
}

if ( pos.plys50moveRule >= 100
|| pos.hasRepeated(0)
|| (pos.phase <= 3 && !(pos.getPieces(PAWN))))
{
result = 1;
break;
}

fens.push(pos.fen());
scores.push(score);
bestMoves.push(bestMove);
Expand All @@ -109,11 +127,7 @@ void playGame(SearchState &state, Position &pos, std::ofstream &out) {
break;
}

if ( adjCounter[1] >= DADJ_MOVECOUNT
|| pos.plys50moveRule >= 100
|| pos.hasRepeated(0)
|| (pos.phase <= 3 && !(pos.getPieces(PAWN))))
{
if (adjCounter[1] >= DADJ_MOVECOUNT) {
result = 1;
break;
}
Expand All @@ -132,6 +146,8 @@ void playGame(SearchState &state, Position &pos, std::ofstream &out) {
<< moveToString(bestMoves.at(i)) << "\n";

out << std::flush;

return fens.getSize();
}

#endif
4 changes: 2 additions & 2 deletions src/Datagen/Newgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ static const int MAX_UNBALANCE = 150;
static const int WADJ_SCORE = 1000;
static const int WADJ_MOVECOUNT = 8;
static const int DADJ_SCORE = 0;
static const int DADJ_MOVECOUNT = 25;
static const int DADJ_MOVECOUNT = 20;

void start(const std::string &filePrefix, u64 initialSeed, int batchSize = 16384);
void loop(SearchState &st, Position &pos, const std::string &filePrefix, std::mt19937 &random, int batchSize);
void createExit(SearchState &state, Position &pos, std::mt19937 &random);
bool verifyExit(SearchState &state, Position &pos);
void playGame(SearchState &state, Position &pos, std::ofstream &out);
int playGame(SearchState &state, Position &pos, std::ofstream &out);

#endif

Expand Down

0 comments on commit 29326ac

Please sign in to comment.