Support Supply chess
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 10 Jan 2020 17:15:33 +0000 (18:15 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 10 Jan 2020 17:15:33 +0000 (18:15 +0100)
A four-player variant of Xiangqi similar to bughouse:
https://en.wikipedia.org/wiki/Xiangqi#Variations

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

index a16d9af..f25a784 100644 (file)
--- a/Readme.md
+++ b/Readme.md
@@ -14,8 +14,8 @@ The goal of the project is to create an engine supporting a large variety of che
 The games currently supported besides chess are listed below. Fairy-Stockfish can also play user-defined variants loaded via a variant configuration file, see the file [`src/variants.ini`](https://github.com/ianfab/Fairy-Stockfish/blob/master/src/variants.ini).
 
 ### Regional and historical games
-- [Xiangqi](https://en.wikipedia.org/wiki/Xiangqi), [Manchu](https://en.wikipedia.org/wiki/Manchu_chess), [Minixiangqi](http://mlwi.magix.net/bg/minixiangqi.htm)
-- [Shogi](https://en.wikipedia.org/wiki/Shogi)
+- [Xiangqi](https://en.wikipedia.org/wiki/Xiangqi), [Manchu](https://en.wikipedia.org/wiki/Manchu_chess), [Minixiangqi](http://mlwi.magix.net/bg/minixiangqi.htm), [Supply chess](https://en.wikipedia.org/wiki/Xiangqi#Variations)
+- [Shogi](https://en.wikipedia.org/wiki/Shogi), [Shogi variants](https://github.com/ianfab/Fairy-Stockfish#shogi-variants)
 - [Makruk](https://en.wikipedia.org/wiki/Makruk), [Ouk Chatrang](https://en.wikipedia.org/wiki/Makruk#Cambodian_chess), [Kar Ouk](https://en.wikipedia.org/wiki/Makruk#Cambodian_chess), [ASEAN](http://hgm.nubati.net/rules/ASEAN.html), Ai-Wok
 - [Sittuyin](https://en.wikipedia.org/wiki/Sittuyin)
 - [Shatar](https://en.wikipedia.org/wiki/Shatar), [Jeson Mor](https://en.wikipedia.org/wiki/Jeson_Mor)
index 105b5cf..8b9aaea 100644 (file)
@@ -825,7 +825,7 @@ bool Position::legal(Move m) const {
   assert(board_bb() & to);
 
   // Illegal checks
-  if ((!checking_permitted() || (sittuyin_promotion() && type_of(m) == PROMOTION)) && gives_check(m))
+  if ((!checking_permitted() || (sittuyin_promotion() && type_of(m) == PROMOTION) || (!drop_checks() && type_of(m) == DROP)) && gives_check(m))
       return false;
 
   // Illegal quiet moves
index b231417..548b609 100644 (file)
@@ -122,6 +122,7 @@ public:
   PieceType castling_rook_piece() const;
   PieceType king_type() const;
   bool checking_permitted() const;
+  bool drop_checks() const;
   bool must_capture() const;
   bool must_drop() const;
   bool piece_drops() const;
@@ -453,6 +454,11 @@ inline bool Position::checking_permitted() const {
   return var->checking;
 }
 
+inline bool Position::drop_checks() const {
+  assert(var != nullptr);
+  return var->dropChecks;
+}
+
 inline bool Position::must_capture() const {
   assert(var != nullptr);
   return var->mustCapture;
index 0c85ec1..5858169 100644 (file)
@@ -793,6 +793,8 @@ namespace {
         v->xiangqiSoldier = true;
         return v;
     }
+    // Manchu/Yitong chess
+    // https://en.wikipedia.org/wiki/Manchu_chess
     Variant* manchu_variant() {
         Variant* v = xiangqi_variant();
         v->pieceToCharTable = "PN.R.AB..K.C....M.....pn.r.ab..k.c..........";
@@ -800,6 +802,19 @@ namespace {
         v->startFen = "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/9/9/M1BAKAB2 w - - 0 1";
         return v;
     }
+    // Supply chess
+    // https://en.wikipedia.org/wiki/Xiangqi#Variations
+    Variant* supply_variant() {
+        Variant* v = xiangqi_variant();
+        v->variantTemplate = "bughouse";
+        v->startFen = "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR[] w - - 0 1";
+        v->twoBoards = true;
+        v->pieceDrops = true;
+        v->dropChecks = false;
+        v->whiteDropRegion = v->mobilityRegion[WHITE][ELEPHANT];
+        v->blackDropRegion = v->mobilityRegion[BLACK][ELEPHANT];
+        return v;
+    }
 #endif
 
 } // namespace
@@ -879,6 +894,7 @@ void VariantMap::init() {
     add("clobber10", clobber10_variant());
     add("xiangqi", xiangqi_variant());
     add("manchu", manchu_variant());
+    add("supply", supply_variant());
 #endif
 }
 
index d7be1f8..9461ea2 100644 (file)
@@ -66,6 +66,7 @@ struct Variant {
   PieceType castlingRookPiece = ROOK;
   PieceType kingType = KING;
   bool checking = true;
+  bool dropChecks = true;
   bool mustCapture = false;
   bool mustDrop = false;
   bool pieceDrops = false;
index cbaa530..0f4bf3b 100644 (file)
 # castlingRookPiece: piece type that participates in castling [PieceType] (default: r)
 # kingType: piece type defining moves of king/royal piece (default: k)
 # checking: allow checks [bool] (default: true)
+# dropChecks: allow checks by piece drops [bool] (default: true)
 # mustCapture: captures are mandatory (check evasion still takes precedence) [bool] (default: false)
 # mustDrop: drops are mandatory (e.g., for Sittuyin setup phase) [bool] (default: false)
 # pieceDrops: enable piece drops [bool] (default: false)
@@ -212,6 +213,7 @@ capturesToHand = true
 [xiangqihouse:xiangqi]
 pieceDrops = true
 capturesToHand = true
+dropChecks = false
 whiteDropRegion = *1 *2 *3 *4 *5
 blackDropRegion = *6 *7 *8 *9 *10