# How often will a shadow land played on turns 1-3 be untapped

Mar 27th, 2016
102
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.                 Probability=ProbabilityForRandomHand(deck,7,10000000,0);
28.                 System.out.println("Probability that an arbitrary shadow land that actually entered the battlefield anywhere on the first three turns is untapped: "+ Math.round(Probability*10000)/100.0);
29.
30.             System.out.println();
31.
32.         }
33.
34.     }//end of main
35.
36.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
37.         //ProbabilityType T: Probability that a Shadow land on turn T would enter the battlefield untapped (outcome: 0=tapped, 1=untapped)
38.
39.         Deck remainingdeck=new Deck();
42.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
43.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
45.             Outcome outcome_of_one_game=SimulateGame(remainingdeck,openinghand,ProbabilityType);
48.         }
50.     }
51.
52.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
53.
54.         Deck remainingdeck=new Deck();
55.         OpeningHand openinghand=new OpeningHand();
56.         int TypeOfCardDrawn;
57.         boolean KeepHand=false;
58.
59.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
60.             if (KeepHand==false){
61.                 openinghand.SetHand(0,0,0,0,0);
63.                 int NumberOfLands=0;
64.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
65.                     TypeOfCardDrawn=remainingdeck.DrawCard();
67.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
68.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
69.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfNonLandCards++;}
70.                     if (TypeOfCardDrawn==5) {openinghand.NotUsed++;}
71.                 }
72.                 KeepHand=true;
73.                 if (OpeningHandSize>1) {
74.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
75.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
76.                     //
77.                 }
78.             }
79.         }
80.
81.         return openinghand;
82.     }//end of GiveOpeningHandAfterMulls
83.
84.
85.     static Outcome SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
86.
87.         Outcome outcome_of_one_game=new Outcome();
88.         int TypeOfCardDrawn;
89.
91.         int BasicLandsInHand=openinghand.NumberOfBasicLands;
92.         int OtherLandsInHand=openinghand.NumberOfOtherLands;
93.
94.         for (int Turn=1; Turn<=3; Turn++){
95.
96.             if (Turn>1) {
97.                 TypeOfCardDrawn=remainingdeck.DrawCard();
99.                 if (TypeOfCardDrawn==2) {BasicLandsInHand++;}
100.                 if (TypeOfCardDrawn==3) {OtherLandsInHand++;}
101.             }
102.             boolean LandPlayed=false;
103.
104.             //1. If we can play an untapped Shadow land, we do so.
105.             if (BasicLandsInHand>=1 && ShadowLandsInHand>=1) {
107.                 LandPlayed=true;
110.             }
111.
112.             //2. Otherwise, if we can play an other land, we do so.
113.             if (LandPlayed==false && OtherLandsInHand>=1) {
114.                 OtherLandsInHand--;
115.                 LandPlayed=true;
116.             }
117.
118.             //3.  Otherwise, if we can play a tapped Shadow land, we do so.
119.             if (LandPlayed==false && BasicLandsInHand==0 && ShadowLandsInHand>=1) {
121.                 LandPlayed=true;
123.             }
124.
125.             //4. Otherwise, finally, if we can play a basic land, we do so.
126.             if (LandPlayed==false && BasicLandsInHand>=1) {
127.                 BasicLandsInHand--;
128.                 LandPlayed=true;
129.             }
130.
131.         }//end of the for-loop over the turns
132.
133.         return outcome_of_one_game;
134.
135.     }//end of SimulateGame
136.
137.
138. }
139.
140. class Outcome {
143.
144.     void setOutcome(int i, int j){
147.     }
148. }
149.
150. class OpeningHand {
152.     int NumberOfBasicLands;
153.     int NumberOfOtherLands;
154.     int NumberOfNonLandCards;
155.     int NotUsed;
156.
157.     int NrOfCards(){
159.     }
160.
161.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
163.         NumberOfBasicLands=Nr2;
164.         NumberOfOtherLands=Nr3;
165.         NumberOfNonLandCards=Nr4;
166.         NotUsed=Nr5;
167.     }
168.
169. }//end of OpeningHand
170.
171. class Deck {
173.     int NumberOfBasicLands;
174.     int NumberOfOtherLands;
175.     int NumberOfNonLandCards;
176.     int NotUsed;
177.
178.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
180.         NumberOfBasicLands=Nr2;
181.         NumberOfOtherLands=Nr3;
182.         NumberOfNonLandCards=Nr4;
183.         NotUsed=Nr5;
184.     }
185.
186.     int NrOfCards(){
188.     }
189.
190.     int DrawCard (){
191.         Random generator = new Random();
192.         int CardType=0;
193.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
195.         int TwoCutoff=OneCutoff+NumberOfBasicLands;
196.         int ThreeCutoff=TwoCutoff+NumberOfOtherLands;
197.         int FourCutoff=ThreeCutoff+NumberOfNonLandCards;
198.         int FiveCutoff=FourCutoff+NotUsed;
199.