Skip to content
HN On Hacker News ↗

Exponential Behavior in Magic: the Gathering

▲ 118 points • 78 comments • by neuwirth • 6d ago • HN discussion ↗

Pangram verdict · v3.3

We believe that this text is a mix of AI and human-written content.

23 %

AI likelihood · overall

Mixed
77% human-written 23% AI-generated
SEGMENTS · HUMAN 6 of 22
SEGMENTS · AI 16 of 22
WORD COUNT 1,676
PEAK AI % 100% · §3
Analyzed
Nov 19
backend: pangram/v3.3
Segments scanned
22 windows
avg 76 words each
Distribution
77 / 23%
human / AI fraction
Verdict
Mixed
Pangram v3.3

Article text · 1,676 words · 22 segments analyzed

Human AI-generated
§1 Human · 0%

I have been fascinated with Magic: The Gathering for years, not only as a remarkably fun and strategically deep game, but also as a mathematical and computational space. The game is remarkably complex, even Turing complete, with intricate keywords and a daunting amount of mechanicsa, presenting an immense computational challenge for making the game run on a computer, let alone machine-playable. There are multiple existing software implementations of Magic; Arena is the most prevalent, developed by Wizards themselves, but there are numerous issues: the card catalog is notoriously incomplete, missing cards from the majority of the game’s history; the matchmaking methodology, particularly for ranked play, is absolutely horrificb, and the performance of the game is quite poor, particularly when there is a lot on the stack. MTGO resolves the card catalog issue, but introduces issues of its own, including lack of adoption, a rather outdated and difficult to use interface, and so on. Meanwhile, Forge, an independent implementation, is promising at first glance — but the AI play is quite poorc, multiplayer is quite buggy and not truly supported, the interface is unintuitive, and the performance is still not ideal, even if improved over Arena. Building an MTG Engine I began theorizing methods to improve AI play of Magic as early as 2024 but did not begin any implementation work on this until mid 2026; I first evaluated Forge and then decided that it was not feasible to get Forge up to a level of performance such that it could serve as an experimentation environment for RL on Magic itself, and thus decided to implement my own rules engine, Arcana. I figured that I could also design with multiplayer in mind from day one as a nice bonus and motivator. One of the sources of my fascination with Magic, and, indeed, one of the reasons that a truly performant and complete software implementation of the game has yet to be achieved, is the nature of abilities in the game. Abilities in Magic can compound exponentially, and the amount of different possible interactions that can occur when any ability is triggered leads to a situation where although there may not be an unfeasible amount of state in principle, the amount of checks that are required to ensure that no further side effects must be put on the stack also grows exponentially, and as we all know, exponential behavior is an enemy of us mere mortal computer scientists. My fascination with the exponential behavior of Magic came back to bite me in an unexpected way. My Irritable Scute Swarm Deck One of my favorite decks I ever devised was very simple in mechanicism and brutal in computational complexity. It revolves around a notorious card: Scute Swarm. To explain how this deck worked, we need a bit of background on the internals of Magic. An introduction to Magic’s mechanics The core quantity of Magic: The Gathering is life; it can be thought of as the player’s score, or an encapsulation of how well the player is doing. Each player begins with 20 life, and the primary way to win the game is to reduce the opponent’s life score to 0 (or below) before your own life score is reduced as such. There are different types of cards that can be used, and on any given turn, a player may use the resources granted to them by lands, the type of card that forms a basic currency in the game, to deploy whatever they wish within the game’s limitations and rules. Perhaps the most important type of card is a creature. These are equivalent to the prototypical card in most trading card games, like Pokemon; they can attack the opponent and defend from the opponent’s attacks. Scute Swarm is one example of a creature. There are also tokens, which are special cards that are the result of an ability of a different card rather than a card that you play. One might use a card to earn a token, but one would not have a token in the deck that they build, and they would not ever have a token in their hand so to speak. The actual mechanics here are a bit complicated, but the big picture is that tokens come into existence as a result of some ability and not from being in the player’s hand or deck outright. Scute Swarm is perhaps the most notorious example of a Magic card that exhibits exponential behavior. It has the ability, when a new land is deployed, to double the amount of copies of itself that exist. In practice, this is usually countered early, as Magic allows for many different waysd to avoid the exponential being realized (which, if substantially realized, will lead to victory for the person who played Scute Swarm practically invariably). If you combined this, I realized, with cards that produce life-gain whenever a new creature enters the battlefield, then one would have exponentially growing life. To make this even worse, one could play an artifact that doubles the amount of tokens that are created whenever any token is created, and throw in something to persistently double the amount of life gained.

§2 Human · 0%

Seems like quite the loophole, eh?

§3 AI · 100%

For the arithmetic, the sixth land matters.

§4 AI · 100%

