Math of Magic

Because math isn't always boring

Month: June, 2012

Randomness, part 1

So, today I’m going to talk about randomness, as promised. But, keeping true to the spirit of randomness, first I’m going to talk about Duels of the Planeswalkers on iPad.

First off, I’m so glad it finally made the leap to the platform. I have my iPad with me pretty much everywhere I go, and I love the ability to pull it out wherever and play a quick game of Magic or three. I do however have a few quibbles with it, hopefully thing they can change for DotP 2014.

First off, I think Stainless would do well to consider the differences in portable and console gaming. Portable gaming tends to be something one does on the side, so if I were them, for the portable version, I would get rid of the notion of time limits for responding to abilities. I realize that those are mostly to facilitate multiplayer, but given the asynchronous nature of gaming on the iPad, I don’t think it would hurt too much there either. Really, they should look at what PlayDek have done with Ascension and try to emulate that as much as possible. Granted, Ascension is a much simpler game, but they brought it to the iPad very well, and one of the great parts of it is being able to launch into a game in seconds, whereas the load time for DotP – at least on my old iPad 1 – closes in on a minute, with all the animations and menus and so on.
But other than that, I’m very happy it exists, and I have been having a lot of fun unlocking cards and dueling opponents.

Now, after that bit of randomness, randomness!

What do we mean when we say a deck is random? Well, the simplest answer is, all the cards in the deck are in a random order, which sounds reductive, but it really is important to define these things.

If all the cards in the deck are in a random order, then for any given card, which we’ll number after its position from the top of the deck, the probability that that card will be any given card in the deck is the same. Or, in symbols,


Where n is the position in the deck, X is the individual card (we’re not counting multiple copies of a card just yet… we’ll get to that a bit later. Assume for now you have a singleton deck), and N is the total number of cards in the deck.

We call this the universal distribution, and it’s very important for probability theory. I’m going to skip the part where I explain how probabilities work, I assume my readers already know the basics.

It’s interesting to note that we can sum up either by n while leaving X constant, and we get:

Σ_n P_n(X) = 1

Or in other words, the probability that a given card X is actually in the deck is one. Also, we can sum over X:

Σ_X P_n(X) = 1

and get the same thing, since the probability that the card in position n is one of the cards in the deck is also one. This works since there are a total of N of both n and X.

If there are multiple copies of a given card in the deck, this formula changes somewhat. We’re going to change up our set that X is a part of a bit. We’re going to name the set of all the  individual cards in a deck, in other words including multiple copies, A, and the set of all the card names, of which some cards might be multiples, M. For any given m out of M, we’ll define c(m) to be the number of copies of that card. Since the probability that any given card will be one of those copies is, fairly obviously, equal to the probability that it is one individual card times the number of copies of that card, we have

P_n (m) = c(m)/N.

Before we close for today, I want to look at a practical example of how this can be useful. Let’s talk about opening hands. Say you have four copies of a card in your sixty card deck. What is the probability that you will draw it in your opening hand?

For starters, we’ll sum up the probability that the card will be in your first seven cards, in other words

Σ_(n=1…7) P_n(m) = c(m)/60 + c(m)/60 + … + c(m)/60 = 7 * 4/60 = 7/15

Or about half. This makes sense intuitively, but is it the whole story? Not exactly. That formula tells us what the probability is that each of the first seven cards is the card you want, but it doesn’t factor in that you might get multiple copies. But that will have to wait for another post.

Next week we’ll mix things up some more.


1. What happens if you sum up over the elements in M?

2. Calculate Σ_n P_n(m) = 1 for a given m in M. What is the result? How can you interpret this?

3. Is pile shuffling random? Explain why or why not.


Shuffling, part 1

So, for our first foray, we’re going to look at shuffling. We all do it, usually several times a day, but how does it work, exactly? What methods work the best for shuffling, and which don’t work at all?

That last question is interesting: Which methods of “shuffling” get used on a regular basis that don’t actually shuffle your deck. Perhaps you already know the answer, it’s the bane of judges everywhere, the so called “Pile Shuffle”.

Pile shuffling (though, as we will see, it isn’t really shuffling at all), is when a player deals cards from the top of their deck into piles in front of him or her, then picks up those piles one after another. It certainly seems random, but it is in actual fact anything but. I’ll try to illustrate this for you, starting with a simpler example.

Take a deck of 12 cards that we deal into six piles. Say also that the cards are either lands (L) or spells (S), and at the beginning the player sorted them so that they alternate land-spell-land. This is allowed, as long as the deck gets shuffled thoroughly since the order they started in will be unrelated to the order they end up in.

So, to start, our deck looks like this: L S L S L S L S L S L S (counting from the top to the bottom. If you flip them around to look at the card faces, this order will be reversed, but you usually shuffle face down)

Let us pile shuffle this deck now. The first pile will get the first land card, the second will get the first spell, the third will get the second land, and so on, till we end up with this:

L  S  L  S  L  S
L  S  L  S  L  S
1  2  3  4  5  6

When we stack these we have a deck that looks like this:


