# Probability of drawing entire deck with Grishoalbrand

Jun 22nd, 2015
976
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package griselbrand;
2.
3. import java.util.Random;
4.
5. public class Griselbrand {
6.
7.     public static void main(String[] args) {
8.
9.         Deck deck=new Deck();
10.         int NrSims=10000000;
11.         //CardType1=Nourishing Shoal
12.         //CardType2=Worldspine Wurm
13.         //CardType3=other
14.             double TotalDrawDeck=0;
15.             double TotalDrawTill21=0;
16.             int Outcome;
17.             for (int i=1; i<=NrSims; i++){
18.                 deck.SetDeck(4,4,47,0,0,0);
19.                 //Deck size is 55 because the first 5 cards were fixed to be Faithless Looting, Goryo's Vengeance, Griselbrand, Mountain, Swamp
20.                 Outcome=Simulate(deck);
21.                 if (Outcome==1){TotalDrawTill21++;}
22.                 if (Outcome==2){TotalDrawTill21++; TotalDrawDeck++;}
23.             }
24.
25.             System.out.println("P[able to draw till 21]="+TotalDrawTill21/NrSims);
26.             System.out.println("P[able to draw entire deck]="+TotalDrawDeck/NrSims);
27.
28.     }//end of main
29.
30.
31.
32.      static int Simulate(Deck remainingdeck) {
33.         int Outcome=42; //What other number could we use to initialize
34.         int TypeOfCardDrawn;
35.
36.         boolean DrawPair=false;
37.         int NrShoalsFound=0;
38.         int NrWurmsFound=0;
39.         //Griselbrand activation 1 and 2, plus 6 additional non-combo cards from opening hand, draw steps, and Lootings. This means we have 20 cards to find the first life-gain pair.
40.         for (int i=1; i<=20; i++){
41.             TypeOfCardDrawn=remainingdeck.DrawCard();
42.             if (TypeOfCardDrawn==1) {NrShoalsFound++;}
43.             if (TypeOfCardDrawn==2) {NrWurmsFound++;}
44.         }
45.
46.         if (NrShoalsFound==0 || NrWurmsFound==0) {Outcome=0;}
47.
48.         if (NrShoalsFound>0 && NrWurmsFound>0) {
49.         //Griselbrand activation 3 and 4.
50.             for (int i=1; i<=14; i++){
51.                 TypeOfCardDrawn=remainingdeck.DrawCard();
52.                 if (TypeOfCardDrawn==1) {NrShoalsFound++;}
53.                 if (TypeOfCardDrawn==2) {NrWurmsFound++;}
54.             }
55.
56.             if (NrShoalsFound<=1 || NrWurmsFound<=1) {Outcome=1;}
57.
58.             if (NrShoalsFound>1 && NrWurmsFound>1) {
59.                 //Griselbrand activation 5.
60.                 for (int i=1; i<=7; i++){
61.                     TypeOfCardDrawn=remainingdeck.DrawCard();
62.                     if (TypeOfCardDrawn==1) {NrShoalsFound++;}
63.                     if (TypeOfCardDrawn==2) {NrWurmsFound++;}
64.                 }
65.
66.                 if (NrShoalsFound<=2 || NrWurmsFound<=2) {Outcome=1;}
67.
68.                 if (NrShoalsFound>2 && NrWurmsFound>2) {Outcome=2;}
69.             }
70.         }
71.         return Outcome;
72.     }
73.
74.
75. static class Deck {
76.     int NrCardType1;
77.     int NrCardType2;
78.     int NrCardType3;
79.     int NrCardType4;
80.     int NrCardType5;
81.     int NrCardType6;
82.
83.     void PrintDeckBrief () {
84.         if(NrCardType1<10) {System.out.print("0");}
85.         System.out.print(NrCardType1+" ");
86.         if(NrCardType2<10) {System.out.print("0");}
87.         System.out.print(NrCardType2+" ");
88.         if(NrCardType3<10) {System.out.print("0");}
89.         System.out.print(NrCardType3+" ");
90.         if(NrCardType4<10) {System.out.print("0");}
91.         System.out.print(NrCardType4+" ");
92.         if(NrCardType5<10) {System.out.print("0");}
93.         System.out.print(NrCardType5+" ");
94.         if(NrCardType6<10) {System.out.print("0");}
95.         System.out.print(NrCardType6);
96.         System.out.print(" ");
97.     }
98.
99.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
100.         NrCardType1=Nr1;
101.         NrCardType2=Nr2;
102.         NrCardType3=Nr3;
103.         NrCardType4=Nr4;
104.         NrCardType5=Nr5;
105.         NrCardType6=Nr6;
106.     }
107.
108.     int NrOfCards(){
109.         return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
110.     }
111.
112.     int DrawCard (){
113.             Random generator = new Random();
114.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
115.             int CardType=0;
116.             int OneCutoff=NrCardType1;
117.             int TwoCutoff=OneCutoff+NrCardType2;
118.             int ThreeCutoff=TwoCutoff+NrCardType3;
119.             int FourCutoff=ThreeCutoff+NrCardType4;
120.             int FiveCutoff=FourCutoff+NrCardType5;
121.             int SixCutoff=FiveCutoff+NrCardType6;
122.
123.             if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
124.             if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
125.             if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
126.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
127.             if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
128.             if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
129.             return CardType;
130.     }
131.
132. }
133. }
RAW Paste Data