Support suicide chess
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 31 Dec 2019 12:47:18 +0000 (13:47 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 31 Dec 2019 12:47:18 +0000 (13:47 +0100)
https://www.freechess.org/Help/HelpFiles/suicide_chess.html

Readme.md
src/position.h
src/variant.cpp
src/variant.h

index f6b481b..1a233bd 100644 (file)
--- a/Readme.md
+++ b/Readme.md
@@ -29,7 +29,7 @@ The games currently supported besides chess are listed below. Fairy-Stockfish ca
 - [Seirawan](https://en.wikipedia.org/wiki/Seirawan_chess), Seirawan-Crazyhouse
 - [Amazon](https://en.wikipedia.org/wiki/Amazon_(chess)), [Chigorin](https://en.wikipedia.org/wiki/Chigorin_Chess), [Almost chess](https://en.wikipedia.org/wiki/Almost_Chess)
 - [Hoppel-Poppel](http://www.chessvariants.com/diffmove.dir/hoppel-poppel.html), New Zealand
-- [Antichess](https://lichess.org/variant/antichess), [Giveaway](http://www.chessvariants.com/diffobjective.dir/giveaway.old.html), [Losers](https://www.chessclub.com/help/Wild17), [Codrus](http://www.binnewirtz.com/Schlagschach1.htm)
+- [Antichess](https://lichess.org/variant/antichess), [Giveaway](http://www.chessvariants.com/diffobjective.dir/giveaway.old.html), [Suicide](https://www.freechess.org/Help/HelpFiles/suicide_chess.html), [Losers](https://www.chessclub.com/help/Wild17), [Codrus](http://www.binnewirtz.com/Schlagschach1.htm)
 - [Extinction](https://en.wikipedia.org/wiki/Extinction_chess), [Kinglet](https://en.wikipedia.org/wiki/V._R._Parton#Kinglet_Chess)
 - [King of the Hill](https://en.wikipedia.org/wiki/King_of_the_Hill_(chess)), [Racing Kings](https://en.wikipedia.org/wiki/V._R._Parton#Racing_Kings)
 - [Three-check](https://en.wikipedia.org/wiki/Three-check_chess), Five-check
index 4c265f9..33723c6 100644 (file)
@@ -569,6 +569,11 @@ inline int Position::n_fold_rule() const {
 
 inline Value Position::stalemate_value(int ply) const {
   assert(var != nullptr);
+  if (var->stalematePieceCount)
+  {
+      int c = count<ALL_PIECES>(sideToMove) - count<ALL_PIECES>(~sideToMove);
+      return c == 0 ? VALUE_DRAW : convert_mate_value(c < 0 ? var->stalemateValue : -var->stalemateValue, ply);
+  }
   return convert_mate_value(var->stalemateValue, ply);
 }
 
index 7615515..a2d3fc9 100644 (file)
@@ -201,6 +201,11 @@ namespace {
         v->castling = false;
         return v;
     }
+    Variant* suicide_variant() {
+        Variant* v = antichess_variant();
+        v->stalematePieceCount = true;
+        return v;
+    }
     Variant* codrus_variant() {
         Variant* v = giveaway_variant();
         v->promotionPieceTypes = {QUEEN, ROOK, BISHOP, KNIGHT};
@@ -813,6 +818,7 @@ void VariantMap::init() {
     add("losers", losers_variant());
     add("giveaway", giveaway_variant());
     add("antichess", antichess_variant());
+    add("suicide", suicide_variant());
     add("codrus", codrus_variant());
     add("extinction", extinction_variant());
     add("kinglet", kinglet_variant());
index 0581227..49bbf76 100644 (file)
@@ -91,6 +91,7 @@ struct Variant {
   bool nFoldValueAbsolute = false;
   bool perpetualCheckIllegal = false;
   Value stalemateValue = VALUE_DRAW;
+  bool stalematePieceCount = false; // multiply stalemate value by sign(count(~stm) - count(stm))
   Value checkmateValue = -VALUE_MATE;
   bool shogiPawnDropMateIllegal = false;
   bool shatarMateRule = false;