skurmedel Stuff

An introduction to the math of Magic the Gathering card draw

Magic has a rich set of mechanics, but it all revolves around drawing cards. Card games are well studied in mathematics and these ideas can be applied to Magic the Gathering as well. Anyone who’s taken a course in probability or combinatorics know card games and dice are a favourite among text book authors.

In this short series we will look at a couple of different questions, you as a player, may have when building a deck for Magic.

I’m most familiar with 40 card, limited, decks, and we will base our scenarios on this. But usually you can just substitute 40 for 60 and the question, and the answer will still hold.

Who’s this for?

Obviously you like Magic, or have an interest. Maybe you want to answer some of the common questions you have when you are building a Magic deck without entering it into a computer. Or maybe you have used the probability counter on Deckstats and wonder what the theory behind it is.

This introduction will not assume great knowledge about maths, but hopefully you can add, multiply and divide. A basic grasp of algebra is helpful too.

I will not provide proofs for anything, because I don’t think it will help the target audience much. Each problem will have a motivation though, and be answered in a deductive form.

About this guide

I am relatively new to Magic, and I’m no Euler, so it might contain both errors in regards to MtG and in regards to the maths involved.

If you spot an error please do get in touch and tell me.

1. The building blocks

Magic players are often encouraged to have multiples of some types of cards. This makes intuitive sense. More copies of the same creature, means a more consistent draw. If we can calculate the probability that a card is drawn, we can put a number on the consistency. What if we eschew the expert advice and go with a deck where no card occurs more than once?

Thus, for now we will assume you have a deck of 40 cards, and it is completely unique, not even multiples of lands are different.

1.1. What about shuffling this deck?

How many different ways can we shuffle these 40 cards? A lot, you say. That’s true, but how many exactly?

We will shuffle our deck by spilling all the cards out on a table then picking one randomly, one after another.

Let’s pick our first card. We have 40 cards to choose from. Then we have another 39 to pick from. Then another 38 and so forth.

The crucial thing to understand now is that when we had picked our first card, for any card we picked as our first, there would be 39 to choose from for the next pick. This means that there is $40 \cdot 39$ ways to pick the first two cards in our sort.

You can look at it like you are along a trail, and at the first fork, you have 40 paths to chose from. The next one has 39 paths, and so forth. Every day, you walk this trail and change the path you take at some fork. When you’ve walked all different paths, you count the number of paths taken.

In total we have ways to do this. This number is denoted by mathematicians, and it’s called the factorial. for example. The factorial of most numbers is usually a very large number. In fact, the number of ways to shuffle an all-unique 40 deck is gigantic:

This may all seem very artificial and unrealistic, but we have introduced the factorial, which is a crucial tool later on.

1.2. How many different ways can we draw 7 cards from this stupid deck?

The starting hand in Magic is very important; so important in fact that you are allowed to mulligan and draw a new (smaller) hand. The possible starting hands is thus of keen interest to most players.

Armed with the factorial above, we know that there are 40, then 39, then 38, then 37, then 36, then 35 and finally 34 cards to possible cards at each step. So . This number is enormous, not as enormous as the one above but still unfathomably large.

We can denote this number:

1.3. But hang on, the order doesn’t matter!

It doesn’t matter if I draw white to green, Demolish and then a Ghalta, or a Ghalta then Demolish and 5 colours. You would still say this is the same hand.

Image showing cards in one ordering One ordering
Image showing cards in another ordering Another ordering

So in our number above, we have counted the same hand many times over. We can deal with this. How many ways can you arrange 7 cards? Let us rephrase that, how many ways can you shuffle 7 cards?

We know this! So each possible hand is counted times too much in . We simply divide it by . Using common algebra this comes out as:

This number is commonly referred to as the binomial number of 40 and 7. Sometimes we say “40 choose 7 without order”, because we choose 7 of something from 40 items, and we don’t care about the order. The number of possible hands in our all-unique 40 deck is thus:

Oops, still enormous! But this number is actually many times smaller than and . In the next session we will build upon this to actually account for multiples of a card.

2. Multiples of cards

A deck with no multiples at all is a rather unrealistic deck. So let’s deal with a more realistic deck, where there’s at the very least 6-8 lands of one type, and about the same of another one.

2.1 Dealing with the lands

2.2 Additional multiples

3. Probabilities

3.1. The basics

3.2. Whats the probability we get one of our 1-drops in the first hand?

A nitpicky explanation of sRGB gamma correction

What is sRGB?

sRGB is a colour space, and a standard that is probably the most common colour space for computer displays. Wikipedia explains this better than me. If your stuff will be displayed on the internet, you are most likely targeting sRGB. This applies to virtually all PC games as well.

Why do we gamma correct?

Here are some good explanations:

  • http://www.cambridgeincolour.com/tutorials/gamma-correction.htm
  • http://www.cgsd.com/papers/gamma_intro.html

In the future I wish to put together an artist-friendly explanation with some interactive aids to explain the whole idea behind a linear workflow.

The power function

Now, after reading the above two links, you might think that gamma correction is simply raising each pixel p:s value by some number: and undoing the operation is simply .

As I’ll explain, for sRGB, this is not really correct. It works, but it is an approximation. If you want to be totally compliant with the standard, you need to use the functions below, which you’ll note is actually a piecewise function.

Linear to corrected

blabla

Corrected to linear

The reasoning behind the piecewise function

Using 2.2 as an approximation

Comparisons

GLSL code

Note about Rec709 and Rec2022