SHARE
TWEET

How many legends do you need for Mox Amber?

frankkarsten Mar 10th, 2018 355 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package moxamber;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class MoxAmber {
  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 Mox
  14.         //CardType 3 is a legend
  15.         //CardType 4 is not used
  16.         //CardType 5 is another card
  17.        
  18.          //Note: Adjust the turn in the SimulateGame function manually
  19.  
  20.         for (int NrLegends=1; NrLegends<=20; NrLegends++){
  21.             deck.SetDeck(21,4,NrLegends,0,60-25-NrLegends);
  22.             double Probability=ProbabilityForRandomHand(deck,7,10000000);
  23.             //System.out.print("Probability of having a legend in games where you have a Mox Amber after mulls in a deck with "+NrLegends+" legends: ");
  24.             System.out.println(Math.round(Probability*10000)/100.0);
  25.         }
  26.                
  27.     }//end of main
  28.  
  29.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
  30.         Deck remainingdeck=new Deck();
  31.         double NumberOfGamesWithfavorableOutcome=0;
  32.         double NumberOfGamesWithMox=0;
  33.         //On the play
  34.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  35.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  36.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  37.            
  38.             int Outcome=SimulateGame(remainingdeck,openinghand,true);
  39.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithMox++;}
  40.             if (Outcome==1) {NumberOfGamesWithMox++;}
  41.         }
  42.         //On the draw; this is a copy-paste where the only change is that the boolean is now false
  43.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  44.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  45.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  46.             int Outcome=SimulateGame(remainingdeck,openinghand,false);
  47.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGamesWithMox++;}
  48.             if (Outcome==1) {NumberOfGamesWithMox++;}
  49.         }
  50.  
  51.         return NumberOfGamesWithfavorableOutcome/(NumberOfGamesWithMox+0.0);
  52.     }//end of AverageKillTurnForRandomHand
  53.    
  54.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  55.        
  56.         Deck remainingdeck=new Deck();
  57.         OpeningHand openinghand=new OpeningHand();
  58.         int TypeOfCardDrawn;
  59.         boolean KeepHand=false;
  60.        
  61.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  62.             if (KeepHand==false){
  63.                 openinghand.SetHand(0,0,0,0,0);
  64.                 remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
  65.                 int NumberOfLands=0;
  66.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  67.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  68.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
  69.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++; NumberOfLands++;}
  70.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
  71.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
  72.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
  73.                 }
  74.                 KeepHand=true;
  75.                 if (OpeningHandSize>1) {
  76.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
  77.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
  78.                     //
  79.                 }
  80.             }
  81.         }
  82.        
  83.         return openinghand;
  84.     }//end of GiveOpeningHandAfterMulls
  85.    
  86.    
  87.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, boolean OnThePlay) {
  88.        
  89.         //Initializing
  90.         int TypeOfCardDrawn=0;
  91.         int Outcome=2;
  92.         int Turn=3;
  93.        
  94.         int MoxInHand=openinghand.NumberOfCardType2;
  95.         int LegendsInHand=openinghand.NumberOfCardType3;
  96.        
  97.         //Turn 1
  98.        
  99.         if (OnThePlay==false) {
  100.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  101.                 if (TypeOfCardDrawn==2) {MoxInHand++;}
  102.                 if (TypeOfCardDrawn==3) {LegendsInHand++;}
  103.             }
  104.        
  105.         //Turn 2
  106.        
  107.         if (Turn>=2){
  108.             TypeOfCardDrawn=remainingdeck.DrawCard();
  109.             if (TypeOfCardDrawn==2) {MoxInHand++;}
  110.             if (TypeOfCardDrawn==3) {LegendsInHand++;}
  111.         }
  112.  
  113.         //Turn 2
  114.        
  115.         if (Turn>=3){
  116.             TypeOfCardDrawn=remainingdeck.DrawCard();
  117.             if (TypeOfCardDrawn==2) {MoxInHand++;}
  118.             if (TypeOfCardDrawn==3) {LegendsInHand++;}
  119.         }
  120.        
  121.         if (MoxInHand>=1 && LegendsInHand>=1) {Outcome=0;}
  122.         if (MoxInHand>=1 && LegendsInHand==0) {Outcome=1;}
  123.        
  124.         return Outcome;
  125.     }//end of SimulateGame
  126.    
  127. }
  128.  
  129. class OpeningHand {
  130.     int NumberOfLands;
  131.     int NumberOfCardType2;
  132.     int NumberOfCardType3;
  133.     int NumberOfCardType4;
  134.     int NumberOfSpells;
  135.  
  136.     int NrOfCards(){
  137.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  138.     }
  139.  
  140.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  141.         NumberOfLands=Nr1;
  142.         NumberOfCardType2=Nr2;
  143.         NumberOfCardType3=Nr3;
  144.         NumberOfCardType4=Nr4;
  145.         NumberOfSpells=Nr5;
  146.     }
  147.  
  148. }//end of OpeningHand
  149.  
  150. class Deck {
  151.     int NumberOfLands;
  152.     int NumberOfCardType2;
  153.     int NumberOfCardType3;
  154.     int NumberOfCardType4;
  155.     int NumberOfSpells;
  156.    
  157.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  158.         NumberOfLands=Nr1;
  159.         NumberOfCardType2=Nr2;
  160.         NumberOfCardType3=Nr3;
  161.         NumberOfCardType4=Nr4;
  162.         NumberOfSpells=Nr5;
  163.     }
  164.    
  165.     int NrOfCards(){
  166.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  167.     }
  168.    
  169.     int DrawCard (){
  170.         Random generator = new Random();
  171.         int CardType=0;
  172.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  173.         int OneCutoff=NumberOfLands;
  174.         int TwoCutoff=OneCutoff+NumberOfCardType2;
  175.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
  176.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
  177.         int FiveCutoff=FourCutoff+NumberOfSpells;
  178.  
  179.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfLands--;}
  180.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
  181.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
  182.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
  183.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
  184.         return CardType;
  185.     }
  186.    
  187. }//end of Deck
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top