# How many Legends do you need for a Legendary sorcery?

Apr 16th, 2018
228
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package legendarysorcery;
2.
3. import java.util.Arrays.*;
4. import java.util.Random;
5.
6. public class LegendarySorcery{
7.
8.     public static void main(String[] args) {
9.
10.         Deck deck=new Deck();
11.
12.         //CardType 1 is a land
13.         //CardType 2 is a legendary sorcery
14.         //CardType 3 is a legend
15.         //CardType 4 is not used
16.         //CardType 5 is another card
17.
18.
19.         for (int NrLegends=8; NrLegends<=26; NrLegends++){
20.             deck.SetDeck(25,4,NrLegends,0,60-29-NrLegends);
21.             double Probability=ProbabilityForRandomHand(deck,7,10000000);
22.             //System.out.print("Probability of having a legend in games where you have a legendary sorcery and enough lands on turn 6 after mulls in a deck with "+NrLegends+" legends: ");
23.             System.out.println(Math.round(Probability*10000)/100.0);
24.         }
25.
26.     }//end of main
27.
28.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
29.         Deck remainingdeck=new Deck();
30.         double NumberOfGamesWithfavorableOutcome=0;
31.         double NumberOfGamesWithSorcery=0; //These are the games where you have a legendary sorcery in hand on turn 6 and at least five lands
32.         //On the play
33.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
34.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
35.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
36.
37.             int Outcome=SimulateGame(remainingdeck,openinghand,true);
38.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithSorcery++;}
39.             if (Outcome==1) {NumberOfGamesWithSorcery++;}
40.         }
41.         //On the draw; this is a copy-paste where the only change is that the boolean is now false
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.             int Outcome=SimulateGame(remainingdeck,openinghand,false);
46.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithSorcery++;}
47.             if (Outcome==1) {NumberOfGamesWithSorcery++;}
48.         }
49.
50.         return NumberOfGamesWithfavorableOutcome/(NumberOfGamesWithSorcery+0.0);
51.     }//end of AverageKillTurnForRandomHand
52.
53.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
54.
55.         Deck remainingdeck=new Deck();
56.         OpeningHand openinghand=new OpeningHand();
57.         int TypeOfCardDrawn;
58.         boolean KeepHand=false;
59.
60.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
61.             if (KeepHand==false){
62.                 openinghand.SetHand(0,0,0,0,0);
63.                 remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
64.                 int NumberOfLands=0;
65.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
66.                     TypeOfCardDrawn=remainingdeck.DrawCard();
67.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
68.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
69.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
70.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
71.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
72.                 }
73.                 KeepHand=true;
74.                 if (OpeningHandSize>1) {
75.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
76.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
77.                     //
78.                 }
79.             }
80.         }
81.
82.         return openinghand;
83.     }//end of GiveOpeningHandAfterMulls
84.
85.
86.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, boolean OnThePlay) {
87.
88.         //Initializing
89.         int TypeOfCardDrawn=0;
90.         int Outcome=2;
91.         int Turn;
92.         int NrOpposingRemovalSpells=2;
93.
94.         int LandInHand=openinghand.NumberOfLands;
95.         int SorceryInHand=openinghand.NumberOfCardType2;
96.         int LegendInHand=openinghand.NumberOfCardType3;
97.
98.         //Turn 1
99.
100.         if (OnThePlay==false) {
101.                 TypeOfCardDrawn=remainingdeck.DrawCard();
102.                 if (TypeOfCardDrawn==1) {LandInHand++;}
103.                 if (TypeOfCardDrawn==2) {SorceryInHand++;}
104.                 if (TypeOfCardDrawn==3) {LegendInHand++;}
105.             }
106.
107.         for (Turn=2; Turn<=5; Turn++){
108.             TypeOfCardDrawn=remainingdeck.DrawCard();
109.             if (TypeOfCardDrawn==1) {LandInHand++;}
110.             if (TypeOfCardDrawn==2) {SorceryInHand++;}
111.             if (TypeOfCardDrawn==3) {LegendInHand++;}
112.         }
113.
114.         boolean WeHaveEnoughLegends=false;
115.         if (LegendInHand>NrOpposingRemovalSpells) {WeHaveEnoughLegends=true;}
116.
117.         //Turn 6
118.
119.         TypeOfCardDrawn=remainingdeck.DrawCard();
120.         if (TypeOfCardDrawn==1) {LandInHand++;}
121.         if (TypeOfCardDrawn==2) {SorceryInHand++;}
122.
123.         boolean WeHaveEnoughLands=false;
124.         if (LandInHand>=5) {WeHaveEnoughLands=true;}
125.
126.         boolean WeHoldTheSorcery=false;
127.         if (SorceryInHand>=1) {WeHoldTheSorcery=true;}
128.
129.         if (WeHaveEnoughLands && WeHoldTheSorcery && WeHaveEnoughLegends) {Outcome=0;}
130.         if (WeHaveEnoughLands && WeHoldTheSorcery && !WeHaveEnoughLegends) {Outcome=1;}
131.
132.         return Outcome;
133.     }//end of SimulateGame
134.
135. }
136.
137. class OpeningHand {
138.     int NumberOfLands;
139.     int NumberOfCardType2;
140.     int NumberOfCardType3;
141.     int NumberOfCardType4;
142.     int NumberOfSpells;
143.
144.     int NrOfCards(){
145.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
146.     }
147.
148.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
149.         NumberOfLands=Nr1;
150.         NumberOfCardType2=Nr2;
151.         NumberOfCardType3=Nr3;
152.         NumberOfCardType4=Nr4;
153.         NumberOfSpells=Nr5;
154.     }
155.
156. }//end of OpeningHand
157.
158. class Deck {
159.     int NumberOfLands;
160.     int NumberOfCardType2;
161.     int NumberOfCardType3;
162.     int NumberOfCardType4;
163.     int NumberOfSpells;
164.
165.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
166.         NumberOfLands=Nr1;
167.         NumberOfCardType2=Nr2;
168.         NumberOfCardType3=Nr3;
169.         NumberOfCardType4=Nr4;
170.         NumberOfSpells=Nr5;
171.     }
172.
173.     int NrOfCards(){
174.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
175.     }
176.
177.     int DrawCard (){
178.         Random generator = new Random();
179.         int CardType=0;
180.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
181.         int OneCutoff=NumberOfLands;
182.         int TwoCutoff=OneCutoff+NumberOfCardType2;
183.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
184.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
185.         int FiveCutoff=FourCutoff+NumberOfSpells;
186.
187.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfLands--;}
188.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
189.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
190.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
191.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
192.         return CardType;
193.     }
194.
195. }//end of Deck
RAW Paste Data