Advertisement
frankkarsten

How many colored sources for gold cards?

Oct 4th, 2018
1,369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.16 KB | None | 0 0
  1. package howmanysourcesgoldcards;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class HowManySourcesGoldCards {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. Deck deck=new Deck();
  11. int NrIterations=1000000;
  12.  
  13. //Manually set the type of card that we're interested to cast here
  14. int NrGoodLandsNeededA=2;
  15. int NrGoodLandsNeededB=2;
  16. int TurnAllowed=4;
  17. //We will look for the probability of casting a spell with CMC TurnAllowed on turn TurnAllowed that requires NrGoodLandsNeeded (which is no larger than TurnAllowed) colored mana of a certain color in its cost.
  18. //For example, for a 2WW Wrath of God, we use TurnAllowed=4 and NrGoodLandsNeeded=2.
  19.  
  20. //Initialize the contents of the deck
  21. int NrCards=60;
  22. int NrOtherLands=0;
  23. int NrDuals=8;
  24. int NrGoodLandsA=8;
  25. int NrGoodLandsB=8;
  26. //Note that the final element needed to describe a deck (NrGoodLands) is set later, as we iterate over the various possible values
  27.  
  28. //Declare other variables
  29. int CardType; //Variable used to reference the type of card drawn from the deck
  30. int LandsInHand; //This will describe the total amount of lands in your hand
  31. int DualInHand;
  32. int GoodLandsInHandA; //This will describe the number of lands that can produce the right color in your hand
  33. int GoodLandsInHandB; //This will describe the number of lands that can produce the right color in your hand
  34. int StartingHandSize;
  35. boolean Mulligan;
  36. boolean GoodLandOnTopA;
  37. boolean GoodLandOnTopB;
  38. boolean DualOnTop;
  39.  
  40. double CountOK=0.0; //This will be the number of relevant games where you draw enough lands and the right colored sources
  41. double CountConditional=0.0; //This will be the number of relevant games where you draw enough lands
  42.  
  43. for (int i=1; i<=NrIterations; i++){
  44.  
  45. //Draw opening 7
  46. deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrDuals, NrCards, NrOtherLands);
  47. LandsInHand=0;
  48. GoodLandsInHandA=0;
  49. GoodLandsInHandB=0;
  50. DualInHand=0;
  51. for (int j=1; j<=7; j++){
  52. CardType=deck.DrawCard();
  53. if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
  54. if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
  55. if (CardType==3) {DualInHand++; LandsInHand++;}
  56. if (CardType==4) {LandsInHand++;}
  57. }
  58. StartingHandSize=7;
  59. Mulligan=false;
  60. if (LandsInHand<2) {Mulligan=true;}
  61. if (LandsInHand>5) {Mulligan=true;}
  62.  
  63. //Mulligan to 6
  64. if (Mulligan){
  65. deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrDuals, NrCards,NrOtherLands);
  66. LandsInHand=0;
  67. GoodLandsInHandA=0;
  68. GoodLandsInHandB=0;
  69. DualInHand=0;
  70. for (int j=1; j<=6; j++){
  71. CardType=deck.DrawCard();
  72. if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
  73. if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
  74. if (CardType==3) {DualInHand++; LandsInHand++;}
  75. if (CardType==4) {LandsInHand++;}
  76. }
  77. StartingHandSize=6;
  78. Mulligan=false;
  79. if (LandsInHand<2) {Mulligan=true;}
  80. if (LandsInHand>4) {Mulligan=true;}
  81. }
  82.  
  83. //Mulligan to 5
  84. if (Mulligan){
  85. deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrDuals, NrCards, NrOtherLands);
  86. LandsInHand=0;
  87. GoodLandsInHandA=0;
  88. GoodLandsInHandB=0;
  89. DualInHand=0;
  90. for (int j=1; j<=5; j++){
  91. CardType=deck.DrawCard();
  92. if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
  93. if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
  94. if (CardType==3) {DualInHand++; LandsInHand++;}
  95. if (CardType==4) {LandsInHand++;}
  96. }
  97. StartingHandSize=5;
  98. Mulligan=false;
  99. if (LandsInHand<1) {Mulligan=true;}
  100. if (LandsInHand>4) {Mulligan=true;}
  101. }
  102.  
  103. //Mulligan to 4
  104. if (Mulligan){
  105. deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrDuals, NrCards, NrOtherLands);
  106. LandsInHand=0;
  107. GoodLandsInHandA=0;
  108. GoodLandsInHandB=0;
  109. DualInHand=0;
  110. for (int j=1; j<=4; j++){
  111. CardType=deck.DrawCard();
  112. if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
  113. if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
  114. if (CardType==3) {DualInHand++; LandsInHand++;}
  115. if (CardType==4) {LandsInHand++;}
  116. }
  117. StartingHandSize=4;
  118. }
  119.  
  120. //Vancouver mulligan scry
  121. //If we already have enough colored sources, we leave any land on top and push any non-land to the bottom
  122. //If we don't already have enough colored sources, we leave any land that can produce the right color on top and push any other card (both off-color lands and spells) to the bottom
  123. GoodLandOnTopA=false;
  124. GoodLandOnTopB=false;
  125. DualOnTop=false;
  126. if (StartingHandSize<7){
  127. CardType=deck.DrawCard();
  128. if (CardType==1) {GoodLandOnTopA=true;}
  129. if (CardType==2) {GoodLandOnTopB=true;}
  130. if (CardType==3) {DualOnTop=true;}
  131. }
  132. //Draw step for turn 2 (remember, we're on the play)
  133. if (TurnAllowed>1){
  134. boolean WeScriedToTop=false;
  135. if (GoodLandOnTopA && GoodLandsInHandA<NrGoodLandsNeededA) {
  136. GoodLandsInHandA++; LandsInHand++; WeScriedToTop=true;
  137. }
  138. if (GoodLandOnTopB && GoodLandsInHandB<NrGoodLandsNeededB) {
  139. GoodLandsInHandB++; LandsInHand++; WeScriedToTop=true;
  140. }
  141. if (DualOnTop) {
  142. DualInHand++; LandsInHand++; WeScriedToTop=true;
  143. }
  144. if (!WeScriedToTop) {
  145. CardType=deck.DrawCard();
  146. if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
  147. if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
  148. if (CardType==3) {DualInHand++; LandsInHand++;}
  149. if (CardType==4) {LandsInHand++;}
  150. }
  151. }
  152.  
  153. //For turns 3 on, draw cards for the number of turns available
  154. for (int turn=3; turn<=TurnAllowed; turn++){
  155. CardType=deck.DrawCard();
  156. if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
  157. if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
  158. if (CardType==3) {DualInHand++; LandsInHand++;}
  159. if (CardType==4) {LandsInHand++;}
  160. }
  161.  
  162. if (GoodLandsInHandA+DualInHand>=NrGoodLandsNeededA && GoodLandsInHandB+DualInHand>=NrGoodLandsNeededB && GoodLandsInHandA+GoodLandsInHandB+DualInHand>=NrGoodLandsNeededA+NrGoodLandsNeededB && LandsInHand>=TurnAllowed) {CountOK++;}
  163. if (LandsInHand>=TurnAllowed) {CountConditional++;}
  164.  
  165. } // end of 1,000,000 iterations
  166.  
  167. //System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
  168. System.out.println(CountOK/CountConditional);
  169.  
  170. }
  171. }
  172.  
  173. class Deck {
  174. int NumberOfGoodLandsA;
  175. int NumberOfGoodLandsB;
  176. int NumberOfDuals;
  177. int NumberOfCards;
  178. int NumberOtherLands;
  179.  
  180. void SetDeck (int NrGoodLandsA, int NrGoodLandsB, int NrDuals, int NrCards, int NrOtherLands) {
  181. NumberOfGoodLandsA=NrGoodLandsA;
  182. NumberOfGoodLandsB=NrGoodLandsB;
  183. NumberOfDuals=NrDuals;
  184. NumberOfCards=NrCards;
  185. NumberOtherLands=NrOtherLands;
  186. }
  187.  
  188. int DrawCard (){
  189. Random generator = new Random();
  190. int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
  191. int CardType=0;
  192. int GoodLandCutoffA=NumberOfGoodLandsA;
  193. int GoodLandCutoffB=NumberOfGoodLandsA+NumberOfGoodLandsB;
  194. int DualCutoff=NumberOfGoodLandsA+NumberOfGoodLandsB+NumberOfDuals;
  195. int OtherLandCutoff=NumberOfGoodLandsA+NumberOfGoodLandsB+NumberOfDuals+NumberOtherLands;
  196. if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffA) {CardType=1; this.NumberOfGoodLandsA--; this.NumberOfCards--;}
  197. if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffA && RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffB) {CardType=2; this.NumberOfGoodLandsB--; this.NumberOfCards--;}
  198. if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffB && RandomIntegerBetweenOneAndDeckSize<=DualCutoff) {CardType=3; this.NumberOfDuals--; this.NumberOfCards--;}
  199. if (RandomIntegerBetweenOneAndDeckSize>DualCutoff && RandomIntegerBetweenOneAndDeckSize<=OtherLandCutoff) {CardType=4; this.NumberOtherLands--; this.NumberOfCards--;}
  200. if (RandomIntegerBetweenOneAndDeckSize>OtherLandCutoff) {CardType=5; this.NumberOfCards--;}
  201. return CardType;
  202. }
  203.  
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement