How many instants/sorceries do you need to turn Ghitu Lavaru

Mar 12th, 2018
182
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package ghitulavarunner;
2.
3.         /*ASSUMPTIONS:
4.         - We consider a 60-deck with a 60-card deck with 24 lands, 4 Ghitu Lavarunner, and a certain number of spells.
5.     - We mulligan a hand if it contains 0, 1, 6, or 7 lands. In case of a mulligan, we ignore the free scry.
6.     - We assume that we are always able to cast any spell we draw. That is, the availability of colored mana to cast our spells is disregarded. This assumption is reasonable if the majority of our spells cost one or two mana. Suitably, those are exactly the type of spells that are ideal to support Ghitu Lavarunner.
7.     - We are on the play and on the draw with equal 50-50 probability.
8.     - We consider the following question: If I have a Ghitu Lavarunner in hand on turn 2 (or any other turn number to be manually adjusted in the SimulateGame function), then what is the probability of also having drawn two spells? In other words, we determine a conditional probability for settings where at least one of our cards (not necessarily the first one we draw) is already taken up by a Ghitu Lavarunner.
9.         */
10.
11. import java.util.Arrays.*;
12. import java.util.Random;
13.
14. public class GhituLavarunner{
15.
16.     public static void main(String[] args) {
17.
18.         Deck deck=new Deck();
19.
20.         //CardType 1 is a land
21.         //CardType 2 is a Ghitu Lavarunner
22.         //CardType 3 is a spell
23.         //CardType 4 is not used
24.         //CardType 5 is another card
25.
26.
27.
28.         for (int NrSpells=9; NrSpells<=26; NrSpells++){
29.             deck.SetDeck(24,4,NrSpells,0,60-28-NrSpells);
30.             double Probability=ProbabilityForRandomHand(deck,7,10000000);
31.             //System.out.print("Probability of having a legend in games where you have a Mox Amber after mulls in a deck with "+NrLegends+" legends: ");
32.             System.out.println(Math.round(Probability*10000)/100.0);
33.         }
34.
35.     }//end of main
36.
37.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
38.         Deck remainingdeck=new Deck();
39.         double NumberOfGamesWithfavorableOutcome=0;
40.         double NumberOfGamesWithSpellMastery=0;
41.         //On the play
42.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
43.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
44.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
45.
46.             int Outcome=SimulateGame(remainingdeck,openinghand,true);
47.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithSpellMastery++;}
48.             if (Outcome==1) {NumberOfGamesWithSpellMastery++;}
49.         }
50.         //On the draw; this is a copy-paste where the only change is that the boolean is now false
51.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
52.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
53.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
54.             int Outcome=SimulateGame(remainingdeck,openinghand,false);
55.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithSpellMastery++;}
56.             if (Outcome==1) {NumberOfGamesWithSpellMastery++;}
57.         }
58.
59.         return NumberOfGamesWithfavorableOutcome/(NumberOfGamesWithSpellMastery+0.0);
60.     }//end of AverageKillTurnForRandomHand
61.
62.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
63.
64.         Deck remainingdeck=new Deck();
65.         OpeningHand openinghand=new OpeningHand();
66.         int TypeOfCardDrawn;
67.         boolean KeepHand=false;
68.
69.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
70.             if (KeepHand==false){
71.                 openinghand.SetHand(0,0,0,0,0);
72.                 remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
73.                 int NumberOfLands=0;
74.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
75.                     TypeOfCardDrawn=remainingdeck.DrawCard();
76.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
77.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
78.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
79.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
80.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
81.                 }
82.                 KeepHand=true;
83.                 if (OpeningHandSize>1) {
84.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
85.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
86.                     //
87.                 }
88.             }
89.         }
90.
91.         return openinghand;
92.     }//end of GiveOpeningHandAfterMulls
93.
94.
95.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, boolean OnThePlay) {
96.
97.         //Initializing
98.         int TypeOfCardDrawn=0;
99.         int Outcome=2;
100.         int Turn=4;
101.
102.         int GhituLavarunnerInHand=openinghand.NumberOfCardType2;
103.         int SpellInHand=openinghand.NumberOfCardType3;
104.
105.         //Turn 1
106.
107.         if (OnThePlay==false) {
108.                 TypeOfCardDrawn=remainingdeck.DrawCard();
109.                 if (TypeOfCardDrawn==2) {GhituLavarunnerInHand++;}
110.                 if (TypeOfCardDrawn==3) {SpellInHand++;}
111.             }
112.
113.         //Turn 2
114.
115.         if (Turn>=2){
116.             TypeOfCardDrawn=remainingdeck.DrawCard();
117.             if (TypeOfCardDrawn==2) {GhituLavarunnerInHand++;}
118.             if (TypeOfCardDrawn==3) {SpellInHand++;}
119.         }
120.
121.         //Turn 3
122.
123.         if (Turn>=3){
124.             TypeOfCardDrawn=remainingdeck.DrawCard();
125.             if (TypeOfCardDrawn==2) {GhituLavarunnerInHand++;}
126.             if (TypeOfCardDrawn==3) {SpellInHand++;}
127.         }
128.
129.         //Turn 4
130.
131.         if (Turn>=4){
132.             TypeOfCardDrawn=remainingdeck.DrawCard();
133.             if (TypeOfCardDrawn==2) {GhituLavarunnerInHand++;}
134.             if (TypeOfCardDrawn==3) {SpellInHand++;}
135.         }
136.
137.         if (GhituLavarunnerInHand>=1 && SpellInHand>=2) {Outcome=0;}
138.         if (GhituLavarunnerInHand>=1 && SpellInHand<2) {Outcome=1;}
139.
140.         return Outcome;
141.     }//end of SimulateGame
142.
143. }
144.
145. class OpeningHand {
146.     int NumberOfLands;
147.     int NumberOfCardType2;
148.     int NumberOfCardType3;
149.     int NumberOfCardType4;
150.     int NumberOfSpells;
151.
152.     int NrOfCards(){
153.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
154.     }
155.
156.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
157.         NumberOfLands=Nr1;
158.         NumberOfCardType2=Nr2;
159.         NumberOfCardType3=Nr3;
160.         NumberOfCardType4=Nr4;
161.         NumberOfSpells=Nr5;
162.     }
163.
164. }//end of OpeningHand
165.
166. class Deck {
167.     int NumberOfLands;
168.     int NumberOfCardType2;
169.     int NumberOfCardType3;
170.     int NumberOfCardType4;
171.     int NumberOfSpells;
172.
173.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
174.         NumberOfLands=Nr1;
175.         NumberOfCardType2=Nr2;
176.         NumberOfCardType3=Nr3;
177.         NumberOfCardType4=Nr4;
178.         NumberOfSpells=Nr5;
179.     }
180.
181.     int NrOfCards(){
182.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
183.     }
184.
185.     int DrawCard (){
186.         Random generator = new Random();
187.         int CardType=0;
188.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
189.         int OneCutoff=NumberOfLands;
190.         int TwoCutoff=OneCutoff+NumberOfCardType2;
191.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
192.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
193.         int FiveCutoff=FourCutoff+NumberOfSpells;
194.
195.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfLands--;}
196.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
197.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
198.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
199.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
200.         return CardType;
201.     }
202.
203. }//end of Deck
RAW Paste Data