Thursday, July 19, 2012

Settlers of Catan - probability of bandit attack


* This post seeks to answer the question, "Given that you have more than 7 cards in your hand, what is the likelihood that nobody (including yourself) will roll a 7 before the next turn, forcing you to discard?"

* First we must calculate the probability of anybody rolling a 7 (a seven is the most common roll possible).

* It is the probability that seven will be rolled in any combination of dice.

* Given that any particular outcome (X=a,Y=b)=P(X=a)*P(Y=b)=1/6*1/6=1/36

* That is P(X+Y=7)=P(X=1,Y=6)+P(X=2,Y=5)+P(X=3,Y=4)+P(X=4,Y=3)+P(X=5,Y=2)+P(X=6,Y=1)
*                 =  1/36    +    1/36  +   1/36   +    1/36  +    1/36  +   1/36    = 6/36 = 1/6

* let's check this

clear
set obs 10000
gen X = ceil(runiform()*6)
gen Y = ceil(runiform()*6)

gen XplusY = X + Y

gen YXis7 = 0
replace YXis7 = 1 if XplusY==7

sum
di 1/6

* Looks pretty close to 1/6 to me.

* So given that 1 out of 6 of the times we roll we will see a 7, what is the probability given z players at the table that you will get all the way around to your turn without rolling a 7?

* If it is just you, then it is easy. P(X1+Y1 != 7)= 1-1/6 = 5/6

* Gets a bit more tricky with more people but in general it is easy to calculate.

* Since the probability of not getting a 7 for any player is independent of not getting a 7 for any other player then the probabily is easy to calculate:

* In the two player case: P(X1+Y1 != 7, X2+Y2 != 7) = P(X1+Y1 != 7)*P(X2+Y2 != 7)=5/6*5/6=(5/6)^2=25/36
di 25/36 " = 69%"

* If you have three players
di "P(X1+Y1 != 7, X2+Y2 != 7, X3+Y3 != 7) = P(X1+Y1 != 7)*P(X2+Y2 != 7)*P(X3+Y3 != 7)=5/6*5/6*5/6=(5/6)^3=125/216 =" 125/216 " about 58%"

* If you have four players
di "P(!=7)=(5/6)^4= " (5/6)^4 " about 48%"

* So with 4 players there is better than 50% chance of rolling a 7 before your turn comes back to you.

* Let's test this with through simulation

set seed 1010
clear
set obs 10000

* This will generate 4 sets of variables
forv i=1/4 {
  * X for the first die
  gen X`i' = ceil(runiform()*6)
  * Y for the second die
  gen Y`i' = ceil(runiform()*6)
  * The sum of the dice
  gen X`i'plusY`i' = X`i' + Y`i'
  * An indicator if the sum equals 7
  gen Y`i'X`i'is7 = 0
  replace Y`i'X`i'is7 = 1 if X`i'plusY`i'==7
}

* If it is just you
gen no7_1 = 0
replace no7_1 = 1 if Y1X1is7 == 0

* If it is you and one other
gen no7_2 = 0
replace no7_2 = 1 if Y1X1is7 == 0 & Y2X2is7 == 0

* If it is you and two others
gen no7_3 = 0
replace no7_3 = 1 if Y1X1is7 == 0 & Y2X2is7 == 0 & Y3X3is7 == 0


* If it is you and three others
gen no7_4 = 0
replace no7_4 = 1 if Y1X1is7 == 0 & Y2X2is7 == 0 & Y3X3is7 == 0 & Y4X4is7 == 0

sum
*  We can see that the simulation confirms about 48% is the probability that a 7 will be rolled.

No comments:

Post a Comment