# How often would you have a basic-type for a shadow land?

Mar 27th, 2016
965
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
2.
3. import java.util.Arrays.*;
4. import java.util.Random;
5.
7.
8.     public static void main(String[] args) {
9.
10.         Deck deck=new Deck();
11.
12.         //CardType 1 is a Shadow land
13.         //CardType 2 is a basic land (or Battle land) with the correct basic land type for the Shadow land
14.         //CardType 3 is another land (e.g., creature-land or pain-land)
15.         //CardType 4 is a non-land card
16.         //CardType 5 is not used
17.
18.         for (int basics=1; basics<=20; basics++){
19.
20.             deck.SetDeck(4,basics,21-basics,35,0);
21.             double Probability;
22.
23.             System.out.println("=================================================");
24.             System.out.println("We now consider a deck with "+basics+" basic-type lands");
25.             System.out.println("=================================================");
26.
27.             //The first output line give the percentage probability that a shadow land would enter the battlefield untapped on turn 1.
28.             //The second output line gives the percentage probability that a shadow land would enter the battlefield untapped on turn 2.
29.             //Etc.
30.
31.             for (int turn=1; turn<=7; turn++){
32.                 Probability=ProbabilityForRandomHand(deck,7,1000000,turn);
33.                 System.out.println(Math.round(Probability*10000)/100.0);
34.                 }
35.
36.             System.out.println();
37.
38.         }
39.
40.     }//end of main
41.
42.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
43.         //ProbabilityType T: Probability that a Shadow land on turn T would enter the battlefield untapped (outcome: 0=tapped, 1=untapped)
44.
45.         Deck remainingdeck=new Deck();
46.         double NumberOfGamesWithFavorableOutcome=0;
47.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
48.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
50.             int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
51.             if (Outcome==1) {NumberOfGamesWithFavorableOutcome++;}
52.         }
53.         return NumberOfGamesWithFavorableOutcome/(NumberOfIterations+0.0);
54.     }
55.
56.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
57.
58.         Deck remainingdeck=new Deck();
59.         OpeningHand openinghand=new OpeningHand();
60.         int TypeOfCardDrawn;
61.         boolean KeepHand=false;
62.
63.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
64.             if (KeepHand==false){
65.                 openinghand.SetHand(0,0,0,0,0);
67.                 int NumberOfLands=0;
68.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
69.                     TypeOfCardDrawn=remainingdeck.DrawCard();
71.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
72.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
73.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfNonLandCards++;}
74.                     if (TypeOfCardDrawn==5) {openinghand.NotUsed++;}
75.                 }
76.                 KeepHand=true;
77.                 if (OpeningHandSize>1) {
78.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
79.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
80.                     //
81.                 }
82.             }
83.         }
84.
85.         return openinghand;
86.     }//end of GiveOpeningHandAfterMulls
87.
88.
89.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
90.
91.         int TypeOfCardDrawn=0;
92.         int Outcome=2;
94.         boolean ThisLandEnteredTapped=false;
95.         boolean BasicLandInHandAtStartFirstMainPhase=false;
96.
98.         int BasicLandsInHand=openinghand.NumberOfBasicLands;
99.         int OtherLandsInHand=openinghand.NumberOfOtherLands;
100.
101.         for (int Turn=1; Turn<=7; Turn++){
102.
103.             if (Turn>1) {
104.                 TypeOfCardDrawn=remainingdeck.DrawCard();
106.                 if (TypeOfCardDrawn==2) {BasicLandsInHand++;}
107.                 if (TypeOfCardDrawn==3) {OtherLandsInHand++;}
108.             }
109.             boolean LandPlayed=false;
110.
111.             if (Turn==ProbabilityType && BasicLandsInHand>=1) {BasicLandInHandAtStartFirstMainPhase=true;}
112.
113.             //1. If we can play an untapped Shadow land, we do so.
114.             if (BasicLandsInHand>=1 && ShadowLandsInHand>=1) {
116.                 LandPlayed=true;
117.             }
118.
119.             //2. Otherwise, if we can play an other land, we do so.
120.             if (LandPlayed==false && OtherLandsInHand>=1) {
121.                 OtherLandsInHand--;
122.                 LandPlayed=true;
123.             }
124.
125.             //3.  Otherwise, if we can play a tapped Shadow land, we do so.
126.             if (LandPlayed==false && BasicLandsInHand==0 && ShadowLandsInHand>=1) {
128.                 LandPlayed=true;
129.             }
130.
131.             //4. Otherwise, finally, if we can play a basic land, we do so.
132.             if (LandPlayed==false && BasicLandsInHand>=1) {
133.                 BasicLandsInHand--;
134.                 LandPlayed=true;
135.             }
136.
137.         }//end of the for-loop over the turns
138.
139.         if (!BasicLandInHandAtStartFirstMainPhase) {Outcome=0;}
140.         if (BasicLandInHandAtStartFirstMainPhase) {Outcome=1;}
141.
142.         return Outcome;
143.
144.     }//end of SimulateGame
145.
146. }
147.
148. class OpeningHand {
150.     int NumberOfBasicLands;
151.     int NumberOfOtherLands;
152.     int NumberOfNonLandCards;
153.     int NotUsed;
154.
155.     int NrOfCards(){
157.     }
158.
159.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
161.         NumberOfBasicLands=Nr2;
162.         NumberOfOtherLands=Nr3;
163.         NumberOfNonLandCards=Nr4;
164.         NotUsed=Nr5;
165.     }
166.
167. }//end of OpeningHand
168.
169. class Deck {
171.     int NumberOfBasicLands;
172.     int NumberOfOtherLands;
173.     int NumberOfNonLandCards;
174.     int NotUsed;
175.
176.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
178.         NumberOfBasicLands=Nr2;
179.         NumberOfOtherLands=Nr3;
180.         NumberOfNonLandCards=Nr4;
181.         NotUsed=Nr5;
182.     }
183.
184.     int NrOfCards(){
186.     }
187.
188.     int DrawCard (){
189.         Random generator = new Random();
190.         int CardType=0;
191.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
193.         int TwoCutoff=OneCutoff+NumberOfBasicLands;
194.         int ThreeCutoff=TwoCutoff+NumberOfOtherLands;
195.         int FourCutoff=ThreeCutoff+NumberOfNonLandCards;
196.         int FiveCutoff=FourCutoff+NotUsed;
197.