You may already see a problem here. While this order isn’t exactly the same as the first one, it still has a very regular pattern about it, and is very predictable. This should already raise red flags, but let’s continue.

The second pile shuffle will look like this:

S  S  L  L  S  S
L  L  S  S  L  L
1  2   3  4 5  6

Remember, the first card we lay down will be at the bottom of the pile, once we lay down the first six piles the next card will be on top of the first. Piling these together gives us:


Pretty close to our original. Already after two pile shuffles we have a big problem, but what happens after the third?

L  S  S  L  S  L
S  L  S  L  L  S
1  2  3  4  5  6

Which leads to


Now, you might be thinking, this looks pretty random. Sure, some lands and spells are clumped together, but if you got handed a deck that looks like this, you’d assume that the player had actually shuffled it, right? Well, let’s go on to some more pile shuffles and see if this stays true.

L  L  S  L  L  S
L  S  S  L  S  S
1  2  3  4  5  6


And one more:

L  L  L  S  S  S
L  L  L  S  S  S
1  2  3  4  5  6


So, now we’ve gone through five pile shuffle, and we’ve nicely put all our lands on top, and all our spells on bottom. Not a very good order, strategically, but that’s not important. What is important is that we know exactly what the order is and, what’s worse, all we have to do is pile shuffle one more time

S  S  S  S  S  S
L  L  L  L  L  L
1  2  3  4  5  6


And we have this. In other words, the exact same order that we started with, except with lands and spells reversed. In fact, do another six pile shuffles – and I’ve seen players easily do that many before starting a game – and you’ll have the same order as in the beginning. Don’t believe me? Try it yourself!

This is why pile shuffling isn’t considered randomization. After each shuffle you know exactly where the cards are going to be. Even if you pick up the piles in a random order, you still have the same relative positions of cards in the piles, which can still lead to a very non-random outcome, especially if all you care about is two qualities, such as land or non-land.

That’s it for now. When I continue this topic I’m going to break out the algebra, but next week I’m going to talk a little more about what “random” means.

(It’s a math blog, of course there are exercises!)

  1. What happens when you pick up the piles randomly? What can you say about the order of cards after a given number of pile shuffles?
  2. Try out the pile shuffle with a full deck of thirty lands and thirty non-land spells. How many pile shuffles do you need to get back to a pattern of land-spell-land?
  3. What about if you pile shuffle a deck while tracking three qualities: land, creature, non-creature spell. Assume equal quantities of each.

Introductions Are in Order

Welcome to my new blog, the Math of Magic.

Still here? That word “math” didn’t scare you away? Wow… well, congratulations, and thank you. I promise it won’t all be math in this blog. Well, mostly math, but it will be fun, just wait!

Well, fun for us math geeks, anyway. But want to know a secret? Come a little closer, let me whisper it to you.

If you play Magic: the Gathering, you’re a math geek.

There, I’ve said it. Don’t believe me? What if I told you a game of Magic was just one huge mathematical operation. Even the entire game of Magic, with all its tens of thousands of cards and trillions of potential interactions, can still be summed up in something as simple as a vector space. A very large vector space, granted, but not infinite.

Sorry to say, but every game of Magic you’ve ever played has just been locating, step by step, your place in this giant vector space. The names of the cards don’t matter, the flavor, the colors, all bow down to the might of math.

I sense I may be losing you, come back! It’s not all bad. The fact Magic is based on math isn’t entirely a bad thing. It’s what allows judges to make unambiguous rulings at tournaments, what allows Duels of the Planeswalkers to beat you every once in a while. And, most importantly, it lets R&D make new cards – usually by taking a look at the underlying equations and saying “okay, how can we break these?”.

If you want to play Magic without math you can, however it would become very… strange very fast. You and your opponent would have to debate what a Stronghold Overseer actually oversees, and whether Calling the Wild summons wolves to do your bidding, or just lets your Evolving Wild, well, evolve. In short, it would be a game without rules, just with storytelling. That game exists too, and it’s called “Dungeons and Dragons” (which technically has rules, but also has a player that can override any of those rules at a whim). Many people do enjoy that game, and many of them also enjoy Magic, but I feel quite confident that those few that actually play Magic solely for the flavor will be quickly disappointed when you equip your Sword of Feast and Famine to a Wall of Omens, and struggle to figure out how any of that makes any kind of flavor sense.

Yes, Magic is based on rules, and rules are based on math. I am firmly of the opinion that understanding math is key to becoming a better Magic player. With that in mind, I intend to dive in to the swirling morass of algebra, probability theory, game theory, and perhaps even a bit of calculus (though probably not a lot) that goes into each and every game of magic you’ll play.

For a flavor of what I intend to look out, check out the article I wrote for (if you just read that in Chewies voice, then send me an email!) at And if you don’t believe me that math can be fun, check out Vi Hart’s YouTube channel at

Stay tuned for my first article on the Math of Magic, where we will look at something that happens in every single game of Magic, oftentimes before it even begins: shuffling.

If you want to get in touch with me, you can email me at, follow my Twitter feed at, call my voicemail line at 425-200-4335, or subscribe to me on Facebook under

Thank you for reading, and stay mathy!