Below six lands a Scute makes an ordinary 1/1 Insect. With six or more when the ability resolves, it makes a copy with the same landfall ability. Give each land’s triggers time to resolve before the next land comes down and every new copy gets to help with the next batch.e Suppose Soul Warden and Essence Warden are both in play. Each gives you one life for each new Scute. With a life-gain doubler that’s four life per arrival, and with a token doubler each existing Scute makes two new ones. Here’s what eight land drops would buy you under those assumptions. # One Scute, two Wardens, one token doubler, one life-gain doubler.

§5 AI · 100%

# Six or more lands are present.

§6 AI · 100%

scutes = 1 life_gained = 0 for _ in range(8): new_scutes = 2 * scutes scutes += new_scutes life_gained += 4 * new_scutes # 6,561 Scutes; 26,240 life gained.

§7 Human · 0%

This is totally egregious!

§8 Human · 0%

Considering that a player begins with 20 life in Magic, and life gains are usually modest if present at all, a change of 3 orders of magnitude warrants that notoriety that Scute Swarm has. For comparison, I think (playing decks outside of this one) that, on paper cards, the highest life total I have achieved in a game is around 150. The Scute curve is something we can work out on paper, but Arcana doesn’t yet support scute swarm (deliberately, I might add). It was the purple curve that got me into trouble. Now, who is this Liliana in the above plot? Liliana takes over Planeswalkers are, in a way, the heroes of Magic. They usually have multiple abilities, the most expensive of which (usually positioned at the bottom as the last one) we tend to call the “ultimate” — simply put, if you are playing against an opponent with a Planeswalker, you’d best ensure they don’t trigger that ability. In some cases, the ultimate can create a special type of cardf called an emblem. Emblems are particularly concerning for you if your opponent has the opportunity to procure one, and particularly advantageous if you have the ability to use one, chiefly because they persist even if the Planeswalker is removed from play. An ability that an emblem provides will be in effect for the remainder of the game, typically leading to devastating and, importantly, compounding consequences for the opponent. Liliana, the Last Hope is one such planeswalker. Her ultimate happens to create quite the dire situation not only for the opponent, but also for those who are interested in implementing Magic in software. When her ultimate ability resolves, the resulting emblem ensures that more and more zombie tokens are deployed onto the battlefield in a matter not too unlike that of Scute Swarm. Unfortunately for us as implementers, and for those who play against Liliana as losers, the amount of zombies that are deployed grows exponentially.

§9 AI · 100%

What is unlike Scute Swarm is that clearing away the Zombies leaves the emblem intact and able to rebuild the army, whereas removing every Scute Swarm removes the source of its growth. Let’s formalize what happens.

§10 AI · 100%

At the beginning of each of your end steps (the last part of a player’s turn), the emblem triggers.

§11 AI · 100%

When that ability resolves, it counts the Zombies you control and creates that many more, plus two.

§12 AI · 100%

With six Zombies already on the battlefield, you get eight new ones, leaving fourteen. Let ZnZ_n be the number of Zombies after nn resolutions of the emblem’s ability.

§13 AI · 100%

Start with no Zombies (Z0=0Z_0=0) and one emblem, and suppose nothing else adds or removes Zombies or changes how many tokens are created.

§14 AI · 100%

Each resolution then gives us: Zn+1=Zn⏟already there+(Zn+2)⏟new arrivals=2Zn+2.

§15 Human · 0%

Z_{n+1} =\underbrace{Z_n}_{\text{already there}} +\underbrace{(Z_n+2)}_{\text{new arrivals}} =2Z_n+2.

§16 AI · 100%

The first few populations are 0,2,6,14,30,62,…0,2,6,14,30,62,\ldots. After nn resolutions, that gives Zn=2n+1−2Z_n=2^{n+1}-2. Crucially, the army will always restart: even if every Zombie is destroyedg, the next resolution produces two more.

§17 AI · 75%

This forms Liliana’s purple curve in the comparison above: 510 Zombies after eight resolutions.

§18 AI · 100%

That plot counts growth events along the horizontal axis: one emblem resolution for Liliana, or one land entry for Scute Swarm.

§19 Human · 21%

Arcana implements that counting rule directly: let zombies = script::count_matching(state, &filter, trig.controller); let x = 2 + zombies; // Token definition omitted: a 2/2 black Zombie.

§20 AI · 100%

let mut effects = Vec::new(); for _ in 0..x { effects.push(Effect::CreateToken { controller: trig.controller, token: token.clone(), }); } Here, x counts the new arrivals, and the loop produces a separate CreateToken effect for every one of them. The engine then has to process all those arrivals, including the rules checks and any abilities they set off. As the army grows, so does the work required to resolve the emblem’s ability.

§21 AI · 100%

What one engine step costs Let’s step back for a second.

§22 AI · 100%

I was trying to decide which gaps in Arcana’s rules to fix next.