Advertisement
frankkarsten

How many colored sources do you need? (GRN update)

Oct 4th, 2018
3,504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. package howmanysourcesupdate;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class HowManySourcesUpdate {
  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 NrGoodLandsNeeded=3;
  15. int TurnAllowed=6;
  16. //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.
  17. //For example, for a 2WW Wrath of God, we use TurnAllowed=4 and NrGoodLandsNeeded=2.
  18.  
  19. //Initialize the contents of the deck
  20. int NrCards=40;
  21. int NrLands=17;
  22. //Note that the final element needed to describe a deck (NrGoodLands) is set later, as we iterate over the various possible values
  23.  
  24. //Declare other variables
  25. int CardType; //Variable used to reference the type of card drawn from the deck
  26. int LandsInHand; //This will describe the total amount of lands in your hand
  27. int GoodLandsInHand; //This will describe the number of lands that can produce the right color in your hand
  28. int StartingHandSize;
  29. boolean Mulligan;
  30. boolean GoodLandOnTop;
  31.  
  32. for (int NrGoodLands=3; NrGoodLands<=17; NrGoodLands++){
  33.  
  34. double CountOK=0.0; //This will be the number of relevant games where you draw enough lands and the right colored sources
  35. double CountConditional=0.0; //This will be the number of relevant games where you draw enough lands
  36.  
  37. for (int i=1; i<=NrIterations; i++){
  38.  
  39. //Draw opening 7
  40. deck.SetDeck(NrLands, NrGoodLands, NrCards);
  41. LandsInHand=0;
  42. GoodLandsInHand=0;
  43. for (int j=1; j<=7; j++){
  44. CardType=deck.DrawCard();
  45. if (CardType<3) {LandsInHand++;}
  46. if (CardType==1) {GoodLandsInHand++;}
  47. }
  48. StartingHandSize=7;
  49. Mulligan=false;
  50. if (LandsInHand<2) {Mulligan=true;}
  51. if (LandsInHand>5) {Mulligan=true;}
  52.  
  53. //Mulligan to 6
  54. if (Mulligan){
  55. deck.SetDeck(NrLands, NrGoodLands, NrCards);
  56. LandsInHand=0;
  57. GoodLandsInHand=0;
  58. for (int j=1; j<=6; j++){
  59. CardType=deck.DrawCard();
  60. if (CardType<3) {LandsInHand++;}
  61. if (CardType==1) {GoodLandsInHand++;}
  62. }
  63. StartingHandSize=6;
  64. Mulligan=false;
  65. if (LandsInHand<2) {Mulligan=true;}
  66. if (LandsInHand>4) {Mulligan=true;}
  67. }
  68.  
  69. //Mulligan to 5
  70. if (Mulligan){
  71. deck.SetDeck(NrLands, NrGoodLands, NrCards);
  72. LandsInHand=0;
  73. GoodLandsInHand=0;
  74. for (int j=1; j<=5; j++){
  75. CardType=deck.DrawCard();
  76. if (CardType<3) {LandsInHand++;}
  77. if (CardType==1) {GoodLandsInHand++;}
  78. }
  79. StartingHandSize=5;
  80. Mulligan=false;
  81. if (LandsInHand<1) {Mulligan=true;}
  82. if (LandsInHand>4) {Mulligan=true;}
  83. }
  84.  
  85. //Mulligan to 4
  86. if (Mulligan){
  87. deck.SetDeck(NrLands, NrGoodLands, NrCards);
  88. LandsInHand=0;
  89. GoodLandsInHand=0;
  90. for (int j=1; j<=4; j++){
  91. CardType=deck.DrawCard();
  92. if (CardType<3) {LandsInHand++;}
  93. if (CardType==1) {GoodLandsInHand++;}
  94. }
  95. StartingHandSize=4;
  96. }
  97.  
  98. //Vancouver mulligan scry
  99. //Wwe 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
  100. GoodLandOnTop=false;
  101. if (StartingHandSize<7){
  102. CardType=deck.DrawCard();
  103. if (CardType==1) {GoodLandOnTop=true;}
  104. }
  105. //Draw step for turn 2 (remember, we're always on the play)
  106. if (TurnAllowed>1){
  107. if (GoodLandOnTop) {
  108. GoodLandsInHand++; LandsInHand++;
  109. }
  110. else {
  111. CardType=deck.DrawCard();
  112. if (CardType<3) {LandsInHand++;}
  113. if (CardType==1) {GoodLandsInHand++;}
  114. }
  115. }
  116.  
  117. //For turns 3 on, draw cards for the number of turns available
  118. for (int turn=3; turn<=TurnAllowed; turn++){
  119. CardType=deck.DrawCard();
  120. if (CardType<3) {LandsInHand++;}
  121. if (CardType==1) {GoodLandsInHand++;}
  122. }
  123.  
  124. if (GoodLandsInHand>=NrGoodLandsNeeded && LandsInHand>=TurnAllowed) {CountOK++;}
  125. if (LandsInHand>=TurnAllowed) {CountConditional++;}
  126.  
  127. } // end of 1,000,000 iterations
  128.  
  129. //System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
  130. System.out.println(CountOK/CountConditional);
  131. }
  132. }
  133. }
  134.  
  135. class Deck {
  136. int NumberOfLands;
  137. int NumberOfGoodLands;
  138. int NumberOfCards;
  139.  
  140. void SetDeck (int NrLands, int NrGoodLands, int NrCards) {
  141. NumberOfLands=NrLands;
  142. NumberOfGoodLands=NrGoodLands;
  143. NumberOfCards=NrCards;
  144. }
  145.  
  146. int DrawCard (){
  147. Random generator = new Random();
  148. int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
  149. int CardType=0;
  150. int GoodLandCutoff=NumberOfGoodLands;
  151. int LandCutoff=NumberOfLands;
  152.  
  153. if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoff) {CardType=1; this.NumberOfGoodLands--; this.NumberOfLands--; this.NumberOfCards--;}
  154. if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=2; this.NumberOfLands--; this.NumberOfCards--;}
  155. if (RandomIntegerBetweenOneAndDeckSize>LandCutoff) {CardType=3; this.NumberOfCards--;}
  156. return CardType;
  157. }
  158.  
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement