frankkarsten

How many Wizards do you need to turn Wizard’s Lightning into

Mar 12th, 2018
253
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package wizardslightning;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class WizardsLightning {
  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 Wizard's Lightning
  14.         //CardType 3 is a Wizard
  15.         //CardType 4 is not used
  16.         //CardType 5 is another card
  17.        
  18.         /*ASSUMPTIONS:
  19.         - We consider a 60-deck with a 60-card deck with 24 lands, 4 Wizard’s Lightning, and a certain number of Wizards.
  20.     - We mulligan a hand if it contains 0, 1, 6, or 7 lands. In case of a mulligan, we ignore the free scry.
  21.     - We assume that we are always able to cast any Wizard we draw. That is, the availability of colored mana to cast our Wizards is disregarded. This assumption is reasonable if the majority of our Wizards cost one or two mana. Suitably, those are exactly the type of Wizards that are ideal to support Wizard's Lightning.
  22.     - We are on the play and on the draw with equal 50-50 probability.
  23.     - We consider the following question: If I have a Wizards Lightning in hand on turn 2 (or any other turn number to be manually adjusted in the SimulateGame function), then what is the probability of also having a Wizard in hand? In other words, we determine a conditional probability for settings where at least one of our cards (not necessarily the first one we draw) is already taken up by a Wizard's Lightning.
  24.         */
  25.        
  26.         for (int NrWizards=1; NrWizards<=20; NrWizards++){
  27.             deck.SetDeck(24,4,NrWizards,0,60-28-NrWizards);
  28.             double Probability=ProbabilityForRandomHand(deck,7,10000000);
  29.             //System.out.print("Probability of having a legend in games where you have a Mox Amber after mulls in a deck with "+NrLegends+" legends: ");
  30.             System.out.println(Math.round(Probability*10000)/100.0);
  31.         }
  32.                
  33.     }//end of main
  34.  
  35.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
  36.         Deck remainingdeck=new Deck();
  37.         double NumberOfGamesWithfavorableOutcome=0;
  38.         double NumberOfGamesWithLightning=0;
  39.         //On the play
  40.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  41.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  42.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  43.            
  44.             int Outcome=SimulateGame(remainingdeck,openinghand,true);
  45.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithLightning++;}
  46.             if (Outcome==1) {NumberOfGamesWithLightning++;}
  47.         }
  48.         //On the draw; this is a copy-paste where the only change is that the boolean is now false
  49.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  50.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  51.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  52.             int Outcome=SimulateGame(remainingdeck,openinghand,false);
  53.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithLightning++;}
  54.             if (Outcome==1) {NumberOfGamesWithLightning++;}
  55.         }
  56.  
  57.         return NumberOfGamesWithfavorableOutcome/(NumberOfGamesWithLightning+0.0);
  58.     }//end of AverageKillTurnForRandomHand
  59.    
  60.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  61.        
  62.         Deck remainingdeck=new Deck();
  63.         OpeningHand openinghand=new OpeningHand();
  64.         int TypeOfCardDrawn;
  65.         boolean KeepHand=false;
  66.        
  67.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  68.             if (KeepHand==false){
  69.                 openinghand.SetHand(0,0,0,0,0);
  70.                 remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
  71.                 int NumberOfLands=0;
  72.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  73.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  74.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
  75.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
  76.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
  77.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
  78.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
  79.                 }
  80.                 KeepHand=true;
  81.                 if (OpeningHandSize>1) {
  82.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
  83.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
  84.                     //
  85.                 }
  86.             }
  87.         }
  88.        
  89.         return openinghand;
  90.     }//end of GiveOpeningHandAfterMulls
  91.    
  92.    
  93.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, boolean OnThePlay) {
  94.        
  95.         //Initializing
  96.         int TypeOfCardDrawn=0;
  97.         int Outcome=2;
  98.         int Turn=4;
  99.        
  100.         int LightningInHand=openinghand.NumberOfCardType2;
  101.         int WizardInHand=openinghand.NumberOfCardType3;
  102.        
  103.         //Turn 1
  104.        
  105.         if (OnThePlay==false) {
  106.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  107.                 if (TypeOfCardDrawn==2) {LightningInHand++;}
  108.                 if (TypeOfCardDrawn==3) {WizardInHand++;}
  109.             }
  110.        
  111.         //Turn 2
  112.        
  113.         if (Turn>=2){
  114.             TypeOfCardDrawn=remainingdeck.DrawCard();
  115.             if (TypeOfCardDrawn==2) {LightningInHand++;}
  116.             if (TypeOfCardDrawn==3) {WizardInHand++;}
  117.         }
  118.  
  119.         //Turn 3
  120.        
  121.         if (Turn>=3){
  122.             TypeOfCardDrawn=remainingdeck.DrawCard();
  123.             if (TypeOfCardDrawn==2) {LightningInHand++;}
  124.             if (TypeOfCardDrawn==3) {WizardInHand++;}
  125.         }
  126.        
  127.         //Turn 4
  128.        
  129.         if (Turn>=4){
  130.             TypeOfCardDrawn=remainingdeck.DrawCard();
  131.             if (TypeOfCardDrawn==2) {LightningInHand++;}
  132.             if (TypeOfCardDrawn==3) {WizardInHand++;}
  133.         }
  134.        
  135.         if (LightningInHand>=1 && WizardInHand>=1) {Outcome=0;}
  136.         if (LightningInHand>=1 && WizardInHand==0) {Outcome=1;}
  137.        
  138.         return Outcome;
  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