frankkarsten

How many Dinos do you need to enable Thunderherd Migration?

Jan 6th, 2018
326
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package thunderherdmigration;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class ThunderherdMigration {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.            
  12.         //CardType 1 is a land
  13.         //CardType 2 is a Thunderherd
  14.         //CardType 3 is a Dino
  15.         //CardType 4 is not used
  16.         //CardType 5 is another card
  17.        
  18.        
  19.         for (int NrDinos=1; NrDinos<=20; NrDinos++){
  20.             deck.SetDeck(24,4,NrDinos,0,60-28-NrDinos);
  21.             double Probability=ProbabilityForRandomHand(deck,7,10000000);
  22.             //System.out.print("Probability of being able to reveal a turn-2 Dino in games where you have a Thunderherd after mulls);
  23.             System.out.println(Math.round(Probability*10000)/100.0);
  24.         }
  25.                
  26.     }//end of main
  27.  
  28.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
  29.         Deck remainingdeck=new Deck();
  30.         double NumberOfGamesWithfavorableOutcome=0;
  31.         double NumberOfGamesWithTurn2Thunderherd=0;
  32.         //On the play
  33.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  34.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  35.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  36.            
  37.             int Outcome=SimulateGame(remainingdeck,openinghand,true);
  38.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithTurn2Thunderherd++;}
  39.             if (Outcome==1) {NumberOfGamesWithTurn2Thunderherd++;}
  40.         }
  41.         //On the draw; this is a copy-paste where the only change is that the boolean is now false
  42.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  43.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  44.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  45.             int Outcome=SimulateGame(remainingdeck,openinghand,false);
  46.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithTurn2Thunderherd++;}
  47.             if (Outcome==1) {NumberOfGamesWithTurn2Thunderherd++;}
  48.         }
  49.  
  50.         return NumberOfGamesWithfavorableOutcome/(NumberOfGamesWithTurn2Thunderherd+0.0);
  51.     }//end of AverageKillTurnForRandomHand
  52.    
  53.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  54.        
  55.         Deck remainingdeck=new Deck();
  56.         OpeningHand openinghand=new OpeningHand();
  57.         int TypeOfCardDrawn;
  58.         boolean KeepHand=false;
  59.        
  60.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  61.             if (KeepHand==false){
  62.                 openinghand.SetHand(0,0,0,0,0);
  63.                 remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
  64.                 int NumberOfLands=0;
  65.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  66.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  67.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
  68.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
  69.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
  70.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
  71.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
  72.                 }
  73.                 KeepHand=true;
  74.                 if (OpeningHandSize>1) {
  75.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
  76.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
  77.                     //
  78.                 }
  79.             }
  80.         }
  81.        
  82.         return openinghand;
  83.     }//end of GiveOpeningHandAfterMulls
  84.    
  85.    
  86.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, boolean OnThePlay) {
  87.        
  88.         //Initializing
  89.         int TypeOfCardDrawn=0;
  90.         int Outcome=2;
  91.  
  92.         int ThunderherdInHand=openinghand.NumberOfCardType2;
  93.         int DinosInHand=openinghand.NumberOfCardType3;
  94.        
  95.         //Turn 1
  96.        
  97.         if (OnThePlay==false) {
  98.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  99.                 if (TypeOfCardDrawn==2) {ThunderherdInHand++;}
  100.                 if (TypeOfCardDrawn==3) {DinosInHand++;}
  101.             }
  102.        
  103.         //Turn 2
  104.        
  105.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  106.                 if (TypeOfCardDrawn==2) {ThunderherdInHand++;}
  107.                 if (TypeOfCardDrawn==3) {DinosInHand++;}
  108.        
  109.         if (ThunderherdInHand>=1 && DinosInHand>=1) {Outcome=0;}
  110.         if (ThunderherdInHand>=1 && DinosInHand==0) {Outcome=1;}
  111.        
  112.         return Outcome;
  113.  
  114. /*
  115. NOTE: FOR DARING BUCCANEER THIS FUNCTION BECOMES AS FOLLOWS:
  116.  
  117.         int TypeOfCardDrawn=0;
  118.         int Outcome=2;
  119.  
  120.         int BuccaneersInHand=openinghand.NumberOfCardType2;
  121.         int PiratesInHand=openinghand.NumberOfCardType3;
  122.        
  123.         if (OnThePlay==false) {
  124.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  125.                 if (TypeOfCardDrawn==2) {BuccaneersInHand++;}
  126.                 if (TypeOfCardDrawn==3) {PiratesInHand++;}
  127.             }
  128.        
  129.         int TotalPirates = PiratesInHand;
  130.         if (BuccaneersInHand>=2) {TotalPirates++;}
  131.        
  132.         if (BuccaneersInHand>=1 && TotalPirates>=1) {Outcome=0;}
  133.         if (BuccaneersInHand>=1 && TotalPirates==0) {Outcome=1;}
  134.        
  135. */        
  136.  
  137.  
  138.  
  139.     }//end of SimulateGame
  140.    
  141. }
  142.  
  143. class OpeningHand {
  144.     int NumberOfLands;
  145.     int NumberOfCardType2;
  146.     int NumberOfCardType3;
  147.     int NumberOfCardType4;
  148.     int NumberOfSpells;
  149.  
  150.     int NrOfCards(){
  151.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  152.     }
  153.  
  154.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  155.         NumberOfLands=Nr1;
  156.         NumberOfCardType2=Nr2;
  157.         NumberOfCardType3=Nr3;
  158.         NumberOfCardType4=Nr4;
  159.         NumberOfSpells=Nr5;
  160.     }
  161.  
  162. }//end of OpeningHand
  163.  
  164. class Deck {
  165.     int NumberOfLands;
  166.     int NumberOfCardType2;
  167.     int NumberOfCardType3;
  168.     int NumberOfCardType4;
  169.     int NumberOfSpells;
  170.    
  171.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  172.         NumberOfLands=Nr1;
  173.         NumberOfCardType2=Nr2;
  174.         NumberOfCardType3=Nr3;
  175.         NumberOfCardType4=Nr4;
  176.         NumberOfSpells=Nr5;
  177.     }
  178.    
  179.     int NrOfCards(){
  180.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  181.     }
  182.    
  183.     int DrawCard (){
  184.         Random generator = new Random();
  185.         int CardType=0;
  186.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  187.         int OneCutoff=NumberOfLands;
  188.         int TwoCutoff=OneCutoff+NumberOfCardType2;
  189.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
  190.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
  191.         int FiveCutoff=FourCutoff+NumberOfSpells;
  192.  
  193.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfLands--;}
  194.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
  195.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
  196.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
  197.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
  198.         return CardType;
  199.     }
  200.    
  201. }//end of Deck
RAW Paste Data