Grimoire for everyone

Every card in our engine is a short text written in a language called Grimoire. You do not need to be a programmer to read it. If you know how Magic works, you already know most of the ideas; Grimoire just writes them down without ambiguity.

Why a card language?

A Magic card is already a tiny program. Its rules text says what happens, in what order, and under which conditions, and some cards go further: they change the rules for every other card on the table. English is wonderful for players, but it leaves room for interpretation, and that is why the Comprehensive Rules run to hundreds of pages.

A computer cannot interpret. So instead of writing special code for each of the 540 cards of the Vintage Cube, we wrote a small language in which each card is described, once, as a precise text. The engine reads these texts and plays the cards. When a card behaves strangely, we fix one short file, not a tangle of special cases.

Grimoire is built on three ideas, each of which you already know from the game.

Idea 1: an effect is a list of operations

“Deal 3 damage”, “draw a card”, “put that creature into its owner's graveyard”: these are operations, the basic actions of the game. A spell is a short recipe of operations, read from left to right, separated by semicolons. Here is the most famous red card, written in Grimoire:

card "Lightning Bolt" : {R} instant {
      spell => t0 ← target(any_target) ; damage_to(t0, 3)
    }

Step by step:

That is the whole card. Nothing about the stack, priority or responses appears here: those are rules of the game, and the engine applies them to every card the same way.

Idea 2: operations can be intercepted

The interesting cards in Magic are the ones that say “if … would happen, … instead”. The rules call these replacement effects. In Grimoire, every operation can be intercepted on its way: just before the action happens, the cards on the table get a chance to say “not like that, like this”.

Think of an operation as a letter on its way to be delivered. A replacement effect is a clerk at the post office who opens certain letters and swaps the contents before they arrive. Here is Hullbreacher, a blue creature from the cube that punishes opponents who draw extra cards:

Flash. If an opponent would draw a card except the first one they draw in each of their draw steps, instead you create a Treasure token.
card "Hullbreacher" : {2}{U} creature Merfolk Pirate 3/2 {
      flash
      replace draw1(p) if opponent(p) ∧ ¬(step = draw ∧ active = p ∧ drawn_this_step(p) = 0)
        => create(token { colorless artifact Treasure { act tap(this) ; sacrifice(this) => add_mana_any(1) } }, you)
    }

Reading it line by line:

The same mechanism covers the “can't” cards (“your opponents can't gain life”), which simply refuse the operation, and the triggered abilities (“whenever a creature dies…”), which watch an operation happen and then react, without changing it.

Idea 3: continuous effects are modifiers, applied in layers

Some cards do not do anything; they change what other things are. “Creatures you control get +1/+1.” “Nonbasic lands are Mountains.” The rules apply all these effects in seven layers, in a fixed order: first copies, then control, text, types, colours, abilities, and finally power and toughness.

In Grimoire, such an effect is a modifier: a pair of glasses placed in front of the objects it affects. The printed card never changes; whenever anyone looks at it, they look through every pair of glasses in turn, in the order of the layers. Remove the enchantment, and its glasses are gone: there is nothing to undo. Blood Moon is a single line:

card "Blood Moon" : {2}{R} enchantment {
      static L4 (land ∩ ¬basic) : set_subtypes(Mountain)
    }

Now Humility, an enchantment that famously confuses even experienced judges:

card "Humility" : {2}{W}{W} enchantment {
      static (L6 creature : remove_all ; L7b creature : set_pt(1, 1))
    }

One ability, two pairs of glasses: in layer 6 (abilities), creatures lose all their abilities; in layer 7b (setting power and toughness), they become 1/1. Because each part sits in its own layer, the classic puzzles sort themselves out. Put Humility next to Opalescence, which turns enchantments into creatures, and the engine applies the type change first (layer 4), then the loss of abilities, then the 1/1, settling ties with timestamps, exactly as the Comprehensive Rules prescribe. Blood Moon and Humility are not part of the current Vintage Cube, but the engine knows them as test cards for precisely this reason.

The layers even look after one subtle rule on their own. When one effect would change whether another effect applies (Blood Moon removing the ability of a land that itself changes other lands, for example), the rules say the first must be applied before the second, whatever their timestamps. Because Grimoire knows what every modifier reads, it can discover these dependencies instead of being told.

The small core underneath: G₀

Card authors write with a comfortable vocabulary of about 300 words: damage_to, create, draw1, set_subtypes and so on. But all of these words are defined in terms of a tiny core, which we call G₀, made of just eight operations:

OperationIn plain words
getlook at something (a card's power, a player's life total), through all the modifiers in place
setchange something (move a card, lose life, tap a permanent); this is what replacement effects intercept
newbring a new object into existence, like a token, or a card that changed zones
chooseask a player to choose, or let chance decide (a shuffle, a coin flip)
attachput a rule-bending effect in place on an object, a player or the game
detachtake one away
logask about the past: “how many cards has this player drawn this turn?”
failstop, because something cannot be done

In this view there are only two places where a card can bend the rules: when something is looked at (that is a continuous effect, applied in layers) and when something is changed (that is a replacement, a prohibition, or a trigger that watches). Drawing a card, destroying a creature, casting with flashback or kicker: all of them turn out to be definitions written with these eight operations.

Why does this matter to a player? Because a small core can be checked. We keep two versions of the language: the precise but slow one, G₀, which serves as the reference, and the fast one that actually runs when you play. Both are run on positions taken from random games and compared, millions of times over, and any disagreement must be traced to a rule of the game before it is accepted. That is how we gain confidence that 540 very different cards follow one consistent set of rules.

One last image. An effect attached to a creature lives on that creature. When the creature leaves the battlefield, the rules say it becomes a new object with no memory of its past; in Grimoire, the old object and everything attached to it simply disappear together. No clean-up code, no forgotten “until end of turn”: the game's own logic does the housekeeping.

Want the details?

The full description of Grimoire and G₀, with its formal semantics and the evaluation of the engine, is in our research articles.