frankkarsten

Analysis of Battle for Zendikar lands

Sep 21st, 2015
599
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package battlelands;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class BattleLands {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.  
  12.         //CardType 1 is a Battle lands
  13.         //CardType 2 is a fetch-land
  14.         //CardType 3 is a basic land (or Evolving Wilds)
  15.         //CardType 4 is another land (e.g., man-land or pain-land)
  16.         //CardType 5 is a non-land card
  17.        
  18.         deck.SetDeck(4,9,9,2,36);
  19.         double Probability;
  20.        
  21.         Probability=ProbabilityForRandomHand(deck,7,10000000,1);
  22.         System.out.println("Probability that you have to play a Battle land on turn 1: "+Math.round(Probability*10000)/100.0+"%");
  23.        
  24.         Probability=ProbabilityForRandomHand(deck,7,10000000,2);
  25.         System.out.println("Probability that you have to play a Battle land on turn 2: "+Math.round(Probability*10000)/100.0+"%");
  26.        
  27.         Probability=ProbabilityForRandomHand(deck,7,10000000,3);
  28.         System.out.println("Probability that a Battle land on turn 3 enters tapped:    "+Math.round(Probability*10000)/100.0+"%");
  29.  
  30.         Probability=ProbabilityForRandomHand(deck,7,10000000,4);
  31.         System.out.println("Probability that a Battle land on turn 4 enters tapped:    "+Math.round(Probability*10000)/100.0+"%");
  32.  
  33.         Probability=ProbabilityForRandomHand(deck,7,10000000,5);
  34.         System.out.println("Probability that a Battle land on turn 5 enters tapped:    "+Math.round(Probability*10000)/100.0+"%");
  35.        
  36.     }//end of main
  37.  
  38.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
  39.         //ProbabilityType 1: Probability that you have to play a Battle land on turn 1 (outcome: 0=no, 1=yes)
  40.         //ProbabilityType 2: Probability that you have to play a Battle land on turn 2 (outcome: 0=no, 1=yes)
  41.         //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)
  42.         //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)
  43.         //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)
  44.        
  45.         Deck remainingdeck=new Deck();
  46.         double NumberOfRelevantGames=0;
  47.         double NumberOfGamesWithUnfavorableOutcome=0;
  48.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  49.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  50.             remainingdeck.SetDeck(deck.NumberOfBattleLands-openinghand.NumberOfBattleLands,deck.NumberOfFetchLands-openinghand.NumberOfFetchLands,deck.NumberOfBasicLands-openinghand.NumberOfBasicLands,deck.NumberOfOtherLands-openinghand.NumberOfOtherLands,deck.NumberOfSpells-openinghand.NumberOfSpells);
  51.             int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
  52.             if (Outcome<2) {NumberOfRelevantGames++;} //This is currently not used
  53.             if (Outcome==1) {NumberOfGamesWithUnfavorableOutcome++;}
  54.         }
  55.         return NumberOfGamesWithUnfavorableOutcome/(NumberOfRelevantGames+0.0);
  56.     }//end of AverageKillTurnForRandomHand
  57.    
  58.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  59.        
  60.         Deck remainingdeck=new Deck();
  61.         OpeningHand openinghand=new OpeningHand();
  62.         int TypeOfCardDrawn;
  63.         boolean KeepHand=false;
  64.        
  65.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  66.             if (KeepHand==false){
  67.                 openinghand.SetHand(0,0,0,0,0);
  68.                 remainingdeck.SetDeck(deck.NumberOfBattleLands,deck.NumberOfFetchLands,deck.NumberOfBasicLands,deck.NumberOfOtherLands,deck.NumberOfSpells);
  69.                 int NumberOfLands=0;
  70.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  71.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  72.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfBattleLands++; NumberOfLands++;}
  73.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfFetchLands++; NumberOfLands++;}
  74.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
  75.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
  76.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
  77.                 }
  78.                 KeepHand=true;
  79.                 if (OpeningHandSize>1) {
  80.                     // We mulligan a hand if it contains 0, 1, 5, 6, or 7 lands
  81.                     if (NumberOfLands<=1 || NumberOfLands>=5) {KeepHand=false;}
  82.                     //
  83.                 }
  84.             }
  85.         }
  86.        
  87.         return openinghand;
  88.     }//end of GiveOpeningHandAfterMulls
  89.    
  90.    
  91.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
  92.        
  93.         int TypeOfCardDrawn=0;
  94.         int BasicsInPlay=0;
  95.         int Outcome=2;
  96.         boolean GotABattleLandThisTurn=false;
  97.         boolean ThisLandEnteredTapped=false;
  98.         boolean EnoughBasicsAtStartTurn=false;
  99.        
  100.         int BattleLandsInHand=openinghand.NumberOfBattleLands;
  101.         int FetchLandsInHand=openinghand.NumberOfFetchLands;
  102.         int BasicLandsInHand=openinghand.NumberOfBasicLands;
  103.         int OtherLandsInHand=openinghand.NumberOfOtherLands;
  104.         int SpellsInHand=openinghand.NumberOfSpells;
  105.                
  106.         for (int Turn=1; Turn<=5; Turn++){
  107.             if (Turn>1) {
  108.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  109.                 if (TypeOfCardDrawn==1) {BattleLandsInHand++;}
  110.                 if (TypeOfCardDrawn==2) {FetchLandsInHand++;}
  111.                 if (TypeOfCardDrawn==3) {BasicLandsInHand++;}
  112.                 if (TypeOfCardDrawn==4) {OtherLandsInHand++;}
  113.                 if (TypeOfCardDrawn==5) {SpellsInHand++;}
  114.             }
  115.             boolean LandPlayed=false;
  116.  
  117.             if (Turn==ProbabilityType && BasicsInPlay>=2) {EnoughBasicsAtStartTurn=true;}
  118.            
  119.             //1. If there are >=2 basics in play and you can play a Battle land from hand, then do so
  120.             if (BasicsInPlay>=2 && BattleLandsInHand>=1) {
  121.                 BattleLandsInHand--;
  122.                 if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=false;}
  123.                 LandPlayed=true;
  124.             }
  125.            
  126.             //2. Otherwise, if there are >=2 basics in play and you can fetch a Battle land, then do so
  127.             if (LandPlayed==false && BasicsInPlay>=2 && FetchLandsInHand>=1 && remainingdeck.NumberOfBattleLands>=1) {
  128.                 FetchLandsInHand--;
  129.                 remainingdeck.NumberOfBattleLands--;
  130.                 if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=false;}
  131.                 LandPlayed=true;
  132.             }
  133.  
  134.             //3. Otherwise, if you can play a basic from hand, then do so
  135.             if (LandPlayed==false && BasicLandsInHand>=1) {
  136.                 BasicLandsInHand--;
  137.                 BasicsInPlay++;
  138.                 LandPlayed=true;
  139.             }
  140.            
  141.             //4. Otherwise, if you can fetch a basic, then do so
  142.             if (LandPlayed==false && FetchLandsInHand>=1 && remainingdeck.NumberOfBasicLands>=1) {
  143.                 FetchLandsInHand--;
  144.                 remainingdeck.NumberOfBasicLands--;
  145.                 BasicsInPlay++;
  146.                 LandPlayed=true;
  147.             }
  148.            
  149.             //5. Otherwise, play another land
  150.             if (LandPlayed==false && OtherLandsInHand>=1) {
  151.                 OtherLandsInHand--;
  152.                 LandPlayed=true;
  153.             }
  154.            
  155.             //6. Otherwise, play a Battle land
  156.             if (LandPlayed==false && BattleLandsInHand>=1) {
  157.                 BattleLandsInHand--;
  158.                 if (Turn==ProbabilityType) {GotABattleLandThisTurn=true; ThisLandEnteredTapped=true;}
  159.             }
  160.         }//end of the for-loop over the turns
  161.  
  162.         if (ProbabilityType<=2 && GotABattleLandThisTurn) {Outcome=1;}
  163.         if (ProbabilityType<=2 && !GotABattleLandThisTurn) {Outcome=0;}
  164.        
  165.         //Commented out below are alternative probabilities that I ran earlier but I wasn't thrilled with the interpretation
  166.         //if (ProbabilityType>=3 && GotABattleLandThisTurn && !ThisLandEnteredTapped) {Outcome=0;}
  167.         //if (ProbabilityType>=3 && GotABattleLandThisTurn && ThisLandEnteredTapped) {Outcome=1;}
  168.         //if (ProbabilityType>=3 && !GotABattleLandThisTurn) {Outcome=2;}
  169.        
  170.         if (ProbabilityType>=3 && EnoughBasicsAtStartTurn) {Outcome=0;}
  171.         if (ProbabilityType>=3 && !EnoughBasicsAtStartTurn) {Outcome=1;}
  172.        
  173.         return Outcome;
  174.        
  175.     }//end of SimulateGame
  176.    
  177. }
  178.  
  179. class OpeningHand {
  180.     int NumberOfBattleLands;
  181.     int NumberOfFetchLands;
  182.     int NumberOfBasicLands;
  183.     int NumberOfOtherLands;
  184.     int NumberOfSpells;
  185.  
  186.     int NrOfCards(){
  187.         return NumberOfBattleLands+NumberOfFetchLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfSpells;
  188.     }
  189.  
  190.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  191.         NumberOfBattleLands=Nr1;
  192.         NumberOfFetchLands=Nr2;
  193.         NumberOfBasicLands=Nr3;
  194.         NumberOfOtherLands=Nr4;
  195.         NumberOfSpells=Nr5;
  196.     }
  197.  
  198. }//end of OpeningHand
  199.  
  200. class Deck {
  201.     int NumberOfBattleLands;
  202.     int NumberOfFetchLands;
  203.     int NumberOfBasicLands;
  204.     int NumberOfOtherLands;
  205.     int NumberOfSpells;
  206.    
  207.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  208.         NumberOfBattleLands=Nr1;
  209.         NumberOfFetchLands=Nr2;
  210.         NumberOfBasicLands=Nr3;
  211.         NumberOfOtherLands=Nr4;
  212.         NumberOfSpells=Nr5;
  213.     }
  214.    
  215.     int NrOfCards(){
  216.         return NumberOfBattleLands+NumberOfFetchLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfSpells;
  217.     }
  218.    
  219.     int DrawCard (){
  220.         Random generator = new Random();
  221.         int CardType=0;
  222.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  223.         int OneCutoff=NumberOfBattleLands;
  224.         int TwoCutoff=OneCutoff+NumberOfFetchLands;
  225.         int ThreeCutoff=TwoCutoff+NumberOfBasicLands;
  226.         int FourCutoff=ThreeCutoff+NumberOfOtherLands;
  227.         int FiveCutoff=FourCutoff+NumberOfSpells;
  228.  
  229.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfBattleLands--;}
  230.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfFetchLands--;}
  231.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfBasicLands--;}
  232.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfOtherLands--;}
  233.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
  234.         return CardType;
  235.     }
  236.    
  237. }//end of Deck
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×