Case study · Python · data reconciliation · Excel

The Giants' Dilemma

A local tournament invented two rules for forming teams. One is trivial. The other forces you to search 159 preconstructed decks card by card. This is how it got solved, told without assuming you know how to play Magic.

Role  Sole engineer Stack  Python, pandas, openpyxl, pytest Sources  Scryfall, MTGJSON Output  Interactive .xlsx
44
Precon sets
159
Decks
1,055
Commanders
551
Partner pairs
21,699
Legal teams

Context

The bare minimum you need to know

Magic: The Gathering is a complex card game with many ways to play it. So that the dilemma this tournament faced actually lands, let me define a few things as plainly as possible.

The game is built on a system of colors: White, Blue, Black, Red and Green. From here on I will use their letters — the U is for blUe, because Black already took the B:

W White U Blue B Black R Red G Green C Colorless

Colors represent different kinds of magic and creatures, and at the same time they work as a constraint.

That last one is not a sixth color: it is the absence of color. Some cards belong to none of the five, and I will mark them with a C. Worth holding onto, because it matters later: a colorless commander can join any colored deck, even a five-color one.

What it cannot do is pair with another colorless commander. The tournament treats the absence of color as an identity in its own right, so two colorless commanders share it and the team is out. That is 34 combinations that look valid at first glance and are not.

Enter Commander, a way to play where you pick a "commander" that represents your deck and defines which colors you have access to. For example: if your commander is "Mooriel, the Warrior Cow" and she is white and black, you may only use cards of those two colors. It closes off the other three. On top of that you cannot repeat cards — one copy of each, basic lands aside. It is a constraint that invites creativity.

The format got so popular partly thanks to preconstructed decks: decks designed to be played straight out of the box, unchanged.

The tournament

Two rules: one trivial, one brutal

Here is where it gets complicated. The tournament used the Two-Headed Giant format, which is the official name for team play: 2 against 2. And this tournament wanted to be distinctive in how teams were formed, with two rules that turn choosing a partner into a headache.

Rule 1 — You and your partner cannot share colors

If my deck uses every color except blue, then my partner's deck has to be blue and nothing else.

You WUR
+
Partner BG
Legal
You WUR
+
Partner WB
Both play white
You WUBRG
+
Partner C
Legal
This is not rocket science. It is simple, and it needs no special solution.

Rule 2 — Both commanders must have appeared in the same preconstructed deck

And here is the problem.

The size of the problem

15,900 card slots to search

As I write this there are 44 sets of legal preconstructed decks published since 2011, totalling 159 individual decks. Each one holds 100 cards, so we are looking at 15,900 card slots — about 6,012 distinct cards once you discount everything that repeats across decks.

To decide whether a pairing is legal, four questions have to be answered first:

  1. Where do I get the data for these cards?
  2. How many of these cards can be commanders?
  3. Are there special cases?
  4. How many legal pairings exist?

Questions 1 and 2

Where the data comes from, and who can be a commander

Two powerful tools answer these: MTGJSON and Scryfall. Magic is popular enough that it has prompted a whole ecosystem of tools for tracking rules, history, cards, editions and collections.

MTGJSON maintains a database with the decklists of the preconstructed decks, ready to examine: that will be our card list. Scryfall is the most complete card database in the game, and it tells us the colors and which cards may be commanders.

The best approach is to take the cards from the decks and run them through Scryfall's is:commander filter. Per the rules, a commander must be:

  • a legendary creature, Spacecraft or Vehicle, or
  • a planeswalker card that explicitly says it can be your commander.

Searching by hand with those two criteria runs into exceptions. The most notable is Grist, the Hunger Tide, which is legally a commander but satisfies neither criterion. I will spare you the details, but Grist is a headache inside the rules because of how it is worded — and precisely for that reason, not using is:commander would drop it without anyone noticing.

With the filter applied, the total comes to 1,055 possible commanders.

Question 3

The special cases

And here it gets more complex still.

Normally you have a single commander, but some cards let you have two. And depending on which mechanic, things get complicated.

