This article assumes you've read the introduction to this series, which you can find here. I'm going to jump right into the details now, so if you haven't perused the previous entry, continue at your own risk of being totally baffled!
Modelling the Commander Deck
EDHREC's primary function is to recommend cards for a commander deck, so the first thing we have to do to recreate that functionality is figure out what a commander deck even is. Simply put, a Commander deck is a list of 100 unique Magic: the Gathering cards legal in the Commander format — no more, and no less.
As you build a deck, you have to designate one of its cards as a commander. It's required to be a legendary creature (a specific type of Magic card), and you're only allowed to include cards in your deck whose color identity (an intrinsic property of cards) is either equal to or a subset of the color identity of your commander.
So, to model a commander deck, we simply have to store an array of 99 cards and the commander, enforce its legality, and be on our way. Simple enough, right? Well, it would be, if I didn't just lie to your face.
In several ways.
The Hidden Complexity of Data Modeling
If you're a Magic player, a programmer, or both, you'll certainly have noticed several serious flaws in my explanation above, and I made those mistakes on purpose to highlight a critical lesson I've learned over my years in the industry: you must deeply understand your domain and your users before you start modeling your data. If you make assumptions, and those assumptions are wrong, then you'll have to make risky changes later down the line to reflect reality.
Now, the above description would be a sufficient explanation for the Commander format, but only if you were teaching a new player the absolute basics. The devil's in the details, so let's go over some of those details now just to illustrate how deep that rabbit hole goes.
"A Commander Deck Is a List of 100 Cards"
False. You might be tempted to think that commander decks are lists of 100 cards, because that's what it says in the rules, but that assumption can be broken in multiple ways:
- A list might not necessarily be finished. Someone may have too few cards because they need to add more, or too many cards because they have to cut bad cards.
- Even if a deck is finished, a deck can sometimes legally contain 101 cards. Currently, that can only happen if one of them is a Companion, and the debates over that were one hell of a popcorn muncher.
- Most importantly, some players just do not care about the rules, and will run a different number than 100 cards. They could be cheating, or maybe playing a Battle of Wits deck with the table's blessing.
I'm highlighting the third point as most important because it represents another salient lesson that I learned in the industry: sometimes, and for whatever reason, rules and standards just aren't followed.
In my real life work, I've had to make code changes to accept input that blatantly contradicts well-defined standards because a third party was not using it correctly in their product. The value of interoperability with a wide array of systems generally outweighs the engineering purity of following something exactly to spec.
"A Commander Deck Is a List of Unique Cards"
Also patently false, and this one doesn't even require that much research. Basic lands like Plains are allowed in multiples, and some cards specifically say that you're allowed to include any number of them.


Even if you know some important information, it's best not to make assumptions about it. It's often said that that Commander is a "singleton format," but it's really not — or at least, not to the extent that the phrase "singleton format" would have you believe. Even the original name of the format, Elder Dragon Highlander, in the sense that "there can be only one," is misleading here!
"A Commander Deck Is Made of Cards Legal In the Format"


Say it with me, folks: some people just do not care. And more power to them! Some cards that aren't legal in commander are really fun to play, or maybe they were really expensive to buy before getting banned and some people don't want to feel like they sunk a bunch of money into cardboard that is no longer useful.
"A Commander Must Be a Legendary Creature"
This is true in the sense that all squares are rectangles, but not all rectangles are squares. Yes, all legendary creatures are allowed to be a deck's commander, but there are more options than just that:
- Some Planeswalkers are allowed to be commanders;
- Some Vehicles are allowed to be commanders;
- Actually, because of a recent rules change, all legendary Vehicles and Spacecraft are allowed to be commanders; and
- Some people just like running whatever as their commander.
In addition to the fact that some people don't care, it's possible for standards and rules to change, and you have to be prepared for that.
"A Commander Must Be a Single Card"
There has to be something. Surely we can rest easily knowing that your commander must be a single card, right? Nope! It turns out some rules allow you to play multiple commanders for one deck, concurrently.



In fact, there are multiple such exceptions. So far they've limited the amount of commanders you can have to two; God forbid they create a mechanic that lets you have three.
Well, Shoot!
So what the heck do we do? All the rules we thought we knew about the construction of a Commander deck falls prey to special exceptions, including the most special exception of all: rule 0, or the tacit idea that the game is anything the players agree it to be. And they're right; who am I to tell someone how to play with pieces of cardboard they bought?
So, the problem becomes how to make a functional model out of the cloudy ambiguity of the real world. There's no one answer to questions like this; it depends on your circumstances and what you're trying to accomplish.
If you're making a product that faces users, it's beneficial to be prescriptive to some extent. For example, EDHREC itself primarily concerns itself with commanders and deck constructions that are (relatively) legal, because its users tend to be the type that play within the established rules. You won't see Swords to Plowshares listed as a commander there.
For me, I'm going to go with these definitions:
- A Commander deck is any collection of Magic cards; and
- A Commander must be at least one and no more than two Magic cards.
The reason I settled on these constraints specifically is because I want to ingest the most data possible that can relate cards together. I don't need any more constraints, because I understand that the vast majority of people are going to conform to the rules.
In a sense, I get the best of both worlds; my code won't break when someone puts a thousand cards in their deck, but as I'm getting data from real people, most of them will be well formed enough that it shouldn't skew the results all that much.
Besides, it's not like illegal decks are void of useful information; practically nothing in this world is completely worthless when it comes to learning.
Next Time
We've got an understanding of what a commander deck is. But that's just a tiny bit of the puzzle, because there's one thing I've neglected to mention this entire time: what the hell is a Magic card? I've spent so much time talking about the aggregate collections of them that I've missed the trees for the forest.
We'll take a look at what constitutes a card next time, and maybe even actually write some code? See you then!