Wednesday, January 20, 2010

Friday Night Math

I’ve always been a nerd. My Friday nights have long been evidence of this. I’ve never been part of the “party people” and have always had nerdy hobbies that took my weekend evenings.

One of my most beloved hobbies, was a collectible card game I played through all of junior high and half of high school. Every Friday night, I’d head to a local comics and games store at 7 pm, and play with nerds of all ages until usually 1 am.

You may not be immediately familiar with collectible card games (CCGs). Although it doesn’t spring to many people’s minds immediately, most people have at least heard of one: Pokemon. Parents probably heard about this one because these collectible game cards became a problem at schools because they became so popular, they became a distraction at schools and kids would fight over them and steal from one another.
Not all CCGs inspire such fervor. My game of choice was the Star Wars CCG, made by Decipher. In 1999, at the age of 15 I won my way to an invitation at the regional championships. This was no small feat. The game had a steep learning curve and was dominated by college students and older. To go so far at such a young age was rare.

As odd as it may seem, my success also came from my nerdy tendencies; I used my skills in math to build a killer deck.


I loved this game not only because it brought my favorite movie series of all time into a playable game, but because of the subtly elegant design of the game. Unlike many other CCGs, which use dice to determine outcomes, beads or pennies to mark certain cards and track currency, side pencil and paper to keep track of health, etc…, the Star Wars CCG did all of this with just the cards themselves.

In all CCGs, at some point, a random number is necessary to determine the outcome of an event. As mentioned, this of often done with a die. In Star Wars, it was done by drawing a card off the top of your deck. Each card had a “destiny” number that would be used for this purpose. In general, high numbers were better. If you wanted to try to hit someone with a lightsaber, you’d draw a card, look at its destiny number, and if it was higher than your target’s defense value, they’d become one with the Force.

You can probably expect that since you choose what cards go in your deck, this would mean you could just fill your deck with cards that had high destinies and be cutting off more arms than Obi-Wan in a Cantina. This is true, but there’s another problem: More powerful cards tended to have very low destiny values. All of the main characters were a measly 1. Thus, part of the strategy of deck building was to find a balance between these powerful characters and high destiny cards that would help you be cooler than Mace Windu on Geonosis.

However, my strategy moved away from this. Instead of using the powerful Jedi, I built my deck around characters no one else would ever glance at and found ways to make them stronger. The nice thing about these guys was that they had a nice destiny value of 4 (7 was the highest any card had).

Being able to keep so many high destiny cards in my deck was a serious advantage. It was made all the more powerful by using strategies that centered on high destiny values (whereas many other strategies just used it on occasion).

Thus, my task to build the deck was to carefully tune my overall destiny numbers as high as I could, without sacrificing the power of my deck. Here’s where the math comes in.

The most obvious way to analyze the destiny value of the deck was to see what the average was. With my deck, it ended up at 4.3. A typical deck had an average of 2 – 3. This was nice to know. It definitely meant I had some high destiny cards in my deck which would help my overall strategy, but it’s not the whole picture. After all, if 50 percent of my deck was a destiny of 1, and 50 percent was a 7, it would average out to around 4 as well. But I’d still be drawing those 1’s a lot when it counted. So averages are nice, but what I really needed was an understanding of how often different values would come up.

To learn this, I made what’s known as a histogram. Histograms are bar graphs that show the number of something occurring for a given value or range of values. These are useful in many circumstances. In doing my undergraduate research, I made a histogram of the number of stars in an area of sky for a star cluster, fit an equation to it, and found the maxima of that equation to determine the star cluster’s center. For the purposes of my deck, I counted up the number of cards for each destiny value (0 through 7). By looking at ratio of each of these to the total number of cards in the deck, I could determine the probability of each one coming up and assure myself that I was as likely as possible to get what I wanted when it counted.

But your deck of cards isn’t a static thing. You are constantly drawing cards from it to put into play, and returning cards to it through various methods. This means that the average and histogram are constantly changing! To really know how my deck was going to perform, I did one final mathematical analysis. I played dozens of games against myself in which, after every time I took cards from or returned cards to the deck, I re-did my histogram. With this, I was able to track how these values were changing as games would progress. This type of analysis is known as a Monte-Carlo Simulation. In this, you run a scenario numerous times, and see how some quantity changes. It can be affected by various random fluctuations (like the deck being shuffled before the game so the order of cards isn’t the same) so looking at the specific points isn’t helpful, but looking at the averaged trend is telling.

One of the things I learned from this is that I tended to get most of my low destiny cards out of the deck within about 7 turns. That meant that, before that, relying on destiny draws wasn’t entirely safe because those low cards still straggling in my deck, were bringing down my average. But once they were out of the deck and into play, I was almost guaranteed to have a draw of 4 or higher. I ended up with about a 5% chance of anything lower after that point. Those are odds I’d bet on.

So going into the qualification tournament, I had a deep mathematical understanding of how my deck would perform. But there was one more mathematical trick up my sleeve. In the game, it’s possible to return cards to the bottom of your deck from your hand. This meant you could return the highest destiny cards if you didn’t need them at the time and know exactly where they were. All you had to do with use subtraction to keep track of how far down they were in the deck. A simple trick to be sure, but by doing this, my scraggly band of nobodies took down Darth Vader, time and time again.

In that tournament, I took 3rd place out of over 40 players. I suffered one loss, and it was at the hands of the player that would become that year’s world champion. So the moral of this story is that an understanding of some math tricks can make you a Jedi Master, if only on Friday nights.

And remember; May the F = ma be with you. Always.

(This post was originally written for another source relating math to every day experiences, but I decided to post it here.)

2 comments:

Brandon said...

Wow, way to relate the CCG that I played in my youth (albeit with my cousins, never in tournament play) with the class I am taking for my master's degree right now (manufacturing systems) where we are doing Monte-Carlo simulations. Its almost like the Force was guiding your thoughts to be in line with mine...or just happy coincidence...I think we'll go with coincidence. Thanks for the interesting write up!

Brandon said...

Wow, way to relate the CCG that I played in my youth (albeit with my cousins, never in tournament play) with the class I am taking for my master's degree right now (manufacturing systems) where we are doing Monte-Carlo simulations. Its almost like the Force was guiding your thoughts to be in line with mine...or just happy coincidence...I think we'll go with coincidence. Thanks for the interesting write up!