Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package battlelands;
- import java.util.Arrays.*;
- import java.util.Random;
- public class BattleLands {
- public static void main(String[] args) {
- Deck deck=new Deck();
- //CardType 1 is a Battle lands
- //CardType 2 is a fetch-land
- //CardType 3 is a basic land (or Evolving Wilds)
- //CardType 4 is another land (e.g., man-land or pain-land)
- //CardType 5 is a non-land card
- deck.SetDeck(4,9,9,2,36);
- double Probability;
- Probability=ProbabilityForRandomHand(deck,7,10000000,1);
- System.out.println("Probability that you have to play a Battle land on turn 1: "+Math.round(Probability*10000)/100.0+"%");
- Probability=ProbabilityForRandomHand(deck,7,10000000,2);
- System.out.println("Probability that you have to play a Battle land on turn 2: "+Math.round(Probability*10000)/100.0+"%");
- Probability=ProbabilityForRandomHand(deck,7,10000000,3);
- System.out.println("Probability that a Battle land on turn 3 enters tapped: "+Math.round(Probability*10000)/100.0+"%");
- Probability=ProbabilityForRandomHand(deck,7,10000000,4);
- System.out.println("Probability that a Battle land on turn 4 enters tapped: "+Math.round(Probability*10000)/100.0+"%");
- Probability=ProbabilityForRandomHand(deck,7,10000000,5);
- System.out.println("Probability that a Battle land on turn 5 enters tapped: "+Math.round(Probability*10000)/100.0+"%");
- }//end of main
- public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
- //ProbabilityType 1: Probability that you have to play a Battle land on turn 1 (outcome: 0=no, 1=yes)
- //ProbabilityType 2: Probability that you have to play a Battle land on turn 2 (outcome: 0=no, 1=yes)
- //ProbabilityType 3: Probability that you have at least 2 basics in play at the start of turn 3 (outcome: 0=yes 2 basics, 1=no not enough basics)
- //ProbabilityType 4: Probability that you have at least 2 basics in play at the start of turn 4 (outcome: 0=yes 2 basics, 1=no not enough basics)
- //ProbabilityType 5: Probability that you have at least 2 basics in play at the start of turn 5 (outcome: 0=yes 2 basics, 1=no not enough basics)
- Deck remainingdeck=new Deck();
- double NumberOfRelevantGames=0;
- double NumberOfGamesWithUnfavorableOutcome=0;
- for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
- OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
- remainingdeck.SetDeck(deck.NumberOfBattleLands-openinghand.NumberOfBattleLands,deck.NumberOfFetchLands-openinghand.NumberOfFetchLands,deck.NumberOfBasicLands-openinghand.NumberOfBasicLands,deck.NumberOfOtherLands-openinghand.NumberOfOtherLands,deck.NumberOfSpells-openinghand.NumberOfSpells);
- int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
- if (Outcome<2) {NumberOfRelevantGames++;} //This is currently not used
- if (Outcome==1) {NumberOfGamesWithUnfavorableOutcome++;}
- }
- return NumberOfGamesWithUnfavorableOutcome/(NumberOfRelevantGames+0.0);
- }//end of AverageKillTurnForRandomHand
- static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
- Deck remainingdeck=new Deck();
- OpeningHand openinghand=new OpeningHand();
- int TypeOfCardDrawn;
- boolean KeepHand=false;
- for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
- if (KeepHand==false){
- openinghand.SetHand(0,0,0,0,0);
- remainingdeck.SetDeck(deck.NumberOfBattleLands,deck.NumberOfFetchLands,deck.NumberOfBasicLands,deck.NumberOfOtherLands,deck.NumberOfSpells);
- int NumberOfLands=0;
- for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {openinghand.NumberOfBattleLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==2) {openinghand.NumberOfFetchLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==3) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==4) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
- }
- KeepHand=true;
- if (OpeningHandSize>1) {
- // We mulligan a hand if it contains 0, 1, 5, 6, or 7 lands
- if (NumberOfLands<=1 || NumberOfLands>=5) {KeepHand=false;}
- //
- }
- }
- }
- return openinghand;
- }//end of GiveOpeningHandAfterMulls
- static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
- int TypeOfCardDrawn=0;
- int BasicsInPlay=0;
- int Outcome=2;
- boolean GotABattleLandThisTurn=false;
- boolean ThisLandEnteredTapped=false;
- boolean EnoughBasicsAtStartTurn=false;
- int BattleLandsInHand=openinghand.NumberOfBattleLands;
- int FetchLandsInHand=openinghand.NumberOfFetchLands;
- int BasicLandsInHand=openinghand.NumberOfBasicLands;
- int OtherLandsInHand=openinghand.NumberOfOtherLands;
- int SpellsInHand=openinghand.NumberOfSpells;
- for (int Turn=1; Turn<=5; Turn++){
- if (Turn>1) {
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {BattleLandsInHand++;}
- if (TypeOfCardDrawn==2) {FetchLandsInHand++;}
- if (TypeOfCardDrawn==3) {BasicLandsInHand++;}
- if (TypeOfCardDrawn==4) {OtherLandsInHand++;}
- if (TypeOfCardDrawn==5) {SpellsInHand++;}
- }
- boolean LandPlayed=false;
- if (Turn==ProbabilityType && BasicsInPlay>=2) {EnoughBasicsAtStartTurn=true;}
- //1. If there are >=2 basics in play and you can play a Battle land from hand, then do so
- if (BasicsInPlay>=2 && BattleLandsInHand>=1) {
- BattleLandsInHand--;
- if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=false;}
- LandPlayed=true;
- }
- //2. Otherwise, if there are >=2 basics in play and you can fetch a Battle land, then do so
- if (LandPlayed==false && BasicsInPlay>=2 && FetchLandsInHand>=1 && remainingdeck.NumberOfBattleLands>=1) {
- FetchLandsInHand--;
- remainingdeck.NumberOfBattleLands--;
- if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=false;}
- LandPlayed=true;
- }
- //3. Otherwise, if you can play a basic from hand, then do so
- if (LandPlayed==false && BasicLandsInHand>=1) {
- BasicLandsInHand--;
- BasicsInPlay++;
- LandPlayed=true;
- }
- //4. Otherwise, if you can fetch a basic, then do so
- if (LandPlayed==false && FetchLandsInHand>=1 && remainingdeck.NumberOfBasicLands>=1) {
- FetchLandsInHand--;
- remainingdeck.NumberOfBasicLands--;
- BasicsInPlay++;
- LandPlayed=true;
- }
- //5. Otherwise, play another land
- if (LandPlayed==false && OtherLandsInHand>=1) {
- OtherLandsInHand--;
- LandPlayed=true;
- }
- //6. Otherwise, play a Battle land
- if (LandPlayed==false && BattleLandsInHand>=1) {
- BattleLandsInHand--;
- if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=true;}
- }
- }//end of the for-loop over the turns
- if (ProbabilityType<=2 && GotABattleLandThisTurn) {Outcome=1;}
- if (ProbabilityType<=2 && !GotABattleLandThisTurn) {Outcome=0;}
- //Commented out below are alternative probabilities that I ran earlier but I wasn't thrilled with the interpretation
- //if (ProbabilityType>=3 && GotABattleLandThisTurn && !ThisLandEnteredTapped) {Outcome=0;}
- //if (ProbabilityType>=3 && GotABattleLandThisTurn && ThisLandEnteredTapped) {Outcome=1;}
- //if (ProbabilityType>=3 && !GotABattleLandThisTurn) {Outcome=2;}
- if (ProbabilityType>=3 && EnoughBasicsAtStartTurn) {Outcome=0;}
- if (ProbabilityType>=3 && !EnoughBasicsAtStartTurn) {Outcome=1;}
- return Outcome;
- }//end of SimulateGame
- }
- class OpeningHand {
- int NumberOfBattleLands;
- int NumberOfFetchLands;
- int NumberOfBasicLands;
- int NumberOfOtherLands;
- int NumberOfSpells;
- int NrOfCards(){
- return NumberOfBattleLands+NumberOfFetchLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfSpells;
- }
- void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
- NumberOfBattleLands=Nr1;
- NumberOfFetchLands=Nr2;
- NumberOfBasicLands=Nr3;
- NumberOfOtherLands=Nr4;
- NumberOfSpells=Nr5;
- }
- }//end of OpeningHand
- class Deck {
- int NumberOfBattleLands;
- int NumberOfFetchLands;
- int NumberOfBasicLands;
- int NumberOfOtherLands;
- int NumberOfSpells;
- void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
- NumberOfBattleLands=Nr1;
- NumberOfFetchLands=Nr2;
- NumberOfBasicLands=Nr3;
- NumberOfOtherLands=Nr4;
- NumberOfSpells=Nr5;
- }
- int NrOfCards(){
- return NumberOfBattleLands+NumberOfFetchLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfSpells;
- }
- int DrawCard (){
- Random generator = new Random();
- int CardType=0;
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
- int OneCutoff=NumberOfBattleLands;
- int TwoCutoff=OneCutoff+NumberOfFetchLands;
- int ThreeCutoff=TwoCutoff+NumberOfBasicLands;
- int FourCutoff=ThreeCutoff+NumberOfOtherLands;
- int FiveCutoff=FourCutoff+NumberOfSpells;
- if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfBattleLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfFetchLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfBasicLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfOtherLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
- return CardType;
- }
- }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement