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 land
- //CardType 2 used to be a fetch-land, which is now not used anymore and set to 0
- //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
- for (int basics=1; basics<=20; basics++){
- System.out.println("=================================================");
- System.out.println("We now consider a deck with "+basics+" basic lands");
- System.out.println("=================================================");
- //The first output line give the percentage probability that a Battle land which would be played on turn 3 enters tapped.
- //The second output line give the percentage probability that a Battle land which would be played on turn 4 enters tapped.
- //The third output line give the percentage probability that a Battle land which would be played on turn 5 enters tapped.
- deck.SetDeck(4,0,basics,21-basics,35);
- double Probability;
- for (int turn=3; turn<=5; turn++){
- Probability=ProbabilityForRandomHand(deck,7,1000000,turn);
- System.out.println(Math.round(Probability*10000)/100.0);
- }
- }
- }//end of main
- public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
- //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;
- }
- //3. Otherwise, if you can play a basic from hand, then do so
- if (LandPlayed==false && BasicLandsInHand>=1) {
- BasicLandsInHand--;
- 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>=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