Skip to content

Commit

Permalink
List variant configuration options in INI (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfab committed Sep 20, 2019
1 parent 6aab09c commit ad9eec8
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 11 deletions.
17 changes: 12 additions & 5 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <map>
#include <vector>
#include <string>
#include <sstream>

Expand All @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@
#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);
};

Expand Down
2 changes: 1 addition & 1 deletion src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
107 changes: 104 additions & 3 deletions src/variants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad9eec8

Please sign in to comment.