Exponential Behavior in Magic: The Gathering
Building a custom Magic: The Gathering rules engine exposed severe computational bottlenecks caused by cards with exponential token generation and combinatorial combat choices.
read it A fascinating technical deep dive into the algorithmic nightmares of implementing complex rule-based game engines.
summary
The author built a custom Magic: The Gathering rules engine called Arcana to run AI experiments, but encountered major performance failures. Specific cards like Liliana created exponential token growth, causing single engine steps to stall for over 35 seconds. Furthermore, combinatorial explosions in attack choices breached action budgets, preventing the AI from executing valid winning moves. The author highlights how naive state-scanning loops compound these performance issues and outlines necessary architectural fixes.
key points
- Liliana's emblem triggered exponential Zombie token growth, scaling single engine resolution steps up to 35 seconds.
- Combinatorial explosions in combat declarations saturated the 1,024-entry action budget, locking out all-in attacks.
- Naive state-scanning loops check every permanent for keywords like evolve repeatedly, resulting in severe performance degradation.
who should read it
Systems programmers, game developers, and engineers interested in complex rule engines and computational complexity.
discussion warm
consensus
Commenters enthusiastically discussed a broader open-source renaissance of alternative MTG engines being built in Rust, Go, and WASM.
There's a bit of an open source Magic renaissance going on lately, which I find really cool.
Forge has been around forever, but we've managed to get it running in the browser via WASM with Manabrew [1]. I'm one of the maintainers, and we're mostly building it because we wanted a nicer way to play Commander with friends.
Meanwhile, Phase and Ironsmith are working on new engines in Rust, Gorge is building one in Go alongside a bot and cross-engine testing tools, and people are starting to collaborate across projects.
Magic is such a ridiculously difficult game to implement that I think it's …
It provides valuable context on other independent modern open-source MTG engine projects currently in development.
Generated by an LLM from the article and thread. Check the sources before relying on it.