Advertisement
frankkarsten

Probability to cast Nicol Bolas, Dragon-God on curve

Apr 19th, 2019
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.07 KB | None | 0 0
  1. package bolasmana;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class BolasMana {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         Deck deck=new Deck();
  11.         int NrIterations=10000000;
  12.        
  13.         //Manually set the type of card that we're interested to cast here
  14.         int NrGoodLandsNeededA=1;
  15.         int NrGoodLandsNeededB=3;
  16.         int NrGoodLandsNeededC=1;
  17.         int TurnAllowed=5;
  18.         //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.
  19.         //For example, for a UBBBR spell, we use TurnAllowed=5 and NrGoodLandsNeededA=1, NrGoodLandsNeededB=3, NrGoodLandsNeededC=1.
  20.        
  21.         //Initialize the contents of the deck
  22.         int NrCards=60;
  23.         int NrOtherLands=0;
  24.         int NrDualsAB=8;
  25.         int NrDualsAC=5;
  26.         int NrDualsBC=8;
  27.         int NrGoodLandsA=0;
  28.         int NrGoodLandsB=5;                
  29.         int NrGoodLandsC=0;                
  30.         //This is surely not the cleanest way to do it, but it was the easiest way to adapt existing code
  31.        
  32.         //Declare other variables
  33.         int CardType; //Variable used to reference the type of card drawn from the deck
  34.         int LandsInHand; //This will describe the total amount of lands in your hand
  35.         int DualABInHand;
  36.         int DualACInHand;
  37.         int DualBCInHand;
  38.         int GoodLandsInHandA; //This will describe the number of lands that can produce A in your hand
  39.         int GoodLandsInHandB;
  40.         int GoodLandsInHandC;
  41.         int StartingHandSize;
  42.         boolean Mulligan;
  43.         boolean LandOnTop;
  44.  
  45.             double CountOK=0.0; //This will be the number of relevant games where you draw enough lands and the right colored sources
  46.             double CountConditional=0.0; //This will be the number of relevant games where you draw enough lands
  47.            
  48.             for (int i=1; i<=NrIterations; i++){
  49.                
  50.                 //Draw opening 7
  51.                 deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
  52.                 LandsInHand=0;
  53.                 GoodLandsInHandA=0;
  54.                 GoodLandsInHandB=0;
  55.                 GoodLandsInHandC=0;
  56.                 DualABInHand=0;
  57.                 DualACInHand=0;
  58.                 DualBCInHand=0;
  59.                 for (int j=1; j<=7; j++){
  60.                     CardType=deck.DrawCard();
  61.                     if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}  
  62.                     if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}  
  63.                     if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
  64.                     if (CardType==4) {DualABInHand++; LandsInHand++;}
  65.                     if (CardType==5) {DualACInHand++; LandsInHand++;}
  66.                     if (CardType==6) {DualBCInHand++; LandsInHand++;}
  67.                     if (CardType==7) {LandsInHand++;}
  68.               }
  69.                 StartingHandSize=7;
  70.                 Mulligan=false;
  71.                 if (LandsInHand<2) {Mulligan=true;}
  72.                 if (LandsInHand>5) {Mulligan=true;}
  73.                
  74.                 //Again, far from the nicest way to program this, but the quickest way to get to something functional by adapting existing code
  75.                
  76.                 //Mulligan to 6
  77.                 if (Mulligan){
  78.                     deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
  79.                     LandsInHand=0;
  80.                     GoodLandsInHandA=0;
  81.                     GoodLandsInHandB=0;
  82.                     GoodLandsInHandC=0;
  83.                     DualABInHand=0;
  84.                     DualACInHand=0;
  85.                     DualBCInHand=0;                
  86.                     for (int j=1; j<=6; j++){
  87.                         CardType=deck.DrawCard();
  88.                         if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}  
  89.                         if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}  
  90.                         if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
  91.                         if (CardType==4) {DualABInHand++; LandsInHand++;}
  92.                         if (CardType==5) {DualACInHand++; LandsInHand++;}
  93.                         if (CardType==6) {DualBCInHand++; LandsInHand++;}
  94.                         if (CardType==7) {LandsInHand++;}
  95.                     }
  96.                     StartingHandSize=6;
  97.                     Mulligan=false;
  98.                     if (LandsInHand<2) {Mulligan=true;}
  99.                     if (LandsInHand>4) {Mulligan=true;}
  100.                 }
  101.                
  102.                 //Mulligan to 5
  103.                 if (Mulligan){
  104.                     deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
  105.                     LandsInHand=0;
  106.                     GoodLandsInHandA=0;
  107.                     GoodLandsInHandB=0;
  108.                     GoodLandsInHandC=0;
  109.                     DualABInHand=0;
  110.                     DualACInHand=0;
  111.                     DualBCInHand=0;                
  112.                     for (int j=1; j<=5; j++){
  113.                         CardType=deck.DrawCard();
  114.                         if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}  
  115.                         if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}  
  116.                         if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
  117.                         if (CardType==4) {DualABInHand++; LandsInHand++;}
  118.                         if (CardType==5) {DualACInHand++; LandsInHand++;}
  119.                         if (CardType==6) {DualBCInHand++; LandsInHand++;}
  120.                         if (CardType==7) {LandsInHand++;}
  121.                     }
  122.                     StartingHandSize=5;
  123.                     Mulligan=false;
  124.                     if (LandsInHand<1) {Mulligan=true;}
  125.                     if (LandsInHand>4) {Mulligan=true;}
  126.                 }
  127.                
  128.                 //Mulligan to 4
  129.                 if (Mulligan){
  130.                     deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
  131.                     LandsInHand=0;
  132.                     GoodLandsInHandA=0;
  133.                     GoodLandsInHandB=0;
  134.                     GoodLandsInHandC=0;
  135.                     DualABInHand=0;
  136.                     DualACInHand=0;
  137.                     DualBCInHand=0;                
  138.                     for (int j=1; j<=4; j++){
  139.                         CardType=deck.DrawCard();
  140.                         if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}  
  141.                         if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}  
  142.                         if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
  143.                         if (CardType==4) {DualABInHand++; LandsInHand++;}
  144.                         if (CardType==5) {DualACInHand++; LandsInHand++;}
  145.                         if (CardType==6) {DualBCInHand++; LandsInHand++;}
  146.                         if (CardType==7) {LandsInHand++;}
  147.                     }
  148.                     StartingHandSize=4;
  149.                 }
  150.  
  151.                 //Vancouver mulligan scry
  152.                 //Leave any non-other land on top, push all other lands and spells to the bottom
  153.                 LandOnTop=false;
  154.                 boolean GoodLandOnTopA=false;
  155.                 boolean GoodLandOnTopB=false;
  156.                 boolean GoodLandOnTopC=false;
  157.                 boolean DualABOnTop=false;
  158.                 boolean DualACOnTop=false;
  159.                 boolean DualBCOnTop=false;
  160.                 if (StartingHandSize<7){
  161.                     CardType=deck.DrawCard();
  162.                     if (CardType==1) {GoodLandOnTopA=true;}  
  163.                     if (CardType==2) {GoodLandOnTopB=true;}  
  164.                     if (CardType==3) {GoodLandOnTopC=true;}  
  165.                     if (CardType==4) {DualABOnTop=true;}
  166.                     if (CardType==5) {DualACOnTop=true;}
  167.                     if (CardType==6) {DualBCOnTop=true;}
  168.                 }
  169.                 //Draw step for turn 2 (remember, we're on the play)
  170.                 if (TurnAllowed>1){
  171.                     boolean WeScriedToTop=false;
  172.                     if (GoodLandOnTopA ) {
  173.                         GoodLandsInHandA++; LandsInHand++; WeScriedToTop=true;
  174.                     }
  175.                     if (GoodLandOnTopB ) {
  176.                         GoodLandsInHandB++; LandsInHand++; WeScriedToTop=true;
  177.                     }
  178.                     if (GoodLandOnTopC ) {
  179.                         GoodLandsInHandC++; LandsInHand++; WeScriedToTop=true;
  180.                     }
  181.                     if (GoodLandOnTopC ) {
  182.                         GoodLandsInHandC++; LandsInHand++; WeScriedToTop=true;
  183.                     }
  184.                     if (DualABOnTop) {
  185.                         DualABInHand++; LandsInHand++; WeScriedToTop=true;
  186.                     }
  187.                     if (DualACOnTop) {
  188.                         DualACInHand++; LandsInHand++; WeScriedToTop=true;
  189.                     }
  190.                     if (DualBCOnTop) {
  191.                         DualBCInHand++; LandsInHand++; WeScriedToTop=true;
  192.                     }
  193.                    
  194.                     if (!WeScriedToTop) {
  195.                         CardType=deck.DrawCard();
  196.                         if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}  
  197.                         if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}  
  198.                         if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
  199.                         if (CardType==4) {DualABInHand++; LandsInHand++;}
  200.                         if (CardType==5) {DualACInHand++; LandsInHand++;}
  201.                         if (CardType==6) {DualBCInHand++; LandsInHand++;}
  202.                         if (CardType==7) {LandsInHand++;}
  203.                     }
  204.                 }
  205.                
  206.                 //For turns 3 on, draw cards for the number of turns available
  207.                 for (int turn=3; turn<=TurnAllowed; turn++){
  208.                     CardType=deck.DrawCard();
  209.                     if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}  
  210.                     if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}  
  211.                     if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
  212.                     if (CardType==4) {DualABInHand++; LandsInHand++;}
  213.                     if (CardType==5) {DualACInHand++; LandsInHand++;}
  214.                     if (CardType==6) {DualBCInHand++; LandsInHand++;}
  215.                     if (CardType==7) {LandsInHand++;}
  216.                 }
  217.                
  218.                 if (GoodLandsInHandA+DualABInHand+DualACInHand>=NrGoodLandsNeededA && GoodLandsInHandB+DualABInHand+DualBCInHand>=NrGoodLandsNeededB && GoodLandsInHandC+DualACInHand+DualBCInHand>=NrGoodLandsNeededC && GoodLandsInHandA+GoodLandsInHandB+GoodLandsInHandC+DualABInHand+DualACInHand+DualBCInHand>=NrGoodLandsNeededA+NrGoodLandsNeededB+NrGoodLandsNeededC && LandsInHand>=TurnAllowed) {CountOK++;}
  219.                 if (LandsInHand>=TurnAllowed) {CountConditional++;}
  220.                
  221.             } // end of 1,000,000 iterations
  222.            
  223.             //System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
  224.             System.out.println(CountOK/CountConditional);
  225.        
  226.     }
  227. }
  228.  
  229. class Deck {
  230.     int NumberOfGoodLandsA;
  231.     int NumberOfGoodLandsB;
  232.     int NumberOfGoodLandsC;
  233.     int NumberOfDualsAB;
  234.     int NumberOfDualsAC;
  235.     int NumberOfDualsBC;
  236.     int NumberOfCards;
  237.     int NumberOtherLands;
  238.  
  239.     void SetDeck (int NrGoodLandsA, int NrGoodLandsB, int NrGoodLandsC, int NrDualsAB, int NrDualsAC, int NrDualsBC, int NrCards, int NrOtherLands) {
  240.         NumberOfGoodLandsA=NrGoodLandsA;
  241.         NumberOfGoodLandsB=NrGoodLandsB;
  242.         NumberOfGoodLandsC=NrGoodLandsC;
  243.         NumberOfDualsAB=NrDualsAB;
  244.         NumberOfDualsAC=NrDualsAC;
  245.         NumberOfDualsBC=NrDualsBC;
  246.         NumberOfCards=NrCards;
  247.         NumberOtherLands=NrOtherLands;
  248.     }
  249.    
  250.     int DrawCard (){
  251.             Random generator = new Random();
  252.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
  253.             int CardType=0;
  254.             int GoodLandCutoffA=NumberOfGoodLandsA;
  255.             int GoodLandCutoffB=NumberOfGoodLandsA+NumberOfGoodLandsB;
  256.             int GoodLandCutoffC=NumberOfGoodLandsA+NumberOfGoodLandsB+NumberOfGoodLandsC;
  257.             int DualCutoffAB=GoodLandCutoffC+NumberOfDualsAB;
  258.             int DualCutoffAC=GoodLandCutoffC+NumberOfDualsAB+NumberOfDualsAC;
  259.             int DualCutoffBC=GoodLandCutoffC+NumberOfDualsAB+NumberOfDualsAC+NumberOfDualsBC;
  260.             int OtherLandCutoff=DualCutoffBC+NumberOtherLands;
  261.             if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffA) {CardType=1; this.NumberOfGoodLandsA--; this.NumberOfCards--;}
  262.             if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffA && RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffB) {CardType=2; this.NumberOfGoodLandsB--; this.NumberOfCards--;}
  263.             if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffB && RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffC) {CardType=3; this.NumberOfGoodLandsC--; this.NumberOfCards--;}
  264.             if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffC && RandomIntegerBetweenOneAndDeckSize<=DualCutoffAB) {CardType=4; this.NumberOfDualsAB--; this.NumberOfCards--;}
  265.             if (RandomIntegerBetweenOneAndDeckSize>DualCutoffAB && RandomIntegerBetweenOneAndDeckSize<=DualCutoffAC) {CardType=5; this.NumberOfDualsAC--; this.NumberOfCards--;}
  266.             if (RandomIntegerBetweenOneAndDeckSize>DualCutoffAC && RandomIntegerBetweenOneAndDeckSize<=DualCutoffBC) {CardType=6; this.NumberOfDualsBC--; this.NumberOfCards--;}
  267.             if (RandomIntegerBetweenOneAndDeckSize>DualCutoffBC && RandomIntegerBetweenOneAndDeckSize<=OtherLandCutoff) {CardType=7; this.NumberOtherLands--; this.NumberOfCards--;}
  268.             if (RandomIntegerBetweenOneAndDeckSize>OtherLandCutoff) {CardType=8; this.NumberOfCards--;}
  269.             return CardType;
  270.     }
  271.  
  272.  
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement