Advertisement
frankkarsten

Can you play 2 Chandra with 4 Oath of Nissa?

Jun 13th, 2016
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.47 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package levychandra;
  6.  
  7. import java.util.Arrays.*;
  8. import java.util.Random;
  9.  
  10. public class LevyChandra {
  11.  
  12.     public static void main(String[] args) {
  13.        
  14.         Deck deck=new Deck();
  15.  
  16.         //CardType 1 is an Oath of Nissa
  17.         //CardType 2 is a Chandra
  18.         //CardType 3 is a land
  19.         //CardType 4 is another non-land card
  20.                
  21.         deck.SetDeck(4,2,25,29);
  22.         double Probability=Probability=ProbabilityForRandomHand(deck,7,10000000);
  23.         System.out.println("Castable Chandra probability:"+Math.round(Probability*10000)/100.0);
  24.        
  25.     }//end of main
  26.  
  27.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
  28.         //ProbabilityType T: Probability that a Shadow land on turn T would enter the battlefield untapped (outcome: 0=tapped, 1=untapped)
  29.        
  30.         Deck remainingdeck=new Deck();
  31.         int NumberOfCastableChandra=0;
  32.         int NumberOfRelevantGames=0;
  33.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  34.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  35.             remainingdeck.SetDeck(deck.NumberOfOath-openinghand.NumberOfOath,deck.NumberOfChandra-openinghand.NumberOfChandra,deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfOther-openinghand.NumberOfOther);
  36.             int Outcome=SimulateGame(remainingdeck,openinghand);
  37.             if (Outcome==2) {NumberOfCastableChandra++; NumberOfRelevantGames++;}
  38.             if (Outcome==1) {NumberOfRelevantGames++;}
  39.         }
  40.         return NumberOfCastableChandra/(NumberOfRelevantGames+0.0);
  41.     }
  42.    
  43.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  44.        
  45.         Deck remainingdeck=new Deck();
  46.         OpeningHand openinghand=new OpeningHand();
  47.         int TypeOfCardDrawn;
  48.         boolean KeepHand=false;
  49.        
  50.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  51.             if (KeepHand==false){
  52.                 openinghand.SetHand(0,0,0,0);
  53.                 remainingdeck.SetDeck(deck.NumberOfOath,deck.NumberOfChandra,deck.NumberOfLands,deck.NumberOfOther);
  54.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  55.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  56.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfOath++;}
  57.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfChandra++;}
  58.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfLands++;}
  59.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfOther++;}
  60.                 }
  61.                 KeepHand=true;
  62.                 if (OpeningHandSize>1) {
  63.                     // We mulligan a hand if it contains 0, 1, 6, or 7 lands
  64.                     if (openinghand.NumberOfLands<=1 || openinghand.NumberOfLands>=6) {KeepHand=false;}
  65.                     if (OpeningHandSize==7 && openinghand.NumberOfLands==2 && openinghand.NumberOfChandra>=1 && openinghand.NumberOfOath==0) {KeepHand=false;}
  66.                 }
  67.             }
  68.         }
  69.        
  70.         return openinghand;
  71.     }//end of GiveOpeningHandAfterMulls
  72.    
  73.    
  74.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand) {
  75.        
  76.         int TypeOfCardDrawn;
  77.        
  78.         int LandsInHand=openinghand.NumberOfLands;
  79.         int ChandrasInHand=openinghand.NumberOfChandra;
  80.         int OathsInHand=openinghand.NumberOfOath;
  81.         int LandsInPlay=0;        
  82.         boolean OathInPlay=false;
  83.         boolean ChandraPlayed=false;
  84.         boolean ChandraFailure=false;
  85.        
  86.         for (int Turn=1; Turn<=10; Turn++){
  87.            
  88.             //We only go through the turn if we hadn't had the ability to cast a 6-drop yet
  89.             if (ChandraPlayed==false && ChandraFailure==false){
  90.            
  91.                 if (Turn>1) {
  92.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  93.                     if (TypeOfCardDrawn==1) {OathsInHand++;}
  94.                     if (TypeOfCardDrawn==2) {ChandrasInHand++;}
  95.                     if (TypeOfCardDrawn==3) {LandsInHand++;}
  96.                 }
  97.                 boolean LandPlayed=false;
  98.                
  99.                
  100.                 //1. If we can play a  land, we do so.
  101.                 if (LandsInHand>=1) {
  102.                     LandsInHand--;
  103.                     LandsInPlay++;
  104.                     LandPlayed=true;
  105.                 }
  106.  
  107.                 //2. If we can play a Chandra, we do so.
  108.                 if (ChandrasInHand>=1 && LandsInPlay>=6 && OathInPlay==true) {
  109.                     ChandrasInHand--;
  110.                     ChandraPlayed=true;
  111.                 }
  112.                
  113.                 //3. If we cannot cast Chandra, then that is an issue
  114.                 if (ChandrasInHand>=1 && LandsInPlay>=6 && OathInPlay==false) {
  115.                     ChandraFailure=true;
  116.                 }                
  117.                
  118.                 //4. If we can cast Oath of Nissa, we do so. (Only one per turn in this implementation, but that shouldn't matter.)
  119.                 if (OathsInHand>=1 && LandsInPlay>=1) {
  120.                     boolean LandAvailable=false;
  121.                     boolean ChandraTaken=false;
  122.                     OathsInHand--;
  123.                     for (int CardsSeen=1; CardsSeen<=3; CardsSeen++){
  124.                         TypeOfCardDrawn=remainingdeck.DrawCard();
  125.                         if (TypeOfCardDrawn==2) {ChandrasInHand++; ChandraTaken=true;} //Might get 2 Chandra in hand this way, but that doesn't matter
  126.                         if (TypeOfCardDrawn==3) {LandAvailable=true;}
  127.                     }
  128.                     if (ChandraTaken==false && LandAvailable==true) {LandsInHand++;}
  129.                     OathInPlay=true;
  130.                 }
  131.                
  132.                 //5. If we can make our land drop via Oath, we do so
  133.                 if (LandsInHand>=1 && LandPlayed==false) {
  134.                     LandsInHand--;
  135.                     LandsInPlay++;
  136.                     LandPlayed=true;
  137.                 }
  138.                
  139.                
  140.                 //6. If we can cast Chandra via Oath this turn, for which we need 7 lands total, we do so
  141.                 if (ChandrasInHand>=1 && LandsInPlay>=7 && OathInPlay==true) {
  142.                     ChandrasInHand--;
  143.                     ChandraPlayed=true;
  144.                 }
  145.                
  146.             }
  147.         }//end of the for-loop over the turns
  148.        
  149.         int Outcome=0;
  150.         if (ChandraPlayed) {Outcome=2;}
  151.         if (ChandraFailure) {Outcome=1;}
  152.        
  153.         return Outcome;
  154.        
  155.     }//end of SimulateGame
  156.    
  157.  
  158. }
  159.  
  160. class OpeningHand {
  161.     int NumberOfOath;
  162.     int NumberOfChandra;
  163.     int NumberOfLands;
  164.     int NumberOfOther;
  165.  
  166.     int NrOfCards(){
  167.         return NumberOfOath+NumberOfChandra+NumberOfLands+NumberOfOther;
  168.     }
  169.  
  170.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4) {
  171.         NumberOfOath=Nr1;
  172.         NumberOfChandra=Nr2;
  173.         NumberOfLands=Nr3;
  174.         NumberOfOther=Nr4;
  175.     }
  176.  
  177. }//end of OpeningHand
  178.  
  179. class Deck {
  180.     int NumberOfOath;
  181.     int NumberOfChandra;
  182.     int NumberOfLands;
  183.     int NumberOfOther;
  184.    
  185.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4) {
  186.         NumberOfOath=Nr1;
  187.         NumberOfChandra=Nr2;
  188.         NumberOfLands=Nr3;
  189.         NumberOfOther=Nr4;
  190.     }
  191.    
  192.     int NrOfCards(){
  193.         return NumberOfOath+NumberOfChandra+NumberOfLands+NumberOfOther;
  194.     }
  195.    
  196.     int DrawCard (){
  197.         Random generator = new Random();
  198.         int CardType=0;
  199.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  200.         int OneCutoff=NumberOfOath;
  201.         int TwoCutoff=OneCutoff+NumberOfChandra;
  202.         int ThreeCutoff=TwoCutoff+NumberOfLands;
  203.         int FourCutoff=ThreeCutoff+NumberOfOther;
  204.  
  205.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfOath--;}
  206.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfChandra--;}
  207.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfLands--;}
  208.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfOther--;}
  209.         return CardType;
  210.     }
  211.    
  212. }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement