From c5d0019c6d7f43a46f409b9e7664eb2eaae1a1cd Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sat, 12 Jan 2019 19:18:45 +0100 Subject: [PATCH] Support prohibition of perpetual check Completes the rule implementation of shogi variants. --- src/position.cpp | 6 +++++- src/variant.cpp | 1 + src/variant.h | 1 + 3 files changed, 7 insertions(+), 1 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 9922efc..29ce04d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1561,17 +1561,21 @@ bool Position::is_optional_game_end(Value& result, int ply) const { StateInfo* stp = st->previous->previous; int cnt = 0; + bool perpetual = true; for (int i = 4; i <= end; i += 2) { stp = stp->previous->previous; + perpetual &= bool(stp->checkersBB); // Return a draw score if a position repeats once earlier but strictly // after the root, or repeats twice before or at the root. if ( stp->key == st->key && ++cnt + 1 == (ply > i ? 2 : n_fold_rule())) { - result = convert_mate_value(var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue : var->nFoldValue, ply); + result = convert_mate_value( var->perpetualCheckIllegal && perpetual ? VALUE_MATE + : var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue + : var->nFoldValue, ply); return true; } } diff --git a/src/variant.cpp b/src/variant.cpp index 84260f5..14e2d9e 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -271,6 +271,7 @@ VariantMap variants; // Global object v->stalemateValue = -VALUE_MATE; v->nFoldRule = 4; v->nMoveRule = 0; + v->perpetualCheckIllegal = true; return v; } Variant* minishogi_variant() { diff --git a/src/variant.h b/src/variant.h index cd7421f..9fa1c0f 100644 --- a/src/variant.h +++ b/src/variant.h @@ -73,6 +73,7 @@ struct Variant { int nFoldRule = 3; Value nFoldValue = VALUE_DRAW; bool nFoldValueAbsolute = false; + bool perpetualCheckIllegal = false; Value stalemateValue = VALUE_DRAW; Value checkmateValue = -VALUE_MATE; bool shogiPawnDropMateIllegal = false; -- 1.7.0.4