List variant configuration options in INI (#30)
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 19 Sep 2019 19:58:13 +0000 (21:58 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 20 Sep 2019 13:32:11 +0000 (15:32 +0200)
src/parser.cpp
src/parser.h
src/variant.cpp
src/variants.ini

index e4c5f70..13be2ee 100644 (file)
@@ -16,8 +16,6 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <map>
-#include <vector>
 #include <string>
 #include <sstream>
 
@@ -42,9 +40,18 @@ namespace {
 
     template <> void set(const std::string& value, File& target) {
         std::stringstream ss(value);
-        int i;
-        ss >> i;
-        target = File(i - 1);
+        if (isdigit(ss.peek()))
+        {
+            int i;
+            ss >> i;
+            target = File(i - 1);
+        }
+        else
+        {
+            char c;
+            ss >> c;
+            target = File(c - 'a');
+        }
     }
 
     template <> void set(const std::string& value, std::string& target) {
index 2cf7901..e634bda 100644 (file)
 #ifndef PARSER_H_INCLUDED
 #define PARSER_H_INCLUDED
 
+#include <iostream>
+
 #include "variant.h"
 
+class Config : public std::map<std::string, std::string> {
+public:
+    Config::iterator find (const std::string& s) {
+        constexpr bool PrintOptions = false; // print config options?
+        if (PrintOptions)
+            std::cout << s << std::endl;
+        return std::map<std::string, std::string>::find(s);
+    }
+};
+
 class VariantParser {
 public:
-    VariantParser(const std::map<std::string, std::string>& c) : config (c) {};
+    VariantParser(const Config& c) : config (c) {};
     Variant* parse();
     Variant* parse(Variant* v);
 
 private:
-    std::map<std::string, std::string> config;
+    Config config;
     template <class T> void parse_attribute(const std::string& key, T& target);
 };
 
index e64bf87..47f0937 100644 (file)
@@ -727,7 +727,7 @@ void VariantMap::parse(std::string path) {
             variant_template = "";
 
         // Read variant rules
-        std::map<std::string, std::string> attribs = {};
+        Config attribs = {};
         while (file.peek() != '[' && std::getline(file, input))
         {
             std::stringstream ss(input);
index 73df9c8..512d633 100644 (file)
 
 # This is a configuration file to add user-defined variants to Fairy-Stockfish.
 
-# Usage:
+################################################
+### Usage:
 # Add "load" and the file path to the SF call (e.g., "./stockfish load variants.ini")
 # or set the UCI option "VariantPath" to the path of this file in order to load it.
 
-# Variant configuration:
+################################################
+### Variant configuration:
 # The variant name needs to be specified as a section in square brackets,
 # followed by its rule configurations as key-value pairs.
 # See variants.h for the available options and their default values.
 # If you encounter problems configuring variants, please report them at:
 # https://github.com/ianfab/Fairy-Stockfish/issues
 
-# Example for minishogi configuration that would be equivalent to the built-in variant:
+### Piece types
+# Firstly, the piece types for a variant need to be defined.
+# For that, specify the letter used for each piece type, e.g.:
+# pawn = p
+#
+# See the list below for all available piece types:
+# pawn
+# knight
+# bishop
+# rook
+# queen
+# fers
+# alfil
+# fers_alfil (=fers+alfil)
+# silver
+# aiwok (=rook+knight+fers)
+# bers (=rook+fers)
+# archbishop (=bishop+knight)
+# chancellor(=rook+bishop)
+# amazon (=queen+knight)
+# knibis
+# biskni
+# shogi_pawn
+# lance
+# shogi_knight
+# euroshogi_knight
+# gold
+# horse
+# clobber
+# breakthrough
+# immobile (piece without moves)
+# cannon
+# wazir
+# commoner (non-royal king)
+# king
+
+### Rule options
+# variantTemplate
+# pocketSize
+# maxRank: maximum rank (e.g., 8)
+# maxFile: maximum file (e.g., 8 or h)
+# chess960: allow chess960 castling (true/false)
+# startFen: FEN of starting position
+# promotionRank: relative rank required to reach for promotion (e.g., 8)
+# promotionPieceTypes: pieces letters of promotion options (e.g., nbrq)
+# sittuyinPromotion: (true/false)
+# promotionLimit
+# promotedPieceType
+# piecePromotionOnCapture: (true/false)
+# mandatoryPawnPromotion: (true/false)
+# mandatoryPiecePromotion: (true/false)
+# pieceDemotion: (true/false)
+# endgameEval: (true/false)
+# doubleStep: (true/false)
+# doubleStepRank
+# firstRankDoubleSteps: (true/false)
+# castling: (true/false)
+# castlingDroppedPiece: (true/false)
+# castlingKingsideFile: e.g., g
+# castlingQueensideFile: e.g., c
+# castlingRank: relative rank of castling, e.g., 1
+# checking: (true/false)
+# mustCapture: (true/false)
+# mustDrop: (true/false)
+# pieceDrops: (true/false)
+# dropLoop: (true/false)
+# capturesToHand: (true/false)
+# firstRankDrops: (true/false)
+# dropOnTop: (true/false)
+# whiteDropRegion
+# blackDropRegion
+# sittuyinRookDrop: (true/false)
+# dropOppositeColoredBishop: (true/false)
+# dropPromoted: (true/false)
+# shogiDoubledPawn: (true/false)
+# immobilityIllegal: (true/false)
+# gating: (true/false)
+# nMoveRule: e.g., 50
+# nFoldRule: e.g., 3
+# nFoldValue: (win/draw/loss)
+# nFoldValueAbsolute: (true/false)
+# perpetualCheckIllegal: (true/false)
+# stalemateValue: (win/draw/loss)
+# checkmateValue: (win/draw/loss)
+# shogiPawnDropMateIllegal: (true/false)
+# shatarMateRule: (true/false)
+# bareKingValue: (win/draw/loss)
+# extinctionValue: (win/draw/loss)
+# bareKingMove: (true/false)
+# extinctionPieceTypes
+# flagPiece
+# whiteFlag
+# blackFlag
+# flagMove: (true/false)
+# checkCounting: (true/false)
+# connectN: number of aligned pieces for win (e.g., 4)
+# countingRule: (makruk/asean)
+
+################################################
+### Example for minishogi configuration that would be equivalent to the built-in variant:
 
 # [minishogi]
 # variantTemplate = shogi