• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Likelihood that check-lands will enter untapped

frankkarsten Sep 11th, 2017 (edited) 587 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package checklands;
2.
3. import java.util.Arrays.*;
4. import java.util.Random;
5.
6. public class CheckLands {
7.
8.     public static void main(String[] args) {
9.
10.         Deck deck=new Deck();
11.
12.         //CardType 1 is a proper-type land
13.         //CardType 2 is a check-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(basics,4,21-basics,35,0);
21.             double Probability;
22.
23.             System.out.println("=================================================");
24.             System.out.println("We now consider a deck with "+basics+" proper-type lands");
25.             System.out.println("=================================================");
26.
27.             //The first output line give the percentage probability that a check-land would enter the battlefield untapped on turn 1.
28.             //The second output line gives the percentage probability that a check-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,10000000,Turn);
33.                 //System.out.println("Probability that, if you have a check-land in hand on turn "+Turn+" and decide to play it, it will enter untapped: "+ Math.round(Probability*10000)/100.0);
34.                 System.out.println(Math.round(Probability*10000)/100.0);
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.         Deck remainingdeck=new Deck();
44.         int NumberOfGamesWherePlayingCheckLandIsPossibleOnTurn=0;
45.         int NumberOfGamesWithUNTAPPEDCheckLandOnTurn=0;
46.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
47.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
48.             remainingdeck.SetDeck(deck.NumberOfBasicLands-openinghand.NumberOfBasicLands,deck.NumberOfCheckLands-openinghand.NumberOfCheckLands,deck.NumberOfOtherLands-openinghand.NumberOfOtherLands,deck.NumberOfNonLandCards-openinghand.NumberOfNonLandCards,deck.NotUsed-openinghand.NotUsed);
49.             int outcome_of_one_game=SimulateGame(remainingdeck,openinghand,ProbabilityType);
50.             if (outcome_of_one_game==1) {NumberOfGamesWherePlayingCheckLandIsPossibleOnTurn++; NumberOfGamesWithUNTAPPEDCheckLandOnTurn++;}
51.             if (outcome_of_one_game==2) {NumberOfGamesWherePlayingCheckLandIsPossibleOnTurn++;}
52.         }
53.         return NumberOfGamesWithUNTAPPEDCheckLandOnTurn/(NumberOfGamesWherePlayingCheckLandIsPossibleOnTurn+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);
66.                 remainingdeck.SetDeck(deck.NumberOfBasicLands,deck.NumberOfCheckLands,deck.NumberOfOtherLands,deck.NumberOfNonLandCards,deck.NotUsed);
67.                 int NumberOfLands=0;
68.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
69.                     TypeOfCardDrawn=remainingdeck.DrawCard();
70.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
71.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCheckLands++; 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;
92.         int Outcome=3;
93.
94.         int CheckLandsInHand=openinghand.NumberOfCheckLands;
95.         int BasicLandsInHand=openinghand.NumberOfBasicLands;
96.         int OtherLandsInHand=openinghand.NumberOfOtherLands;
97.         boolean BasicInPlay=false;
98.
99.         for (int Turn=1; Turn<=7; Turn++){
100.
101.             if (Turn>1) {
102.                 TypeOfCardDrawn=remainingdeck.DrawCard();
103.                 if (TypeOfCardDrawn==1) {BasicLandsInHand++;}
104.                 if (TypeOfCardDrawn==2) {CheckLandsInHand++;}
105.                 if (TypeOfCardDrawn==3) {OtherLandsInHand++;}
106.             }
107.             boolean LandPlayed=false;
108.
109.             if (Turn==ProbabilityType){
110.                 if (CheckLandsInHand==0) {Outcome=3;}
111.                 if (CheckLandsInHand>=1) {
112.                     CheckLandsInHand--;
113.                     LandPlayed=true;
114.                     if (BasicInPlay) {Outcome=1;}
115.                     if (!BasicInPlay) {Outcome=2;}
116.                 }
117.             }
118.
119.             //1. If we can play a basic-type land, we do so.
120.             if (LandPlayed==false && BasicLandsInHand>=1) {
121.                 BasicLandsInHand--;
122.                 LandPlayed=true;
123.                 BasicInPlay=true;
124.             }
125.
126.             //2. Otherwise, if we can play an other land, we do so.
127.             if (LandPlayed==false && OtherLandsInHand>=1) {
128.                 OtherLandsInHand--;
129.                 LandPlayed=true;
130.             }
131.
132.             //3.  Otherwise, if we can play a check-land, we do so.
133.             if (LandPlayed==false && CheckLandsInHand>=1) {
134.                 CheckLandsInHand--;
135.                 LandPlayed=true;
136.             }
137.
138.         }//end of the for-loop over the turns
139.
140.         return Outcome;
141.
142.     }//end of SimulateGame
143.
144.
145. }
146.
147. class OpeningHand {
148.     int NumberOfBasicLands;
149.     int NumberOfCheckLands;
150.     int NumberOfOtherLands;
151.     int NumberOfNonLandCards;
152.     int NotUsed;
153.
154.     int NrOfCards(){
155.         return NumberOfBasicLands+NumberOfCheckLands+NumberOfOtherLands+NumberOfNonLandCards+NotUsed;
156.     }
157.
158.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
159.         NumberOfBasicLands=Nr1;
160.         NumberOfCheckLands=Nr2;
161.         NumberOfOtherLands=Nr3;
162.         NumberOfNonLandCards=Nr4;
163.         NotUsed=Nr5;
164.     }
165.
166. }//end of OpeningHand
167.
168. class Deck {
169.     int NumberOfBasicLands;
170.     int NumberOfCheckLands;
171.     int NumberOfOtherLands;
172.     int NumberOfNonLandCards;
173.     int NotUsed;
174.
175.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
176.         NumberOfBasicLands=Nr1;
177.         NumberOfCheckLands=Nr2;
178.         NumberOfOtherLands=Nr3;
179.         NumberOfNonLandCards=Nr4;
180.         NotUsed=Nr5;
181.     }
182.
183.     int NrOfCards(){
184.         return NumberOfBasicLands+NumberOfCheckLands+NumberOfOtherLands+NumberOfNonLandCards+NotUsed;
185.     }
186.
187.     int DrawCard (){
188.         Random generator = new Random();
189.         int CardType=0;
190.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
191.         int OneCutoff=NumberOfBasicLands;
192.         int TwoCutoff=OneCutoff+NumberOfCheckLands;
193.         int ThreeCutoff=TwoCutoff+NumberOfOtherLands;
194.         int FourCutoff=ThreeCutoff+NumberOfNonLandCards;
195.         int FiveCutoff=FourCutoff+NotUsed;
196.
197.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfBasicLands--;}
198.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCheckLands--;}
199.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfOtherLands--;}
200.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfNonLandCards--;}
201.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NotUsed--;}
202.         return CardType;
203.     }
204.
205. }//end of Deck
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top