From 5bb6cdf7ba732f2f108451214a3eed243fc14024 Mon Sep 17 00:00:00 2001 From: fsmosca Date: Mon, 5 Apr 2021 13:29:49 +0800 Subject: [PATCH 1/3] Update gensfen.cpp * Terminate game by 3-fold repetition. * Fix segmentation fault by properly initializing the random_multi_pv_depth. --- src/learn/gensfen.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/learn/gensfen.cpp b/src/learn/gensfen.cpp index 06e6295b..b28afa13 100644 --- a/src/learn/gensfen.cpp +++ b/src/learn/gensfen.cpp @@ -110,6 +110,8 @@ namespace Learner save_every = std::max(save_every, REPORT_STATS_EVERY); num_threads = Options["Threads"]; + + random_multi_pv_depth = std::max(search_depth_max, random_multi_pv_depth); } }; @@ -489,8 +491,11 @@ namespace Learner // draw at the maximum number of steps to write. const int ply = move_hist_scores.size(); - // has it reached the max length or is a draw - if (ply >= params.write_maxply || pos.is_draw(ply)) + // has it reached the max length or is a draw by fifty-move rule + // or by 3-fold repetition + if (ply >= params.write_maxply + || pos.is_fifty_move_draw() + || pos.is_three_fold_repetition()) { return 0; } From f57af4d203fd86a35f088786ba06531539c2190b Mon Sep 17 00:00:00 2001 From: fsmosca Date: Mon, 5 Apr 2021 13:31:21 +0800 Subject: [PATCH 2/3] Update position.cpp * Add is_fifty_move_draw() and is_three_fold_repetition for gensfen() --- src/position.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/position.cpp b/src/position.cpp index 934c1403..1b5ff222 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1180,6 +1180,22 @@ bool Position::is_draw(int ply) const { } +/// Position::is_fifty_move_draw() returns true if a game can be claimed +/// by a fifty-move draw rule. + +bool Position::is_fifty_move_draw() const { + + return (st->rule50 > 99 && (!checkers() || MoveList(*this).size())); +} + + +/// Position::is_three_fold_repetition() returns true if there is 3-fold repetition. +bool Position::is_three_fold_repetition() const { + + return st->repetition < 0; +} + + // Position::has_repeated() tests whether there has been at least one repetition // of positions since the last capture or pawn move. From 560daefb01639fe04c185756051b9b9bdb0b57ef Mon Sep 17 00:00:00 2001 From: fsmosca Date: Mon, 5 Apr 2021 13:31:49 +0800 Subject: [PATCH 3/3] Update position.h * Add is_fifty_move_draw() and is_three_fold_repetition for gensfen() --- src/position.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/position.h b/src/position.h index e7513eb1..fe5be374 100644 --- a/src/position.h +++ b/src/position.h @@ -161,6 +161,8 @@ public: bool is_chess960() const; Thread* this_thread() const; bool is_draw(int ply) const; + bool is_fifty_move_draw() const; + bool is_three_fold_repetition() const; bool has_game_cycle(int ply) const; bool has_repeated() const; int rule50_count() const;