Probability Question (Magic Cards)

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

User avatar
superglucose
hermaj's new favourite
Posts: 2353
Joined: Wed Sep 12, 2007 1:59 am UTC
Location: Domain of Azura
Contact:

Probability Question (Magic Cards)

Postby superglucose » Fri Nov 09, 2012 6:31 am UTC

There is a great story about one of the best players in Magic, Owen Turtenwald. The story goes like this (and is true): in a team draft event he had a pack rat. He lost his first two rounds despite playing this pack rat, so decided to go completely all-in on the Pack Rat strategy. What he did was shuffled up 39 swamps and his one pack rat and aggressively mulliganed his hand to make sure he got turn 2 pack rat on the play. He won his round in 5 minutes, well before any of his teammates, and slammed his deck down showing his opponent the build.

This made me wonder, "which draft deck is better, 1, 2, or 3 pack rats?" I am assuming that in RTR draft the maximum number of rats you can have is 3, though analysis that includes a general solution for a certain number of pack rats would be super sweet because technically it's possible, even if everyone is drafting correctly (I.E. taking pack rat over everything else all the time), to have 6 pack rats (you open 3 packs with at least 1 of 2 possible pack rats, the person to your right/left/right opens packs with 1 pack rat, 1 foil pack rat).

The conditions:

  • We have a 40 card deck made of N pack rats and 40-N swamps.
  • We start the game on the play, meaning that we do not draw an extra card on our first turn.
  • At the beginning of play we will draw 7 cards. If it is not guaranteed that we will have 1 pack rat and 3 lands in play by turn 3 (playing 1 land per turn), we mulligan, meaning we draw 6 cards.
  • We repeat this process until we have mulliganed to 2 cards, at which point we keep the hand and play the game regardless of what that hand is.

So, for example, in a deck that has 2 pack rats, a hand of "Swamp, Swamp, Swamp" would be a mulligan. A hand of "swamp, swamp" may be a winning hand, but only if our next two draw steps are "swamp, pack rat" in any order. A hand of "pack rat, pack rat" loses. A hand of "pack rat, swamp" loses if we draw a second pack rat. A hand of "pack rat, pack rat, swamp" wins.

My question to you is, what build of N pack rats and 40-N n swamps, 0 < N < 7, N is a positive integer, gives us the highest chance of "winning"?

