From 486f72af5418a7915779c496f92c7fc2722e3e18 Mon Sep 17 00:00:00 2001 From: tttak Date: Tue, 30 Jun 2020 13:30:18 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3=EF=BC=88le?= =?UTF-8?q?arn=20convert=5Fbin=5Ffrom=5Fpgn-extract=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/learn/learner.cpp | 55 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/learn/learner.cpp b/src/learn/learner.cpp index c13b69f7..d2507fba 100644 --- a/src/learn/learner.cpp +++ b/src/learn/learner.cpp @@ -2614,6 +2614,7 @@ void convert_bin_from_pgn_extract(const vector& filenames, const string& else { int gamePly = 0; + bool first = true; PackedSfenValue psv; memset((char*)&psv, 0, sizeof(PackedSfenValue)); @@ -2682,6 +2683,35 @@ void convert_bin_from_pgn_extract(const vector& filenames, const string& break; } + if (first) { + first = false; + } + else { + psv.gamePly = gamePly; + psv.game_result = game_result; + + if (pos.side_to_move() == BLACK) { + if (!pgn_eval_side_to_move) { + psv.score *= -1; + } + psv.game_result *= -1; + } + +#if 0 + std::cout << "write: " + << "score=" << psv.score + << ", move=" << psv.move + << ", gamePly=" << psv.gamePly + << ", game_result=" << (int)psv.game_result + << std::endl; +#endif + + ofs.write((char*)&psv, sizeof(PackedSfenValue)); + memset((char*)&psv, 0, sizeof(PackedSfenValue)); + + fen_count++; + } + // example: { rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR b KQkq d3 0 1 } if (!std::regex_search(itr, line.cend(), match, pattern_bracket)) { break; @@ -2706,31 +2736,6 @@ void convert_bin_from_pgn_extract(const vector& filenames, const string& trim(str_move); //std::cout << "str_move=" << str_move << std::endl; psv.move = UCI::to_move(pos, str_move); - - // - psv.gamePly = gamePly; - psv.game_result = game_result; - - if (pos.side_to_move() == BLACK) { - if (!pgn_eval_side_to_move) { - psv.score *= -1; - } - psv.game_result *= -1; - } - -#if 0 - std::cout << "write: " - << "score=" << psv.score - << ", move=" << psv.move - << ", gamePly=" << psv.gamePly - << ", game_result=" << (int)psv.game_result - << std::endl; -#endif - - ofs.write((char*)&psv, sizeof(PackedSfenValue)); - memset((char*)&psv, 0, sizeof(PackedSfenValue)); - - fen_count++; } game_result = 0;