New Variant Cheat Sheet - fairy-stockfish/Fairy-Stockfish GitHub Wiki
- For most variants, you will only have to add a new entry to variants.ini
- Check to see if the options to create your variant already exist.
- For rule variants, see variants.ini -> "Rule definition options"
- For custom pieces, see variants.ini -> "Custom pieces"
- Most variants are added to variants.ini, but some are added to variant.cpp
- If your game rules aren't supported:
-
Break it down into what changes will be required. For instance, "Connect 4" can be broken down into settings such as:
enclosingDrop = top connectN = 4
rather than
playConnect4 = true
-
In variant.h -> "struct Variant", add a variable for each new setting
-
In parser.cpp -> "parse(Variant* v)", add "parse_attribute" to read from variants.ini into the variable.
-
In position.h, most settings have a getter with a snake_case name which reads the camelCase variable. Remember to declare the getter under "class Position".
-
If your rule changes how moves occur, see:
- movegen.cpp->“make_move_and_gating(const Position& pos, ExtMove* moveList, Color us, Square from, Square to, PieceType pt = NO_PIECE_TYPE)”
- position.cpp -> "do_move(Move m, StateInfo& newSt, bool givesCheck)"
- position.cpp->”legal(Move m)”
- position.cpp->”pseudo_legal(const Move m)”
- position.cpp->”undo_move(Move m)”
-
If your rule includes a new Betza modifier, piece.cpp->”from_betza(const std::string& betza, const std::string& name)”
-
If your rule adjudicates win, loss, or draw, see position.cpp -> "is_immediate_game_end(Value& result, int ply)" or "is_optional_game_end(Value& result, int ply, int countStarted)"
-
See https://github.com/fairy-stockfish/Fairy-Stockfish/wiki/Understanding-the-code for more descriptions.
-
Document your new setting in the comment section at the beginning on variants.ini
-
Do not break backwards compatibility with previous .ini files that people may have. If you are making a more flexible version of a previous configuration option, read the previous option into the new option with defaults that reflect the old behaviour.
-
Performance and portability are top priorities. Try to avoid excessive dependencies, or intensive computation inside main loops.
-
Code is indented 2 spaces for the first function level, then 4 spaces each level after that.
-
- Other functions:
- “movegen.cpp->generate_all” calls “movegen.cpp->generate_drops”, “movegen.cpp->generate_moves”, and “movegen.cpp->generate_pawn_moves”.
- “movegen.cpp->make_move_and_gating” is called by the above to encode and store the moves they generate in moveList
- “position.cpp->pseudo_legal” checks basic validity “position.cpp->legal” does a more extensive check, like making sure you aren’t hanging your king.
- “position.cpp->do_move” performs the actual change of board state, while “position.cpp->undo_move” reverses it.
- Testing your variant
-
Compile using “make”. Type “make help” to see important options. Remember that you need to run "make" from the "src" folder, the executable will be created there, and the default location for "variants.ini" is in there.
- “largeboards=yes” if your board is greater than 8x8. Boards greater than 10x12 are not supported.
- “all=yes” if your variant has a large branching factor such as “Duck Chess” or “Game of the Amazons”
- “debug=yes” and “optimize=no” if you’re troubleshooting
-
You can use a GUI (see docs for your GUI if so), or run the executable directly. Useful options:
- “setoption name VariantPath value variants.ini”
- “setoption name UCI_Variant value [your_variant]”
-
To play moves, start with “position”, either “startpos” or “fen” then use coordinates to play your moves. ie.
- “position startpos moves e2e4 e7e5”
- “position fen 4k3/8/8/8/8/8/p7/4K2R w K - 0 1 moves e1g1 a2a1q”
- Castling is encoded as “king moves two spaces”
- Promotion piece is indicated with just letter (no “=”)
- Drops are encoded with “@”. For instance, tictactoe looks like: position startpos moves P@b2 P@a1 P@c1
- “d” (prints current board using text characters)
- “go movetime [milliseconds]”
- “go depth [ply]”
- “quit”
-
If you want to automate your testing, you can use redirection from the command line: Create test.txt:
position startpos moves e2e4 d7d5 go movetime 100 d quit
Run stockfish:
stockfish < test.txt > output.txt
-