Advertisement
frankkarsten

How often would you have a basic-type for a shadow land?

Mar 27th, 2016
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.58 KB | None | 0 0
  1. package shadowlands;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class ShadowLands {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.  
  12.         //CardType 1 is a Shadow land
  13.         //CardType 2 is a basic land (or Battle land) with the correct basic land type for the Shadow land
  14.         //CardType 3 is another land (e.g., creature-land or pain-land)
  15.         //CardType 4 is a non-land card
  16.         //CardType 5 is not used
  17.        
  18.         for (int basics=1; basics<=20; basics++){
  19.        
  20.             deck.SetDeck(4,basics,21-basics,35,0);
  21.             double Probability;
  22.  
  23.             System.out.println("=================================================");
  24.             System.out.println("We now consider a deck with "+basics+" basic-type lands");
  25.             System.out.println("=================================================");
  26.  
  27.             //The first output line give the percentage probability that a shadow land would enter the battlefield untapped on turn 1.
  28.             //The second output line gives the percentage probability that a shadow land would enter the battlefield untapped on turn 2.
  29.             //Etc.
  30.            
  31.             for (int turn=1; turn<=7; turn++){
  32.                 Probability=ProbabilityForRandomHand(deck,7,1000000,turn);
  33.                 System.out.println(Math.round(Probability*10000)/100.0);
  34.                 }
  35.            
  36.             System.out.println();
  37.  
  38.         }
  39.        
  40.     }//end of main
  41.  
  42.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
  43.         //ProbabilityType T: Probability that a Shadow land on turn T would enter the battlefield untapped (outcome: 0=tapped, 1=untapped)
  44.        
  45.         Deck remainingdeck=new Deck();
  46.         double NumberOfGamesWithFavorableOutcome=0;
  47.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  48.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  49.             remainingdeck.SetDeck(deck.NumberOfShadowLands-openinghand.NumberOfShadowLands,deck.NumberOfBasicLands-openinghand.NumberOfBasicLands,deck.NumberOfOtherLands-openinghand.NumberOfOtherLands,deck.NumberOfNonLandCards-openinghand.NumberOfNonLandCards,deck.NotUsed-openinghand.NotUsed);
  50.             int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
  51.             if (Outcome==1) {NumberOfGamesWithFavorableOutcome++;}
  52.         }
  53.         return NumberOfGamesWithFavorableOutcome/(NumberOfIterations+0.0);
  54.     }
  55.    
  56.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  57.        
  58.         Deck remainingdeck=new Deck();
  59.         OpeningHand openinghand=new OpeningHand();
  60.         int TypeOfCardDrawn;
  61.         boolean KeepHand=false;
  62.        
  63.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  64.             if (KeepHand==false){
  65.                 openinghand.SetHand(0,0,0,0,0);
  66.                 remainingdeck.SetDeck(deck.NumberOfShadowLands,deck.NumberOfBasicLands,deck.NumberOfOtherLands,deck.NumberOfNonLandCards,deck.NotUsed);
  67.                 int NumberOfLands=0;
  68.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  69.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  70.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfShadowLands++; NumberOfLands++;}
  71.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
  72.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
  73.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfNonLandCards++;}
  74.                     if (TypeOfCardDrawn==5) {openinghand.NotUsed++;}
  75.                 }
  76.                 KeepHand=true;
  77.                 if (OpeningHandSize>1) {
  78.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
  79.                     if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
  80.                     //
  81.                 }
  82.             }
  83.         }
  84.        
  85.         return openinghand;
  86.     }//end of GiveOpeningHandAfterMulls
  87.    
  88.    
  89.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
  90.        
  91.         int TypeOfCardDrawn=0;
  92.         int Outcome=2;
  93.         boolean GotAShadowLandThisTurn=false;
  94.         boolean ThisLandEnteredTapped=false;
  95.         boolean BasicLandInHandAtStartFirstMainPhase=false;
  96.        
  97.         int ShadowLandsInHand=openinghand.NumberOfShadowLands;
  98.         int BasicLandsInHand=openinghand.NumberOfBasicLands;
  99.         int OtherLandsInHand=openinghand.NumberOfOtherLands;
  100.                
  101.         for (int Turn=1; Turn<=7; Turn++){
  102.            
  103.             if (Turn>1) {
  104.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  105.                 if (TypeOfCardDrawn==1) {ShadowLandsInHand++;}
  106.                 if (TypeOfCardDrawn==2) {BasicLandsInHand++;}
  107.                 if (TypeOfCardDrawn==3) {OtherLandsInHand++;}
  108.             }
  109.             boolean LandPlayed=false;
  110.            
  111.             if (Turn==ProbabilityType && BasicLandsInHand>=1) {BasicLandInHandAtStartFirstMainPhase=true;}
  112.  
  113.             //1. If we can play an untapped Shadow land, we do so.
  114.             if (BasicLandsInHand>=1 && ShadowLandsInHand>=1) {
  115.                 ShadowLandsInHand--;
  116.                 LandPlayed=true;
  117.             }
  118.            
  119.             //2. Otherwise, if we can play an other land, we do so.
  120.             if (LandPlayed==false && OtherLandsInHand>=1) {
  121.                 OtherLandsInHand--;
  122.                 LandPlayed=true;
  123.             }
  124.  
  125.             //3.  Otherwise, if we can play a tapped Shadow land, we do so.
  126.             if (LandPlayed==false && BasicLandsInHand==0 && ShadowLandsInHand>=1) {
  127.                 ShadowLandsInHand--;
  128.                 LandPlayed=true;
  129.             }
  130.            
  131.             //4. Otherwise, finally, if we can play a basic land, we do so.
  132.             if (LandPlayed==false && BasicLandsInHand>=1) {
  133.                 BasicLandsInHand--;
  134.                 LandPlayed=true;
  135.             }
  136.            
  137.         }//end of the for-loop over the turns
  138.  
  139.         if (!BasicLandInHandAtStartFirstMainPhase) {Outcome=0;}
  140.         if (BasicLandInHandAtStartFirstMainPhase) {Outcome=1;}
  141.        
  142.         return Outcome;
  143.        
  144.     }//end of SimulateGame
  145.    
  146. }
  147.  
  148. class OpeningHand {
  149.     int NumberOfShadowLands;
  150.     int NumberOfBasicLands;
  151.     int NumberOfOtherLands;
  152.     int NumberOfNonLandCards;
  153.     int NotUsed;
  154.  
  155.     int NrOfCards(){
  156.         return NumberOfShadowLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfNonLandCards+NotUsed;
  157.     }
  158.  
  159.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  160.         NumberOfShadowLands=Nr1;
  161.         NumberOfBasicLands=Nr2;
  162.         NumberOfOtherLands=Nr3;
  163.         NumberOfNonLandCards=Nr4;
  164.         NotUsed=Nr5;
  165.     }
  166.  
  167. }//end of OpeningHand
  168.  
  169. class Deck {
  170.     int NumberOfShadowLands;
  171.     int NumberOfBasicLands;
  172.     int NumberOfOtherLands;
  173.     int NumberOfNonLandCards;
  174.     int NotUsed;
  175.    
  176.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  177.         NumberOfShadowLands=Nr1;
  178.         NumberOfBasicLands=Nr2;
  179.         NumberOfOtherLands=Nr3;
  180.         NumberOfNonLandCards=Nr4;
  181.         NotUsed=Nr5;
  182.     }
  183.    
  184.     int NrOfCards(){
  185.         return NumberOfShadowLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfNonLandCards+NotUsed;
  186.     }
  187.    
  188.     int DrawCard (){
  189.         Random generator = new Random();
  190.         int CardType=0;
  191.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  192.         int OneCutoff=NumberOfShadowLands;
  193.         int TwoCutoff=OneCutoff+NumberOfBasicLands;
  194.         int ThreeCutoff=TwoCutoff+NumberOfOtherLands;
  195.         int FourCutoff=ThreeCutoff+NumberOfNonLandCards;
  196.         int FiveCutoff=FourCutoff+NotUsed;
  197.  
  198.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfShadowLands--;}
  199.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfBasicLands--;}
  200.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfOtherLands--;}
  201.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfNonLandCards--;}
  202.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NotUsed--;}
  203.         return CardType;
  204.     }
  205.    
  206. }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement