Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bolasmana;
- import java.util.Arrays.*;
- import java.util.Random;
- public class BolasMana {
- public static void main(String[] args) {
- Deck deck=new Deck();
- int NrIterations=10000000;
- //Manually set the type of card that we're interested to cast here
- int NrGoodLandsNeededA=1;
- int NrGoodLandsNeededB=3;
- int NrGoodLandsNeededC=1;
- int TurnAllowed=5;
- //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.
- //For example, for a UBBBR spell, we use TurnAllowed=5 and NrGoodLandsNeededA=1, NrGoodLandsNeededB=3, NrGoodLandsNeededC=1.
- //Initialize the contents of the deck
- int NrCards=60;
- int NrOtherLands=0;
- int NrDualsAB=8;
- int NrDualsAC=5;
- int NrDualsBC=8;
- int NrGoodLandsA=0;
- int NrGoodLandsB=5;
- int NrGoodLandsC=0;
- //This is surely not the cleanest way to do it, but it was the easiest way to adapt existing code
- //Declare other variables
- int CardType; //Variable used to reference the type of card drawn from the deck
- int LandsInHand; //This will describe the total amount of lands in your hand
- int DualABInHand;
- int DualACInHand;
- int DualBCInHand;
- int GoodLandsInHandA; //This will describe the number of lands that can produce A in your hand
- int GoodLandsInHandB;
- int GoodLandsInHandC;
- int StartingHandSize;
- boolean Mulligan;
- boolean LandOnTop;
- double CountOK=0.0; //This will be the number of relevant games where you draw enough lands and the right colored sources
- double CountConditional=0.0; //This will be the number of relevant games where you draw enough lands
- for (int i=1; i<=NrIterations; i++){
- //Draw opening 7
- deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
- LandsInHand=0;
- GoodLandsInHandA=0;
- GoodLandsInHandB=0;
- GoodLandsInHandC=0;
- DualABInHand=0;
- DualACInHand=0;
- DualBCInHand=0;
- for (int j=1; j<=7; j++){
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
- if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
- if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
- if (CardType==4) {DualABInHand++; LandsInHand++;}
- if (CardType==5) {DualACInHand++; LandsInHand++;}
- if (CardType==6) {DualBCInHand++; LandsInHand++;}
- if (CardType==7) {LandsInHand++;}
- }
- StartingHandSize=7;
- Mulligan=false;
- if (LandsInHand<2) {Mulligan=true;}
- if (LandsInHand>5) {Mulligan=true;}
- //Again, far from the nicest way to program this, but the quickest way to get to something functional by adapting existing code
- //Mulligan to 6
- if (Mulligan){
- deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
- LandsInHand=0;
- GoodLandsInHandA=0;
- GoodLandsInHandB=0;
- GoodLandsInHandC=0;
- DualABInHand=0;
- DualACInHand=0;
- DualBCInHand=0;
- for (int j=1; j<=6; j++){
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
- if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
- if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
- if (CardType==4) {DualABInHand++; LandsInHand++;}
- if (CardType==5) {DualACInHand++; LandsInHand++;}
- if (CardType==6) {DualBCInHand++; LandsInHand++;}
- if (CardType==7) {LandsInHand++;}
- }
- StartingHandSize=6;
- Mulligan=false;
- if (LandsInHand<2) {Mulligan=true;}
- if (LandsInHand>4) {Mulligan=true;}
- }
- //Mulligan to 5
- if (Mulligan){
- deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
- LandsInHand=0;
- GoodLandsInHandA=0;
- GoodLandsInHandB=0;
- GoodLandsInHandC=0;
- DualABInHand=0;
- DualACInHand=0;
- DualBCInHand=0;
- for (int j=1; j<=5; j++){
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
- if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
- if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
- if (CardType==4) {DualABInHand++; LandsInHand++;}
- if (CardType==5) {DualACInHand++; LandsInHand++;}
- if (CardType==6) {DualBCInHand++; LandsInHand++;}
- if (CardType==7) {LandsInHand++;}
- }
- StartingHandSize=5;
- Mulligan=false;
- if (LandsInHand<1) {Mulligan=true;}
- if (LandsInHand>4) {Mulligan=true;}
- }
- //Mulligan to 4
- if (Mulligan){
- deck.SetDeck(NrGoodLandsA, NrGoodLandsB, NrGoodLandsC, NrDualsAB, NrDualsAC, NrDualsBC, NrCards, NrOtherLands);
- LandsInHand=0;
- GoodLandsInHandA=0;
- GoodLandsInHandB=0;
- GoodLandsInHandC=0;
- DualABInHand=0;
- DualACInHand=0;
- DualBCInHand=0;
- for (int j=1; j<=4; j++){
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
- if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
- if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
- if (CardType==4) {DualABInHand++; LandsInHand++;}
- if (CardType==5) {DualACInHand++; LandsInHand++;}
- if (CardType==6) {DualBCInHand++; LandsInHand++;}
- if (CardType==7) {LandsInHand++;}
- }
- StartingHandSize=4;
- }
- //Vancouver mulligan scry
- //Leave any non-other land on top, push all other lands and spells to the bottom
- LandOnTop=false;
- boolean GoodLandOnTopA=false;
- boolean GoodLandOnTopB=false;
- boolean GoodLandOnTopC=false;
- boolean DualABOnTop=false;
- boolean DualACOnTop=false;
- boolean DualBCOnTop=false;
- if (StartingHandSize<7){
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandOnTopA=true;}
- if (CardType==2) {GoodLandOnTopB=true;}
- if (CardType==3) {GoodLandOnTopC=true;}
- if (CardType==4) {DualABOnTop=true;}
- if (CardType==5) {DualACOnTop=true;}
- if (CardType==6) {DualBCOnTop=true;}
- }
- //Draw step for turn 2 (remember, we're on the play)
- if (TurnAllowed>1){
- boolean WeScriedToTop=false;
- if (GoodLandOnTopA ) {
- GoodLandsInHandA++; LandsInHand++; WeScriedToTop=true;
- }
- if (GoodLandOnTopB ) {
- GoodLandsInHandB++; LandsInHand++; WeScriedToTop=true;
- }
- if (GoodLandOnTopC ) {
- GoodLandsInHandC++; LandsInHand++; WeScriedToTop=true;
- }
- if (GoodLandOnTopC ) {
- GoodLandsInHandC++; LandsInHand++; WeScriedToTop=true;
- }
- if (DualABOnTop) {
- DualABInHand++; LandsInHand++; WeScriedToTop=true;
- }
- if (DualACOnTop) {
- DualACInHand++; LandsInHand++; WeScriedToTop=true;
- }
- if (DualBCOnTop) {
- DualBCInHand++; LandsInHand++; WeScriedToTop=true;
- }
- if (!WeScriedToTop) {
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
- if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
- if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
- if (CardType==4) {DualABInHand++; LandsInHand++;}
- if (CardType==5) {DualACInHand++; LandsInHand++;}
- if (CardType==6) {DualBCInHand++; LandsInHand++;}
- if (CardType==7) {LandsInHand++;}
- }
- }
- //For turns 3 on, draw cards for the number of turns available
- for (int turn=3; turn<=TurnAllowed; turn++){
- CardType=deck.DrawCard();
- if (CardType==1) {GoodLandsInHandA++; LandsInHand++;}
- if (CardType==2) {GoodLandsInHandB++; LandsInHand++;}
- if (CardType==3) {GoodLandsInHandC++; LandsInHand++;}
- if (CardType==4) {DualABInHand++; LandsInHand++;}
- if (CardType==5) {DualACInHand++; LandsInHand++;}
- if (CardType==6) {DualBCInHand++; LandsInHand++;}
- if (CardType==7) {LandsInHand++;}
- }
- 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++;}
- if (LandsInHand>=TurnAllowed) {CountConditional++;}
- } // end of 1,000,000 iterations
- //System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
- System.out.println(CountOK/CountConditional);
- }
- }
- class Deck {
- int NumberOfGoodLandsA;
- int NumberOfGoodLandsB;
- int NumberOfGoodLandsC;
- int NumberOfDualsAB;
- int NumberOfDualsAC;
- int NumberOfDualsBC;
- int NumberOfCards;
- int NumberOtherLands;
- void SetDeck (int NrGoodLandsA, int NrGoodLandsB, int NrGoodLandsC, int NrDualsAB, int NrDualsAC, int NrDualsBC, int NrCards, int NrOtherLands) {
- NumberOfGoodLandsA=NrGoodLandsA;
- NumberOfGoodLandsB=NrGoodLandsB;
- NumberOfGoodLandsC=NrGoodLandsC;
- NumberOfDualsAB=NrDualsAB;
- NumberOfDualsAC=NrDualsAC;
- NumberOfDualsBC=NrDualsBC;
- NumberOfCards=NrCards;
- NumberOtherLands=NrOtherLands;
- }
- int DrawCard (){
- Random generator = new Random();
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
- int CardType=0;
- int GoodLandCutoffA=NumberOfGoodLandsA;
- int GoodLandCutoffB=NumberOfGoodLandsA+NumberOfGoodLandsB;
- int GoodLandCutoffC=NumberOfGoodLandsA+NumberOfGoodLandsB+NumberOfGoodLandsC;
- int DualCutoffAB=GoodLandCutoffC+NumberOfDualsAB;
- int DualCutoffAC=GoodLandCutoffC+NumberOfDualsAB+NumberOfDualsAC;
- int DualCutoffBC=GoodLandCutoffC+NumberOfDualsAB+NumberOfDualsAC+NumberOfDualsBC;
- int OtherLandCutoff=DualCutoffBC+NumberOtherLands;
- if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffA) {CardType=1; this.NumberOfGoodLandsA--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffA && RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffB) {CardType=2; this.NumberOfGoodLandsB--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffB && RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoffC) {CardType=3; this.NumberOfGoodLandsC--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoffC && RandomIntegerBetweenOneAndDeckSize<=DualCutoffAB) {CardType=4; this.NumberOfDualsAB--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>DualCutoffAB && RandomIntegerBetweenOneAndDeckSize<=DualCutoffAC) {CardType=5; this.NumberOfDualsAC--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>DualCutoffAC && RandomIntegerBetweenOneAndDeckSize<=DualCutoffBC) {CardType=6; this.NumberOfDualsBC--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>DualCutoffBC && RandomIntegerBetweenOneAndDeckSize<=OtherLandCutoff) {CardType=7; this.NumberOtherLands--; this.NumberOfCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>OtherLandCutoff) {CardType=8; this.NumberOfCards--;}
- return CardType;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement