The engine
A rules engine for Magic: The Gathering, written in Rust, that plays all 540 cards of the Magic Online Vintage Cube. It is fast enough to play millions of games for training, and small enough to run inside your browser.
What it does
The engine knows the whole game, not a simplified version of it. The card pool is the Magic Online Vintage Cube list of October 2026: power, fast mana, reanimation, planeswalkers, double-faced cards, sagas, vehicles, alternative costs and all the rest. Every one of the 540 cards can be drafted and played.
- The stack. Spells and abilities go on the stack, players receive priority in turn, and responses resolve last in, first out.
- Continuous effects in layers. Effects that change what a permanent is (copy, control, text, type, colour, abilities, power and toughness) are applied in the seven layers of rule 613, with timestamps and dependencies. Blood Moon against Urborg, Humility against Opalescence: the engine works them out the way the Comprehensive Rules say.
- Replacement and prevention effects. “If … would …, instead …” effects (rules 614 to 616), including the choice of which one applies first when several want the same event.
- Triggers and state-based actions. Triggered abilities wait for the next time a player would receive priority, then go on the stack in the order their controllers choose; state-based actions are checked first.
Deterministic by design
Given the same random seed and the same decisions, the engine always produces the same game, event for event. A game can therefore be stored as a seed, two decks and a list of choices, and replayed exactly. This makes bugs reproducible, lets search algorithms explore “what if” branches cheaply, and keeps recorded games tiny.
Fast
A state transition (one step of the game: a player choice, a spell resolving, a phase changing) takes between a quarter of a microsecond and about 1.6 microseconds on a laptop processor. A typical game has around 650 transitions. On a twelve-core machine the engine plays more than fifty thousand random games per second. That speed is what makes search and self-play possible: an AI that thinks by simulating thousands of continuations needs an engine that is almost free to run.
Tested three ways
Rules scenarios
More than two thousand small, executable scenarios each set up a board, perform actions and check the outcome against the Comprehensive Rules: a burn spell in response to a pump spell, a creature that changes zones and becomes a new object, two replacement effects competing for one event. They run on every change to the engine.
Fuzzing
Random players play huge numbers of games with random Vintage Cube decks while the engine checks invariants after every step: no card in two places, no impossible mana pool, no game that never ends, every recorded game replaying identically. Fingerprints of these runs detect any unintended change in behaviour.
A reference semantics
Cards are written in Grimoire, a small language with a precise meaning defined by a minimal core of eight operations. An independent interpreter of that core is compared with the fast engine on states drawn from random games: more than eight million comparisons so far, every divergence traced to a rule of the game before it is accepted. The details are in the research articles.
In your browser
The same Rust code is compiled to WebAssembly and runs in a background thread of your browser, together with the draft bots and the trained networks. Nothing is sent to a server while you play: the page you load is the whole game.