Ludax: A GPU-Accelerated Domain Specific Language for Board Games

Graham Todd, Alexander Padula, Dennis J. N. J. Soemers, Julian Togelius · DOI

Introduction

Ludax is a novel domain-specific language (DSL) designed to allow researchers to define board games in a human-readable format and automatically compile them into high-performance, GPU-accelerated JAX code. By bridging the gap between flexible but slow game description languages and fast but rigid hand-optimized libraries, Ludax enables rapid experimentation and massive-scale reinforcement learning across a wide variety of games.

The Generality vs. Speed Bottleneck

In AI research, games serve as a primary "proving ground." However, researchers often face a frustrating trade-off. On one hand, Game Description Languages (GDLs) like Ludii can represent thousands of different games using a simple syntax but are CPU-bound and relatively slow. On the other hand, hardware-accelerated libraries like PGX offer incredible throughput on GPUs but require every game to be hand-coded and optimized in JAX—a task that is difficult and time-consuming for non-experts.

Ludax addresses this "generality vs. speed" bottleneck. It provides a system where a researcher can write down the rules of a new, unexplored game in a few lines of text and immediately have a GPU-ready environment capable of generating millions of moves per second for deep reinforcement learning (RL).

Methods: The Ludax Compilation Pipeline

Ludax is built on a "ludemic" philosophy, breaking game rules into high-level, understandable components: equipment, setup, play mechanics, and end conditions.

The compilation process involves several key stages:

  1. Parsing: Ludax uses the Lark Python library to transform DSL text into a grammar tree.
  2. Atomic Mapping: The "leaves" of this tree—basic operations like checking if a cell is empty—are mapped to atomic functions written in JAX.
  3. Bottom-Up Composition: These JAX functions are dynamically composed to form higher-level logic, resulting in a single, compiled step function for the entire game environment.
  4. Optimizations:
  5. Precomputation: Static properties, such as board indices for winning lines, are calculated during compilation to turn complex search logic into simple matrix lookups.
  6. Dynamic State: The compiler extracts only necessary state attributes, reducing memory footprint.
  7. Incremental Updates: For games like Hex, Ludax uses efficient union-find-style logic to update board connectivity.

Benchmarking and Evaluation

The researchers evaluated Ludax using a benchmark suite of eight board games, including Tic-Tac-Toe, Connect Four, Hex, Reversi, Gomoku, Pente, Yavalath, and Yavalax. These were compared against Ludii (CPU-based) and PGX (hand-optimized JAX).

Throughput comparison of Ludax against Ludii and PGX across various board games.

Key Results

Massive Speedups

Ludax consistently outperformed Ludii, even when Ludii utilized 32 CPU threads. In the case of Pente, Ludax was approximately 55x faster. At small batch sizes, Ludax's throughput is nearly identical to hand-optimized PGX implementations. While PGX maintains a lead at very large batch sizes due to aggressive game-specific memory optimizations, Ludax remains within an order of magnitude.

RL Parity

To demonstrate practical utility, the authors conducted a full RL training run using an AlphaZero-style setup on Reversi. The Ludax-based agent achieved the same win rate and learning stability as the PGX-based agent, completing 57 million frames of training in about 3 hours on a single A100 GPU.

Mean and variance of win rates for Ludax and PGX agents during AlphaZero training on Reversi.

Key Insights

  • Generality and Speed: By treating game rules as a composition of JAX primitives, high-throughput environments can be automated without manual "bespoke" engineering.
  • Unified Action Space: Ludax enforces a "place-based" action space, providing a consistent interface that facilitates knowledge transfer between different games.
  • JAX as a Compiler Target: JAX is leveraged not just for math, but as a powerful backend for domain-specific compilers, utilizing JIT compilation and vectorization for game simulation.

Limitations and Future Work

Currently, Ludax supports two-player, perfect-information games where pieces are placed on a board. It does not yet support piece movement (e.g., Chess), hidden information, or stochastic elements. Future work aims to expand the DSL to support these features and explore "automated game design," where AI searches the DSL space to discover new, balanced games.

Summary updated

BibTeX
@inproceedings{todd2025ludax,
  author = {Graham Todd and Alexander Padula and Dennis J. N. J. Soemers and Julian Togelius},
  title = {{Ludax: A GPU-Accelerated Domain Specific Language for Board Games}},
  booktitle = {SEA @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=FNryl3qXOm},
}
Figure