Partner. Cards you can pair freely with each other. There are 27 in the precons, and since each can be up to 2 colors, a pair can reach 4.

Partner with. Cards with one very specific partner, named on the card itself. Far easier to handle: each has exactly one possible match.

Doctor's companion. Introduced in the Doctor Who set. It lets a card with that ability be your second commander if your main commander is a Time Lord Doctor. 41 cards in total: 15 Doctors and 26 companions.

Choose a Background. Applies to 4 creatures that can pair with 4 cards defining their background.

Character select. 6 creatures you can pair with one another.

Where rule 2 actually bites

Why this cannot be solved by multiplying on a napkin

Doctor's companion lives entirely inside one set (Doctor Who). Character select lives entirely in another (Ninja Turtles). Backgrounds, in Baldur's Gate. Because each mechanic is contained in a single set, the "same preconstructed deck" rule removes nothing, and multiplying gives the right answer:

Mechanics contained in a single set
MechanicThe arithmeticLegal pairs
Doctor's companion15 Doctors × 26 companions390
Choose a Background4 creatures × 4 backgrounds16
Character select6 creatures with each other15
Partner witheach with its single match14

Partner is the exception, and that is what makes it interesting. Its 27 cards are spread across 10 different sets. If they all combined with each other that would be 351 pairs. But rule 2 demands both came out of the same precon, and that cuts it to 116.

In fact 105 of those 116 come from a single product: Commander 2016, which on its own brings 15 cards with Partner. The other 11 are scattered across the remaining nine sets.

In total: 551 legal partner pairs.

A curiosity

Why Commander 2016 is the tournament's best product

C16 is worth pausing on, because it does not merely contribute the most pairs: they are also the most flexible, which matters enormously when rule 1 forbids you from stepping on your partner's colors.

Its 15 Partner cards are all exactly two colors, and between them they cover all ten two-color combinations that exist in the game. Not one is missing.

Color coverage by set
SetPairsDistinct color identities
Commander 201610520
Doctor Who39214
Baldur's Gate1713
Ninja Turtles168

Of those 105 pairs, 65 reach three colors and 35 reach four. Which means: with C16 you can build a four-color deck and leave your partner a single color, or split three and two. Almost any division they come up with has a pair that supports it.

And as a curiosity, that flexibility comes with raw power. The C16 partners — Thrasios, Triton Hero, Tymna the Weaver, Vial Smasher the Fierce, Kraum, Ludevic's Opus — have been staples of competitive Commander for years; Thrasios + Tymna is probably the best-known pair in the format. Wizards printed a product designed for its cards to combine with each other, and a decade later it turns out to be exactly what this tournament rewards.

Question 4

How many legal pairings exist

Adding it all up, a "seat" on a team is not a card: it is a card or a legal pair. That gives 1,602 possible commander configurations.

And only then can the original question be answered, by crossing every configuration against all the others and filtering by the two rules:

21,699 legal pairings.

Of those, 11,534 are one commander per side, and 10,165 involve at least one partner pair.

Findings

What showed up at the end

Once you can finally enumerate every pairing, something nobody had noticed appears: the format is very lopsided.

Viability by set
SetCommandersWith no possible partnerLegal pairings
Phyrexia: All Will Be One770
Lorwyn Eclipsed17107
Modern Horizons 319634
Doctor Who78010,582

Phyrexia: All Will Be One has no legal pairing at all. Every color identity in that set contains red or white, so nothing can pair with anything. Lorwyn Eclipsed has 17 commanders but only 7 pairings, because four of them are five-color and the set ships no colorless commander to go with them.

This is exactly the kind of thing that ruins a tournament: someone buys a product, builds their deck, and finds out at the table that their partner has no legal option.

Delivery

And now, how do I get this to people

Players are not going to run a script. So the end result is an Excel workbook: you type your commander and it lists every commander your partner may legally choose, with the set that makes them valid and which deck to find each one in.

The complete answer, in a spreadsheet that opens in two clicks.