(I honestly have no earthly idea how to approach this because I'm really bad at statistics)
Image

User avatar
phlip
Restorer of Worlds
Posts: 7569
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Probability Question

Postby phlip » Fri Nov 09, 2012 6:49 am UTC

It's not quite the question you're asking (which I might take a look at later, but I'm busy at the moment) but I have analysed something similar for the Lost in the Woods deck, which was pretty similar - one Lost in the Woods, about 44ish Forests, mull until you get it. And I found that if you draw your two-card hand and don't have the Woods, you're still better mulling to 1 than keeping it... it makes you more likely to get the Woods into play by turn 5, or in fact by any turn up to about turn 20 at which point keeping the 2 card hand is ahead (though at that point you're likely dead). Obviously there's no advantage to mulling to 0.

Anyways, this plan (mulling if you don't get the card all the way to 1) had an overall chance of about 50/50, give or take, of getting the Woods into play on turn 5 (ie the chance of having it in your opener, or the chance of keeping a 1-card hand and drawing it in the first 5 turns). I can't remember the exact number.

As to the actual question at hand... the only important cards are one Rat and three Swamps, everything else is so much discard fodder. These four cards are the only things you need to see. So at first approximation I'd say you'd want a deck that's about 10 rats, 30 swamps. The actual peak may vary somewhat as the other details of the game come into play, but that's at least the order of magnitude you're looking at.
For a second approximation, ignoring the size of the deck (ie picking with replacement, or having an infinite-sized deck) this says that a deck that's just over 1/3 rats (as opposed to 1/4) has the best probability of giving you a 7-card opener that has at least one rat and at least 3 swamps in it.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
superglucose
hermaj's new favourite
Posts: 2353
Joined: Wed Sep 12, 2007 1:59 am UTC
Location: Domain of Azura
Contact:

Re: Probability Question

Postby superglucose » Fri Nov 09, 2012 6:54 am UTC

So 6 rats and 3 rats are the best of our "possible" scenarios.

(and yeah the Lost in the Woods deck is similar but Pack Rat... is. I dunno if you've played any RTR limited yet but a resolved turn 2 pack rat is almost unbeatable... and most of the time you have to beat it THAT TURN unless you actually have the wrath or detention sphere.)
Image

User avatar
phlip
Restorer of Worlds
Posts: 7569
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Probability Question

Postby phlip » Fri Nov 09, 2012 12:17 pm UTC

(I had a Pack Rat in my draft deck tonight at FNM. Didn't even see it once. It made me sad. But yes, I have had a turn 2 rat, both on my side and the other side...)

Anyways, I threw together a Python script to calculate the probability of being able to play a turn 2 Pack Rat and activate it on turn 3:
Spoiler:

Code: Select all

#!/usr/bin/python
from fractions import Fraction as F

def nPr(n,r):
   return reduce(lambda a,b:a*b, xrange(n-r+1,n+1), 1)
def fact(n):
   return nPr(n,n)
def nCr(n,r):
   return nPr(n,r)//fact(r)

def calcpdraw(numrats, numcards, handsize, ratsinhand):
   """
   Calculate probability of drawing this hand, from this many cards.

   eg chance of having 3 rats in a 7-card hand from a 40-card deck with 10 rats is:
   7C3 * (10/40)*(9/39)*(8/38) * (30/37)*(29/36)*(28/35)*(27/34)
   """
   pdraw = F(nCr(handsize, ratsinhand))
   for i in xrange(ratsinhand):
      pdraw *= F(numrats - i, numcards - i)
   for i in xrange(handsize - ratsinhand):
      pdraw *= F(numcards - numrats - i, numcards - ratsinhand - i)
   return pdraw

def calcpwin(numrats, numcards, handsize, ratsinhand, ondraw=False):
   """
   Calculate probability of this hand having a turn-3 rat activation

   This is the probability that:
   * If ondraw is True, we draw a card, otherwise we don't
   * We have at least one swamp in hand
   * Draw a second card, we have at least a second swamp and a rat
   * Draw a third card, we have at least a third swamp, and any other card in hand
   """
   # Recursive function to try a few draws and check our constraints
   def turns(turnnum, rats, swamps):
      # Check constraints
      if turnnum == 1:
         if swamps < 1:
            return F(0)
      elif turnnum == 2:
         if swamps < 2 or rats < 1:
            return F(0)
      elif turnnum == 3:
         if swamps < 3 or (swamps + rats) < 5:
            return F(0)
         else:
            return F(1)
      # See what happens when we draw the next card
      if turnnum == 0 and not ondraw:
         return turns(turnnum + 1, rats, swamps)
      else:
         pdrawrat = F(numrats - rats, numcards - rats - swamps)
         return pdrawrat * turns(turnnum + 1, rats + 1, swamps) + (1 - pdrawrat) * turns(turnnum + 1, rats, swamps + 1)
   return turns(0, ratsinhand, handsize - ratsinhand)

def docalcs(numrats, numcards=40, ondraw=False, maxhandsize=7, verbose=True):
   """
   Calculate the optimal mulligan strategy for a particular deck composition, and return the probability of winning with that composition
   """
   pwinmull = -1 # Everything is better than mulling to negative cards
   for handsize in xrange(maxhandsize+1):
      totalpwin = F(0)
      if verbose:
         print "%d cards:" % handsize
      for ratsinhand in xrange(min(handsize,numrats) + 1):
         pdraw = calcpdraw(numrats, numcards, handsize, ratsinhand)
         pwin = calcpwin(numrats, numcards, handsize, ratsinhand, ondraw)

         if verbose:
            print "%5.2f%%: %d Pack Rat, %d Swamp:%7.3f%% to win - %s" % (float(100 * pdraw), ratsinhand, handsize - ratsinhand, float(100 * pwin), "Mull" if pwin < pwinmull else "Keep")

         totalpwin += pdraw * pwin
      if verbose:
         print "Total to win:%7.3f%%" % (float(100 * totalpwin))
         print
      pwinmull = totalpwin
   return totalpwin

def allcalcs(numcards=40, ondraw=False, maxhandsize=7):
   """
   Find the deck composition with the highest probability of winning
   """
   for numrats in xrange(numcards + 1):
      res = docalcs(numrats, numcards, ondraw, maxhandsize, verbose=False)
      print "%2d/%2d:%7.3f%% to win" % (numrats, numcards, float(100 * res))

#docalcs(15)
allcalcs()

These are the results:
Spoiler:
On the play:

Code: Select all

 0/40:  0.000% to win
 1/40: 20.000% to win
 2/40: 36.410% to win
 3/40: 49.798% to win
 4/40: 60.652% to win
 5/40: 69.396% to win
 6/40: 76.391% to win
 7/40: 81.946% to win
 8/40: 86.321% to win
 9/40: 89.736% to win
10/40: 92.370% to win
11/40: 94.368% to win
12/40: 95.844% to win
13/40: 96.880% to win
14/40: 97.531% to win
15/40: 97.827% to win
16/40: 97.772% to win
17/40: 97.350% to win
18/40: 96.526% to win
19/40: 95.251% to win
20/40: 93.467% to win
21/40: 91.108% to win
22/40: 88.114% to win
23/40: 84.428% to win
24/40: 80.013% to win
25/40: 74.853% to win
26/40: 68.963% to win
27/40: 62.398% to win
28/40: 55.254% to win
29/40: 47.677% to win
30/40: 39.859% to win
31/40: 32.042% to win
32/40: 24.503% to win
33/40: 17.543% to win
34/40: 11.467% to win
35/40:  6.549% to win
36/40:  2.987% to win
37/40:  0.850% to win
38/40:  0.000% to win
39/40:  0.000% to win
40/40:  0.000% to win
On the draw:

Code: Select all

 0/40:  0.000% to win
 1/40: 22.500% to win
 2/40: 40.385% to win
 3/40: 54.504% to win
 4/40: 65.571% to win
 5/40: 74.178% to win
 6/40: 80.818% to win
 7/40: 85.896% to win
 8/40: 89.742% to win
 9/40: 92.627% to win
10/40: 94.765% to win
11/40: 96.329% to win
12/40: 97.451% to win
13/40: 98.230% to win
14/40: 98.736% to win
15/40: 99.010% to win
16/40: 99.069% to win
17/40: 98.907% to win
18/40: 98.494% to win
19/40: 97.780% to win
20/40: 96.697% to win
21/40: 95.161% to win
22/40: 93.078% to win
23/40: 90.351% to win
24/40: 86.885% to win
25/40: 82.600% to win
26/40: 77.440% to win
27/40: 71.388% to win
28/40: 64.474% to win
29/40: 56.791% to win
30/40: 48.506% to win
31/40: 39.860% to win
32/40: 31.174% to win
33/40: 22.835% to win
34/40: 15.275% to win
35/40:  8.929% to win
36/40:  4.169% to win
37/40:  1.215% to win
38/40:  0.000% to win
39/40:  0.000% to win
40/40:  0.000% to win
So, on the play, the optimal number of Pack Rats to have is 15, while on the draw you want 16. At lower counts than that, more is better.

Also, for completeness, this is the mulligan strategy for both:
Spoiler:
On the play with 15 rats:

Code: Select all

0 cards:
100.00%: 0 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

1 cards:
62.50%: 0 Pack Rat, 1 Swamp:  0.000% to win - Keep
37.50%: 1 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

2 cards:
38.46%: 0 Pack Rat, 2 Swamp:  0.000% to win - Keep
48.08%: 1 Pack Rat, 1 Swamp:  0.000% to win - Keep
13.46%: 2 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

3 cards:
23.28%: 0 Pack Rat, 3 Swamp: 40.541% to win - Keep
45.55%: 1 Pack Rat, 2 Swamp: 86.336% to win - Keep
26.57%: 2 Pack Rat, 1 Swamp: 41.441% to win - Keep
 4.61%: 3 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win: 59.771%

4 cards:
13.84%: 0 Pack Rat, 4 Swamp: 41.667% to win - Mull
37.75%: 1 Pack Rat, 3 Swamp:100.000% to win - Keep
34.47%: 2 Pack Rat, 2 Swamp: 87.619% to win - Keep
12.45%: 3 Pack Rat, 1 Swamp: 43.810% to win - Mull
 1.49%: 4 Pack Rat, 0 Swamp:  0.000% to win - Mull
Total to win: 79.171%

5 cards:
 8.07%: 0 Pack Rat, 5 Swamp: 42.857% to win - Mull
28.84%: 1 Pack Rat, 4 Swamp:100.000% to win - Keep
36.70%: 2 Pack Rat, 3 Swamp:100.000% to win - Keep
20.74%: 3 Pack Rat, 2 Swamp: 88.908% to win - Keep
 5.19%: 4 Pack Rat, 1 Swamp: 46.387% to win - Mull
 0.46%: 5 Pack Rat, 0 Swamp:  0.000% to win - Mull
Total to win: 89.848%

6 cards:
 4.61%: 0 Pack Rat, 6 Swamp: 44.118% to win - Mull
20.76%: 1 Pack Rat, 5 Swamp:100.000% to win - Keep
34.60%: 2 Pack Rat, 4 Swamp:100.000% to win - Keep
27.26%: 3 Pack Rat, 3 Swamp:100.000% to win - Keep
10.67%: 4 Pack Rat, 2 Swamp: 90.196% to win - Keep
 1.96%: 5 Pack Rat, 1 Swamp: 49.198% to win - Mull
 0.13%: 6 Pack Rat, 0 Swamp:  0.000% to win - Mull
Total to win: 95.252%

7 cards:
 2.58%: 0 Pack Rat, 7 Swamp: 45.455% to win - Mull
14.25%: 1 Pack Rat, 6 Swamp:100.000% to win - Keep
29.92%: 2 Pack Rat, 5 Swamp:100.000% to win - Keep
30.87%: 3 Pack Rat, 4 Swamp:100.000% to win - Keep
16.84%: 4 Pack Rat, 3 Swamp:100.000% to win - Keep
 4.83%: 5 Pack Rat, 2 Swamp: 91.477% to win - Mull
 0.67%: 6 Pack Rat, 1 Swamp: 52.273% to win - Mull
 0.03%: 7 Pack Rat, 0 Swamp:  0.000% to win - Mull
Total to win: 97.827%
On the draw with 16 rats:

Code: Select all

0 cards:
100.00%: 0 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

1 cards:
60.00%: 0 Pack Rat, 1 Swamp:  0.000% to win - Keep
40.00%: 1 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

2 cards:
35.38%: 0 Pack Rat, 2 Swamp: 60.503% to win - Keep
49.23%: 1 Pack Rat, 1 Swamp: 65.979% to win - Keep
15.38%: 2 Pack Rat, 0 Swamp: 23.992% to win - Keep
Total to win: 57.582%

3 cards:
20.49%: 0 Pack Rat, 3 Swamp: 68.468% to win - Keep
44.70%: 1 Pack Rat, 2 Swamp: 94.144% to win - Keep
29.15%: 2 Pack Rat, 1 Swamp: 68.378% to win - Keep
 5.67%: 3 Pack Rat, 0 Swamp: 26.049% to win - Mull
Total to win: 77.514%

4 cards:
11.63%: 0 Pack Rat, 4 Swamp: 69.841% to win - Mull
35.43%: 1 Pack Rat, 3 Swamp:100.000% to win - Keep
36.24%: 2 Pack Rat, 2 Swamp: 94.902% to win - Keep
14.71%: 3 Pack Rat, 1 Swamp: 70.868% to win - Mull
 1.99%: 4 Pack Rat, 0 Swamp: 28.347% to win - Mull
Total to win: 88.935%

5 cards:
 6.46%: 0 Pack Rat, 5 Swamp: 71.261% to win - Mull
25.84%: 1 Pack Rat, 4 Swamp:100.000% to win - Keep
36.91%: 2 Pack Rat, 3 Swamp:100.000% to win - Keep
23.49%: 3 Pack Rat, 2 Swamp: 95.630% to win - Keep
 6.64%: 4 Pack Rat, 1 Swamp: 73.445% to win - Mull
 0.66%: 5 Pack Rat, 0 Swamp: 30.924% to win - Mull
Total to win: 94.896%

6 cards:
 3.51%: 0 Pack Rat, 6 Swamp: 72.727% to win - Mull
17.72%: 1 Pack Rat, 5 Swamp:100.000% to win - Keep
33.22%: 2 Pack Rat, 4 Swamp:100.000% to win - Keep
29.53%: 3 Pack Rat, 3 Swamp:100.000% to win - Keep
13.09%: 4 Pack Rat, 2 Swamp: 96.324% to win - Keep
 2.73%: 5 Pack Rat, 1 Swamp: 76.103% to win - Mull
 0.21%: 6 Pack Rat, 0 Swamp: 33.824% to win - Mull
Total to win: 97.772%

7 cards:
 1.86%: 0 Pack Rat, 7 Swamp: 74.242% to win - Mull
11.55%: 1 Pack Rat, 6 Swamp:100.000% to win - Keep
27.36%: 2 Pack Rat, 5 Swamp:100.000% to win - Keep
31.92%: 3 Pack Rat, 4 Swamp:100.000% to win - Keep
19.76%: 4 Pack Rat, 3 Swamp:100.000% to win - Keep
 6.47%: 5 Pack Rat, 2 Swamp: 96.976% to win - Mull
 1.03%: 6 Pack Rat, 1 Swamp: 78.831% to win - Mull
 0.06%: 7 Pack Rat, 0 Swamp: 37.097% to win - Mull
Total to win: 99.069%

Also, for completeness, since it's the only case that's actually reasonably-likely to ever happen, here's the mulligan strategy for a single pack rat:
Spoiler:
On the play:

Code: Select all

0 cards:
100.00%: 0 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

1 cards:
97.50%: 0 Pack Rat, 1 Swamp:  0.000% to win - Keep
 2.50%: 1 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

2 cards:
95.00%: 0 Pack Rat, 2 Swamp:  0.000% to win - Keep
 5.00%: 1 Pack Rat, 1 Swamp:  0.000% to win - Keep
Total to win:  0.000%

3 cards:
92.50%: 0 Pack Rat, 3 Swamp:  2.703% to win - Keep
 7.50%: 1 Pack Rat, 2 Swamp:100.000% to win - Keep
Total to win: 10.000%

4 cards:
90.00%: 0 Pack Rat, 4 Swamp:  2.778% to win - Mull
10.00%: 1 Pack Rat, 3 Swamp:100.000% to win - Keep
Total to win: 12.500%

5 cards:
87.50%: 0 Pack Rat, 5 Swamp:  2.857% to win - Mull
12.50%: 1 Pack Rat, 4 Swamp:100.000% to win - Keep
Total to win: 15.000%

6 cards:
85.00%: 0 Pack Rat, 6 Swamp:  2.941% to win - Mull
15.00%: 1 Pack Rat, 5 Swamp:100.000% to win - Keep
Total to win: 17.500%

7 cards:
82.50%: 0 Pack Rat, 7 Swamp:  3.030% to win - Mull
17.50%: 1 Pack Rat, 6 Swamp:100.000% to win - Keep
Total to win: 20.000%
On the draw:

Code: Select all

0 cards:
100.00%: 0 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

1 cards:
97.50%: 0 Pack Rat, 1 Swamp:  0.000% to win - Keep
 2.50%: 1 Pack Rat, 0 Swamp:  0.000% to win - Keep
Total to win:  0.000%

2 cards:
95.00%: 0 Pack Rat, 2 Swamp:  5.263% to win - Keep
 5.00%: 1 Pack Rat, 1 Swamp:100.000% to win - Keep
Total to win: 10.000%

3 cards:
92.50%: 0 Pack Rat, 3 Swamp:  5.405% to win - Mull
 7.50%: 1 Pack Rat, 2 Swamp:100.000% to win - Keep
Total to win: 12.500%

4 cards:
90.00%: 0 Pack Rat, 4 Swamp:  5.556% to win - Mull
10.00%: 1 Pack Rat, 3 Swamp:100.000% to win - Keep
Total to win: 15.000%

5 cards:
87.50%: 0 Pack Rat, 5 Swamp:  5.714% to win - Mull
12.50%: 1 Pack Rat, 4 Swamp:100.000% to win - Keep
Total to win: 17.500%

6 cards:
85.00%: 0 Pack Rat, 6 Swamp:  5.882% to win - Mull
15.00%: 1 Pack Rat, 5 Swamp:100.000% to win - Keep
Total to win: 20.000%

7 cards:
82.50%: 0 Pack Rat, 7 Swamp:  6.061% to win - Mull
17.50%: 1 Pack Rat, 6 Swamp:100.000% to win - Keep
Total to win: 22.500%

Basically, mull until you get the rat; stop at 3 cards on the play, two on the draw.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
gmalivuk
GNU Terry Pratchett
Posts: 26727
Joined: Wed Feb 28, 2007 6:02 pm UTC
Location: Here and There
Contact:

Re: Probability Question (Magic Cards)

Postby gmalivuk » Fri Nov 09, 2012 6:16 pm UTC

Folks, please be specific in your thread titles!

The next thread that gets started called only "probability question" or "question about probability" will be derailed with pictured of animals playing poker until the title is fixed.
Unless stated otherwise, I do not care whether a statement, by itself, constitutes a persuasive political argument. I care whether it's true.
---
If this post has math that doesn't work for you, use TeX the World for Firefox or Chrome

(he/him/his)


Return to “Mathematics”

Who is online

Users browsing this forum: No registered users and 12 guests