From ad9eec8dbcd28be36c2acfbbf4875cc4b87e00e8 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Thu, 19 Sep 2019 21:58:13 +0200 Subject: [PATCH] List variant configuration options in INI (#30) --- src/parser.cpp | 17 +++++--- src/parser.h | 16 ++++++- src/variant.cpp | 2 +- src/variants.ini | 107 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 131 insertions(+), 11 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index e4c5f7067..13be2ee8e 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -16,8 +16,6 @@ along with this program. If not, see . */ -#include -#include #include #include @@ -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) { diff --git a/src/parser.h b/src/parser.h index 2cf790101..e634bdad5 100644 --- a/src/parser.h +++ b/src/parser.h @@ -19,16 +19,28 @@ #ifndef PARSER_H_INCLUDED #define PARSER_H_INCLUDED +#include + #include "variant.h" +class Config : public std::map { +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::find(s); + } +}; + class VariantParser { public: - VariantParser(const std::map& c) : config (c) {}; + VariantParser(const Config& c) : config (c) {}; Variant* parse(); Variant* parse(Variant* v); private: - std::map config; + Config config; template void parse_attribute(const std::string& key, T& target); }; diff --git a/src/variant.cpp b/src/variant.cpp index e64bf87a3..47f0937b9 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -727,7 +727,7 @@ void VariantMap::parse(std::string path) { variant_template = ""; // Read variant rules - std::map attribs = {}; + Config attribs = {}; while (file.peek() != '[' && std::getline(file, input)) { std::stringstream ss(input); diff --git a/src/variants.ini b/src/variants.ini index 73df9c8a5..512d6331a 100644 --- a/src/variants.ini +++ b/src/variants.ini @@ -16,18 +16,119 @@ # 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