Case study · Python · data reconciliation · Excel
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.
Context
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:
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
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.
If my deck uses every color except blue, then my partner's deck has to be blue and nothing else.
And here is the problem.
The size of the problem
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:
Questions 1 and 2
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:
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
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
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:
| Mechanic | The arithmetic | Legal pairs |
|---|---|---|
| Doctor's companion | 15 Doctors × 26 companions | 390 |
| Choose a Background | 4 creatures × 4 backgrounds | 16 |
| Character select | 6 creatures with each other | 15 |
| Partner with | each with its single match | 14 |
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
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.
| Set | Pairs | Distinct color identities |
|---|---|---|
| Commander 2016 | 105 | 20 |
| Doctor Who | 392 | 14 |
| Baldur's Gate | 17 | 13 |
| Ninja Turtles | 16 | 8 |
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
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
Once you can finally enumerate every pairing, something nobody had noticed appears: the format is very lopsided.
| Set | Commanders | With no possible partner | Legal pairings |
|---|---|---|---|
| Phyrexia: All Will Be One | 7 | 7 | 0 |
| Lorwyn Eclipsed | 17 | 10 | 7 |
| Modern Horizons 3 | 19 | 6 | 34 |
| Doctor Who | 78 | 0 | 10,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
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.