Luna is a UCI-compatible chess engine written entirely in Rust, combining classical bitboard-based alpha-beta search with a quantized NNUE (Efficiently Updatable Neural Network) evaluation for deep positional understanding.
Board & move generation
- Bitboard board representation
- Fancy magic bitboards for sliding-piece (bishop/rook/queen) attack generation, precomputed once at startup
- Zobrist hashing with deterministic ChaCha20-based key generation
- Static Exchange Evaluation (SEE) for capture ordering and pruning
Search
- Lazy SMP multi-threading (
ThreadsUCI option): independent iterative-deepening search per thread over a lock-free shared transposition table and shared history/capture-history tables - Negamax with Principal Variation Search (PVS) and iterative deepening
- Progressive aspiration windows
- Transposition table with generational aging
- Reverse Futility Pruning, Futility Pruning, Null Move Pruning (with a zugzwang guard), Mate Distance Pruning
- Late Move Reductions (LMR)
- Check extensions and passed-pawn push extensions
- Quiescence search with SEE-based and delta pruning
- Move ordering: TT move, SEE, MVV-LVA, killer moves, history heuristic (with a self-limiting "gravity" update and malus for non-cutoff moves), counter-move heuristic, capture history
- winc/binc-aware time management
Evaluation
- NNUE ((768 inputs × 4 king-buckets, horizontally mirrored) × 2 perspectives → 1024 hidden → 1 output, SCReLU activation), with an incrementally-updated accumulator
- The default network is baked directly into the binary at compile time — no external file needed to run
- SIMD-accelerated inference: AVX2 on x86_64, NEON on AArch64, with a portable scalar fallback
- Classical piece-square-table evaluation as an automatic fallback if no usable network is available at all
- Endgame conversion aids (passed-pawn bonus, king mop-up bonus, no-progress score decay)
Protocol & compatibility
- Full UCI protocol support, tested with lichess-bot
- Runs on Windows and Linux (x86_64), and on Linux ARM64 (tested on Oracle Cloud Ampere instances and Android)
Requires the Rust toolchain (stable channel).
git clone https://github.com/Spunc595/Luna-Chess-Engine.git
cd Luna-Chess-Engine
cargo build --releaseThe optimized binary is produced at target/release/luna (luna.exe on Windows).
About the releases: each release contains the source code and an Android ARM64 build. From 4.0.0, it also contains a Linux ARM64 build and a Windows x86_64 build. For every other platform, compile it yourself with cargo build --release as above.
Release files are named luna-v<version>-<platform>-<arch>, e.g. luna-v3.1.5-android-arm64 (and, from 4.0.0, luna-v4.0.0-linux-arm64 and luna-v4.0.0-windows-x86_64).
Windows builds and CPU requirements. luna-v4.0.0-windows-x86_64.exe was built for the x86-64-v2 microarchitecture level (SSE4.1, SSE4.2, POPCNT, CMPXCHG16B) — evidence from disassembly (POPCNT/SSE4.1/SSE4.2 present, no LZCNT/BMI1/BMI2, AVX2 confined to the runtime-gated NNUE kernel); not dynamically verified with Intel SDE. luna-v4.1.0-windows-x86_64.exe was built by mistake for the build machine's own CPU (-C target-cpu=native): it requires POPCNT, LZCNT, BMI1/BMI2 and AVX2 unconditionally (roughly Intel Haswell, 2013, or AMD Excavator, 2015, or newer) and fails to start with an illegal-instruction error on older CPUs. luna-v4.1.0-windows-x86_64-baseline.exe, added to the same release as an extra asset, is the same v4.1.0 source built with no target-cpu override (RUSTFLAGS=""); it contains SSE3, CMPXCHG16B and FXSR (part of the x86_64-pc-windows-msvc target's own default feature set, not something enabled by this project) but no POPCNT, LZCNT or BMI1/BMI2, and no AVX2 outside the NNUE kernel's own runtime check — not dynamically tested on a CPU without AVX2.
If you compile it yourself, note that on Windows cargo build --release currently uses target-cpu=native (see .cargo/config.toml); set RUSTFLAGS="" for a portable build (a fix to make this the default is planned for a future release). The AVX2 NNUE kernel still activates at runtime on CPUs that support it, regardless of which target you build for — see the NNUE network section below.
Luna's default network (resources/net.bin) is committed to this repository and baked directly into the executable at compile time — a plain cargo build --release produces a fully self-contained binary, no extra download or file placement needed. This was a deliberate choice for reliability: some environments (e.g. Android tournament GUIs) only import a single engine file with no guarantee a companion file ends up next to it, and a missing/misplaced external network used to silently degrade Luna to its much weaker classical evaluation.
An external luna.nnue file placed next to the executable, if present and valid, still takes priority over the embedded network — useful for trying a different/updated net without recompiling. If it is missing or fails to parse, Luna falls back to the network embedded in the binary, not directly to classical evaluation. Classical PST evaluation is only reached if the embedded network itself fails to parse too (wrong file size, or output weights outside the SIMD-safe range checked in src/nnue.rs) or if the UseNNUE UCI option is explicitly set to false (default true) — Luna never fails to start either way. The embedded-network parse failure case cannot happen in the official prebuilt binaries (the shipped net.bin is fixed and already validated); it can only happen in a from-source build with an incompatible net.bin.
Which network is actually inside this binary: as of v4.0.0, resources/net.bin is trained by the author, with his own training pipeline, on public Leela Chess Zero data (1 billion positions — about 914 million unique by exact board and side-to-move match, 91.4%; 910.5 million if mirror images are merged — 8 epochs, king-bucketed 768x4 HalfKA architecture, trained with bullet) — see the luna-nnue repository for the full provenance, compliance declaration, and measurements. Through v3.1.7, the embedded network was akimbo's own (MIT-licensed); it was replaced once the self-trained network was measured, in the engine's own search, to be statistically indistinguishable from akimbo's (+0.3 +/- 10.7 Elo, 2,000 games, 95% CI) — the architecture and the AVX2/NEON inference code are still akimbo's (see Acknowledgments below), only the trained weights changed.
Luna speaks the UCI protocol and works with any compliant GUI or wrapper (Arena, CuteChess, lichess-bot, etc.). Point your GUI at the compiled binary and it's ready to play.
| Path | Contents |
|---|---|
src/ |
Engine core: board representation, move generation, search, NNUE, transposition table, opening book, UCI loop |
tests/ |
Integration tests (NNUE incremental-update correctness) |
examples/ |
Standalone diagnostic tools (perft, NNUE sanity checks) |
tuner/, book_converter/ |
Auxiliary development tools |
Luna's search and move-ordering heuristics draw on techniques and ideas documented across the open-source computer chess community, including Stockfish, Reckless, and Viridithas.
Luna's AVX2 NNUE kernel is ported from akimbo by Jamie Whiting (MIT; the notice below applies). The NEON kernel for AArch64 is a port of the same scheme, written by the author with AI assistance. Earlier versions of Luna, before the akimbo network, used SIMD inference kernels contributed by Jim Ablett on the TalkChess forum, who also built and shared cross-platform release binaries for the engine.
As of v4.0.0, the embedded network is trained with bullet by Jamie Whiting. See the luna-nnue repository for the training data's own provenance and licensing.
Training data for the v4.0.0 network: Leela Chess Zero self-play games (runs T77 and T79), as filtered and converted to bullet's binary format by Linrock (Hugging Face: linrock/bullet-training-data). The Lc0 project announced in June 2021 that its training data is released under the Open Database License 1.0 and the Database Contents License 1.0 (lczero.org/blog/2021/06/the-importance-of-open-data). Contains information from the Leela Chess Zero training data, available under the ODbL 1.0.
Luna's default NNUE architecture (the king-bucketed, horizontally-mirrored HalfKA scheme, and the AVX2/NEON inference kernels) is ported from akimbo by Jamie Whiting, used under the MIT License. As of v4.0.0, resources/net.bin is trained by the author, with his own training pipeline, on public Leela Chess Zero data with this architecture (see above), not akimbo's own network file; the MIT license below covers the architecture and code ported from akimbo, not the trained weights:
Copyright (c) 2023 Jamie Whiting
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Luna is licensed under the GNU General Public License v3.0 or later (see the LICENSE file for full details). The NNUE architecture and AVX2 kernel ported from akimbo (see Acknowledgments above) are MIT-licensed, which is compatible with the GPLv3. Several search techniques (noted inline in the source, e.g. in search.rs/tt.rs/movegen.rs) follow published ideas and formulas from Stockfish, Reckless and Viridithas, independently implemented rather than copied — the akimbo port is the only ported third-party source code currently in the engine.
Through v3.1.7, the embedded NNUE network (resources/net.bin) was akimbo's own, MIT-licensed. As of v4.0.0 the network's trained weights are Luna's own (the architecture and inference code ported from akimbo remain MIT-licensed) — see the Acknowledgments section above and the luna-nnue repository for the training data's provenance and licensing.
Luna is developed by Daniele Marpino, with special thanks to my son Alessandro Marpino for his invaluable help in stress-testing and refining the engine.