# How often do you have 2 basics for battle lands?

Mar 28th, 2016
334
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package battlelands;
2.
3. import java.util.Arrays.*;
4. import java.util.Random;
5.
6. public class BattleLands {
7.
8.     public static void main(String[] args) {
9.
10.         Deck deck=new Deck();
11.
12.         //CardType 1 is a Battle land
13.         //CardType 2 used to be a fetch-land, which is now not used anymore and set to 0
14.         //CardType 3 is a basic land (or Evolving Wilds)
15.         //CardType 4 is another land (e.g., man-land or pain-land)
16.         //CardType 5 is a non-land card
17.
18.         for (int basics=1; basics<=20; basics++){
19.
20.             System.out.println("=================================================");
21.             System.out.println("We now consider a deck with "+basics+" basic lands");
22.             System.out.println("=================================================");
23.
24.             //The first output line give the percentage probability that a Battle land which would be played on turn 3 enters tapped.
25.             //The second output line give the percentage probability that a Battle land which would be played on turn 4 enters tapped.
26.             //The third output line give the percentage probability that a Battle land which would be played on turn 5 enters tapped.
27.
28.             deck.SetDeck(4,0,basics,21-basics,35);
29.             double Probability;
30.
31.             for (int turn=3; turn<=5; turn++){
32.                 Probability=ProbabilityForRandomHand(deck,7,1000000,turn);
33.                 System.out.println(Math.round(Probability*10000)/100.0);
34.             }
35.         }
36.
37.     }//end of main
38.
39.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
40.         //ProbabilityType 3: Probability that you have at least 2 basics in play at the start of turn 3 (outcome: 0=yes 2 basics, 1=no not enough basics)
41.         //ProbabilityType 4: Probability that you have at least 2 basics in play at the start of turn 4 (outcome: 0=yes 2 basics, 1=no not enough basics)
42.         //ProbabilityType 5: Probability that you have at least 2 basics in play at the start of turn 5 (outcome: 0=yes 2 basics, 1=no not enough basics)
43.
44.         Deck remainingdeck=new Deck();
45.         double NumberOfRelevantGames=0;
46.         double NumberOfGamesWithUnfavorableOutcome=0;
47.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
48.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
49.             remainingdeck.SetDeck(deck.NumberOfBattleLands-openinghand.NumberOfBattleLands,deck.NumberOfFetchLands-openinghand.NumberOfFetchLands,deck.NumberOfBasicLands-openinghand.NumberOfBasicLands,deck.NumberOfOtherLands-openinghand.NumberOfOtherLands,deck.NumberOfSpells-openinghand.NumberOfSpells);
50.             int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
51.             if (Outcome<2) {NumberOfRelevantGames++;} //This is currently not used
52.             if (Outcome==1) {NumberOfGamesWithUnfavorableOutcome++;}
53.         }
54.         return NumberOfGamesWithUnfavorableOutcome/(NumberOfRelevantGames+0.0);
55.     }//end of AverageKillTurnForRandomHand
56.
57.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
58.
59.         Deck remainingdeck=new Deck();
60.         OpeningHand openinghand=new OpeningHand();
61.         int TypeOfCardDrawn;
62.         boolean KeepHand=false;
63.
64.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
65.             if (KeepHand==false){
66.                 openinghand.SetHand(0,0,0,0,0);
67.                 remainingdeck.SetDeck(deck.NumberOfBattleLands,deck.NumberOfFetchLands,deck.NumberOfBasicLands,deck.NumberOfOtherLands,deck.NumberOfSpells);
68.                 int NumberOfLands=0;
69.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
70.                     TypeOfCardDrawn=remainingdeck.DrawCard();
71.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfBattleLands++; NumberOfLands++;}
72.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfFetchLands++; NumberOfLands++;}
73.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
74.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
75.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
76.                 }
77.                 KeepHand=true;
78.                 if (OpeningHandSize>1) {
79.                     // We mulligan a hand if it contains 0, 1, 5, 6, or 7 lands
80.                     if (NumberOfLands<=1 || NumberOfLands>=5) {KeepHand=false;}
81.                     //
82.                 }
83.             }
84.         }
85.
86.         return openinghand;
87.     }//end of GiveOpeningHandAfterMulls
88.
89.
90.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
91.
92.         int TypeOfCardDrawn=0;
93.         int BasicsInPlay=0;
94.         int Outcome=2;
95.         boolean GotABattleLandThisTurn=false;
96.         boolean ThisLandEnteredTapped=false;
97.         boolean EnoughBasicsAtStartTurn=false;
98.
99.         int BattleLandsInHand=openinghand.NumberOfBattleLands;
100.         int FetchLandsInHand=openinghand.NumberOfFetchLands;
101.         int BasicLandsInHand=openinghand.NumberOfBasicLands;
102.         int OtherLandsInHand=openinghand.NumberOfOtherLands;
103.         int SpellsInHand=openinghand.NumberOfSpells;
104.
105.         for (int Turn=1; Turn<=5; Turn++){
106.             if (Turn>1) {
107.                 TypeOfCardDrawn=remainingdeck.DrawCard();
108.                 if (TypeOfCardDrawn==1) {BattleLandsInHand++;}
109.                 if (TypeOfCardDrawn==2) {FetchLandsInHand++;}
110.                 if (TypeOfCardDrawn==3) {BasicLandsInHand++;}
111.                 if (TypeOfCardDrawn==4) {OtherLandsInHand++;}
112.                 if (TypeOfCardDrawn==5) {SpellsInHand++;}
113.             }
114.             boolean LandPlayed=false;
115.
116.             if (Turn==ProbabilityType && BasicsInPlay>=2) {EnoughBasicsAtStartTurn=true;}
117.
118.             //1. If there are >=2 basics in play and you can play a Battle land from hand, then do so
119.             if (BasicsInPlay>=2 && BattleLandsInHand>=1) {
120.                 BattleLandsInHand--;
121.                 if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=false;}
122.                 LandPlayed=true;
123.             }
124.
125.             //3. Otherwise, if you can play a basic from hand, then do so
126.             if (LandPlayed==false && BasicLandsInHand>=1) {
127.                 BasicLandsInHand--;
128.                 BasicsInPlay++;
129.                 LandPlayed=true;
130.             }
131.
132.             //5. Otherwise, play another land
133.             if (LandPlayed==false && OtherLandsInHand>=1) {
134.                 OtherLandsInHand--;
135.                 LandPlayed=true;
136.             }
137.
138.             //6. Otherwise, play a Battle land
139.             if (LandPlayed==false && BattleLandsInHand>=1) {
140.                 BattleLandsInHand--;
141.                 if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=true;}
142.             }
143.         }//end of the for-loop over the turns
144.
145.         if (ProbabilityType>=3 && EnoughBasicsAtStartTurn) {Outcome=0;}
146.         if (ProbabilityType>=3 && !EnoughBasicsAtStartTurn) {Outcome=1;}
147.
148.         return Outcome;
149.
150.     }//end of SimulateGame
151.
152. }
153.
154. class OpeningHand {
155.     int NumberOfBattleLands;
156.     int NumberOfFetchLands;
157.     int NumberOfBasicLands;
158.     int NumberOfOtherLands;
159.     int NumberOfSpells;
160.
161.     int NrOfCards(){
162.         return NumberOfBattleLands+NumberOfFetchLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfSpells;
163.     }
164.
165.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
166.         NumberOfBattleLands=Nr1;
167.         NumberOfFetchLands=Nr2;
168.         NumberOfBasicLands=Nr3;
169.         NumberOfOtherLands=Nr4;
170.         NumberOfSpells=Nr5;
171.     }
172.
173. }//end of OpeningHand
174.
175. class Deck {
176.     int NumberOfBattleLands;
177.     int NumberOfFetchLands;
178.     int NumberOfBasicLands;
179.     int NumberOfOtherLands;
180.     int NumberOfSpells;
181.
182.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
183.         NumberOfBattleLands=Nr1;
184.         NumberOfFetchLands=Nr2;
185.         NumberOfBasicLands=Nr3;
186.         NumberOfOtherLands=Nr4;
187.         NumberOfSpells=Nr5;
188.     }
189.
190.     int NrOfCards(){
191.         return NumberOfBattleLands+NumberOfFetchLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfSpells;
192.     }
193.
194.     int DrawCard (){
195.         Random generator = new Random();
196.         int CardType=0;
197.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
198.         int OneCutoff=NumberOfBattleLands;
199.         int TwoCutoff=OneCutoff+NumberOfFetchLands;
200.         int ThreeCutoff=TwoCutoff+NumberOfBasicLands;
201.         int FourCutoff=ThreeCutoff+NumberOfOtherLands;
202.         int FiveCutoff=FourCutoff+NumberOfSpells;
203.
204.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfBattleLands--;}
205.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfFetchLands--;}
206.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfBasicLands--;}
207.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfOtherLands--;}
208.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
209.         return CardType;
210.     }
211.
212. }//end of Deck
RAW Paste Data