Simplify configuration of custom royal pieces
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 6 Nov 2021 16:59:06 +0000 (17:59 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 6 Nov 2021 17:55:29 +0000 (18:55 +0100)
Use the same syntax for custom king as for other custom pieces.

Closes #363.

src/parser.cpp
src/types.h
src/variants.ini

index 7d6ac68..b76b577 100644 (file)
@@ -164,6 +164,10 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
     // piece types
     for (PieceType pt = PAWN; pt <= KING; ++pt)
     {
+        if (pt == CUSTOM_PIECES_ROYAL)
+            // reserved custom royal/king slot
+            continue;
+
         // piece char
         std::string name = piece_name(pt);
 
@@ -186,6 +190,17 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
                 else if (DoCheck)
                     std::cerr << name << " - Missing Betza move notation" << std::endl;
             }
+            else if (pt == KING)
+            {
+                if (keyValue->second.size() > 1)
+                {
+                    // custom royal piece
+                    v->customPiece[CUSTOM_PIECES_ROYAL - CUSTOM_PIECES] = keyValue->second.substr(2);
+                    v->kingType = CUSTOM_PIECES_ROYAL;
+                }
+                else
+                    v->kingType = KING;
+            }
         }
         // mobility region
         std::string capitalizedPiece = name;
@@ -281,7 +296,6 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
     parse_attribute("castlingKingFile", v->castlingKingFile);
     parse_attribute("castlingKingPiece", v->castlingKingPiece, v->pieceToChar);
     parse_attribute("castlingRookPiece", v->castlingRookPiece, v->pieceToChar);
-    parse_attribute("kingType", v->kingType, v->pieceToChar);
     parse_attribute("checking", v->checking);
     parse_attribute("dropChecks", v->dropChecks);
     parse_attribute("mustCapture", v->mustCapture);
@@ -415,7 +429,9 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
                 std::cerr << "Can not use kings with blastOnCapture." << std::endl;
             if (v->flipEnclosedPieces)
                 std::cerr << "Can not use kings with flipEnclosedPieces." << std::endl;
-            // We can not fully check custom king movements at this point
+            // We can not fully check support for custom king movements at this point,
+            // since custom pieces are only initialized on loading of the variant.
+            // We will assume this is valid, but it might cause problems later if it's not.
             if (!is_custom(v->kingType))
             {
                 const PieceInfo* pi = pieceMap.find(v->kingType)->second;
index c82e76f..531bf65 100644 (file)
@@ -397,6 +397,7 @@ enum PieceType {
   PIECE_TYPE_NB = 1 << PIECE_TYPE_BITS,
   KING = PIECE_TYPE_NB - 1,
   CUSTOM_PIECES_END = KING - 1,
+  CUSTOM_PIECES_ROYAL = CUSTOM_PIECES_END,
   CUSTOM_PIECES_NB = CUSTOM_PIECES_END - CUSTOM_PIECES + 1,
   ALL_PIECES = 0,
 };
index 624ae38..f59911c 100644 (file)
 
 ### Custom pieces
 # Custom pieces can be defined by using one of the available slots:
-# customPiece1, customPiece2, ..., customPiece26
+# customPiece1, customPiece2, ..., customPiece25
 # E.g., pawns without double steps could be described as:
 # customPiece1 = p:mfWcfF
 #
+# You can define custom king movements in the same way you can define another custom piece.
+# E.g., to make the king move like a centaur:
+# king = k:KN
+# In constrast to other custom pieces the Betza notation for the king is optional though
+# and defaults to a standard chess king (betza: K) when skipped, e.g.:
+# king = k
+#
 # The movements of custom pieces can be defined using the Betza notation.
 # https://www.gnu.org/software/xboard/Betza.html
 # In Fairy-Stockfish only a subset of Betza notation can be used. The supported features are:
 # castlingKingFile: starting file of the castlingKingPiece if there can be more than one of that type [File] (default: e)
 # castlingKingPiece: first piece type that participates in castling [PieceType] (default: k)
 # castlingRookPiece: second 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)
@@ -326,6 +332,11 @@ promotionPieceTypes = q
 doubleStep = false
 castling = false
 
+# Centaurking
+# A variant demonstrating how to define a custom royal piece movement
+[centaurking:chess]
+king = k:KN
+
 # Mahajarah and the Sepoys
 # https://en.wikipedia.org/wiki/Maharajah_and_the_Sepoys
 [maharajah]