|
| 1 | +# Fairy-Stockfish Development Guide |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +**Fairy-Stockfish** is a chess variant engine derived from Stockfish, designed to support numerous chess variants and protocols. Written primarily in C++17, it includes Python and JavaScript bindings for library use. |
| 6 | + |
| 7 | +**Repository Statistics:** |
| 8 | +- **Languages:** C++17 (primary), Python, JavaScript, Shell scripts |
| 9 | +- **Architecture:** Multi-protocol chess engine (UCI, UCCI, USI, XBoard/CECP) |
| 10 | +- **Target Platforms:** Windows, Linux, macOS, Android, WebAssembly |
| 11 | +- **Supported Variants:** 90+ chess variants including regional, historical, and modern variants |
| 12 | + |
| 13 | +## Build System & Requirements |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | +- **Compiler:** GCC, Clang, or MSVC with C++17 support |
| 17 | +- **Build Tool:** GNU Make (required for C++ engine) |
| 18 | +- **Python:** 3.7+ (for Python bindings) |
| 19 | +- **Node.js:** (for JavaScript bindings) |
| 20 | +- **Additional Tools:** expect utility (for testing) |
| 21 | + |
| 22 | +### Core Build Process |
| 23 | + |
| 24 | +Note: Run engine and test commands from the `src/` directory unless specified otherwise. |
| 25 | + |
| 26 | +#### Basic Build Commands |
| 27 | +```bash |
| 28 | +# Standard release build (recommended for most users) |
| 29 | +make -j2 ARCH=x86-64 build |
| 30 | + |
| 31 | +# Debug build (for development) |
| 32 | +make -j2 ARCH=x86-64 debug=yes build |
| 33 | + |
| 34 | +# All variants including ones with large boards (up to 12x10) and large branching factor (all) |
| 35 | +make -j2 ARCH=x86-64 largeboards=yes all=yes build |
| 36 | +``` |
| 37 | + |
| 38 | +### Python Bindings (pyffish) |
| 39 | +```bash |
| 40 | +# Build Python bindings (from repository root) |
| 41 | +python3 setup.py install |
| 42 | + |
| 43 | +# Alternative: Install from PyPI |
| 44 | +pip install pyffish |
| 45 | +``` |
| 46 | + |
| 47 | +### JavaScript Bindings (ffish.js) |
| 48 | +Also see the `tests/js/README.md`. |
| 49 | +```bash |
| 50 | +cd src/ |
| 51 | + |
| 52 | +# Build JavaScript bindings (requires emscripten) |
| 53 | +make -f Makefile_js build |
| 54 | + |
| 55 | +# Alternative: Install from npm |
| 56 | +npm install ffish |
| 57 | +``` |
| 58 | + |
| 59 | +## Testing & Validation |
| 60 | + |
| 61 | +All test commands below assume the current directory is `src/`. |
| 62 | + |
| 63 | +### Core Engine Tests |
| 64 | +```bash |
| 65 | +# Basic functionality test |
| 66 | +./stockfish bench |
| 67 | + |
| 68 | +# Variant-specific benchmarks |
| 69 | +./stockfish bench xiangqi |
| 70 | +./stockfish bench shogi |
| 71 | +./stockfish bench capablanca |
| 72 | + |
| 73 | +# Validate variants configuration |
| 74 | +./stockfish check variants.ini |
| 75 | +``` |
| 76 | + |
| 77 | +### Comprehensive Test Suite |
| 78 | +```bash |
| 79 | +# Protocol compliance tests |
| 80 | +../tests/protocol.sh |
| 81 | + |
| 82 | +# Move generation validation |
| 83 | +../tests/perft.sh all |
| 84 | +../tests/perft.sh chess # Chess only |
| 85 | +../tests/perft.sh largeboard # Large board variants only |
| 86 | + |
| 87 | +# Regression testing |
| 88 | +../tests/regression.sh |
| 89 | + |
| 90 | +# Reproducible search test |
| 91 | +../tests/reprosearch.sh |
| 92 | + |
| 93 | +# Build signature verification |
| 94 | +../tests/signature.sh |
| 95 | +``` |
| 96 | + |
| 97 | + |
| 98 | +## Project Architecture |
| 99 | + |
| 100 | +### Directory Structure |
| 101 | +``` |
| 102 | +src/ # Core C++ engine source |
| 103 | +tests/ # Test scripts and data |
| 104 | +.github/workflows/ # CI/CD configurations |
| 105 | +``` |
| 106 | + |
| 107 | +### Configuration Files |
| 108 | +- **`src/variants.ini`**: Defines examples for configuration of chess variants |
| 109 | +- **`setup.py`**: Python package build configuration |
| 110 | +- **`tests/js/package.json`**: JavaScript bindings configuration |
| 111 | + |
| 112 | +### Key Source Files in `src/` |
| 113 | +- **`variant.h`**: Variant rule properties |
| 114 | +- **`variant.cpp`**: Variant-specific game rules |
| 115 | +- **`variant.ini`**: Variant rule configuration examples and documentation of variant properties |
| 116 | +- **`position.h`**: Position representation |
| 117 | +- **`position.cpp`**: Board logic |
| 118 | +- **`movegen.cpp`**: Move generation logic |
| 119 | +- **`parser.cpp`**: Variant rule configuration parsing |
| 120 | +- **`piece.cpp`**: Piece type definitions and behavior |
| 121 | +- **`pyffish.cpp`**: Python bindings |
| 122 | +- **`ffishjs.cpp`**: JavaScript bindings |
| 123 | + |
| 124 | +## Continuous Integration |
| 125 | + |
| 126 | +### GitHub Actions Workflows |
| 127 | +- **`fairy.yml`**: Core engine testing (perft, protocols, variants) |
| 128 | +- **`stockfish.yml`**: Standard Stockfish compatibility tests |
| 129 | +- **`release.yml`**: Binary releases for multiple platforms |
| 130 | +- **`wheels.yml`**: Python package builds |
| 131 | +- **`ffishjs.yml`**: JavaScript binding builds |
| 132 | + |
| 133 | +## Common Development Patterns |
| 134 | + |
| 135 | +### Making Engine Changes |
| 136 | +1. **Always test basic functionality:** `./stockfish bench` after changes |
| 137 | +2. **Validate variant compatibility:** `./stockfish check variants.ini` |
| 138 | +3. **Run relevant tests:** `../tests/perft.sh all` for move generation changes |
| 139 | + |
| 140 | +### Adding New Configurable Variants |
| 141 | +1. **Edit `src/variants.ini`**: Add variant configuration |
| 142 | +2. **Test parsing:** `./stockfish check variants.ini` |
| 143 | + |
| 144 | +### Relevant websites for researching chess variant rules |
| 145 | +- [Chess Variants on Wikipedia](https://en.wikipedia.org/wiki/List_of_chess_variants) |
| 146 | +- [Chess Variants Wiki](https://www.chessvariants.com/) |
| 147 | +- [Variant Chess on BoardGameGeek](https://boardgamegeek.com/boardgamefamily/4024/traditional-games-chess) |
| 148 | +- [PyChess Variants](https://www.pychess.org/variants) |
| 149 | +- [Ludii](https://ludii.games/library.php) |
| 150 | +- [Lichess.org Variants](https://lichess.org/variant) |
| 151 | +- [Greenchess](https://greenchess.net/variants.php) |
| 152 | +- [Chess Variants on Chess.com](https://www.chess.com/variants) |
| 153 | + |
| 154 | +### Development Best Practices |
| 155 | +* Make sure to only stage and commit changes that were changed as part of the task, do not simply add all changes. |
| 156 | +* Keep changes minimal and focused on the task at hand. |
| 157 | +* After applying changes make sure that all places related to the task have been identified. |
| 158 | +* Stay consistent with the existing code style and conventions. |
0 commit comments