Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package levychandra;
- import java.util.Arrays.*;
- import java.util.Random;
- public class LevyChandra {
- public static void main(String[] args) {
- Deck deck=new Deck();
- //CardType 1 is an Oath of Nissa
- //CardType 2 is a Chandra
- //CardType 3 is a land
- //CardType 4 is another non-land card
- deck.SetDeck(4,2,25,29);
- double Probability=Probability=ProbabilityForRandomHand(deck,7,10000000);
- System.out.println("Castable Chandra probability:"+Math.round(Probability*10000)/100.0);
- }//end of main
- public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
- //ProbabilityType T: Probability that a Shadow land on turn T would enter the battlefield untapped (outcome: 0=tapped, 1=untapped)
- Deck remainingdeck=new Deck();
- int NumberOfCastableChandra=0;
- int NumberOfRelevantGames=0;
- for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
- OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
- remainingdeck.SetDeck(deck.NumberOfOath-openinghand.NumberOfOath,deck.NumberOfChandra-openinghand.NumberOfChandra,deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfOther-openinghand.NumberOfOther);
- int Outcome=SimulateGame(remainingdeck,openinghand);
- if (Outcome==2) {NumberOfCastableChandra++; NumberOfRelevantGames++;}
- if (Outcome==1) {NumberOfRelevantGames++;}
- }
- return NumberOfCastableChandra/(NumberOfRelevantGames+0.0);
- }
- static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
- Deck remainingdeck=new Deck();
- OpeningHand openinghand=new OpeningHand();
- int TypeOfCardDrawn;
- boolean KeepHand=false;
- for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
- if (KeepHand==false){
- openinghand.SetHand(0,0,0,0);
- remainingdeck.SetDeck(deck.NumberOfOath,deck.NumberOfChandra,deck.NumberOfLands,deck.NumberOfOther);
- for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {openinghand.NumberOfOath++;}
- if (TypeOfCardDrawn==2) {openinghand.NumberOfChandra++;}
- if (TypeOfCardDrawn==3) {openinghand.NumberOfLands++;}
- if (TypeOfCardDrawn==4) {openinghand.NumberOfOther++;}
- }
- KeepHand=true;
- if (OpeningHandSize>1) {
- // We mulligan a hand if it contains 0, 1, 6, or 7 lands
- if (openinghand.NumberOfLands<=1 || openinghand.NumberOfLands>=6) {KeepHand=false;}
- if (OpeningHandSize==7 && openinghand.NumberOfLands==2 && openinghand.NumberOfChandra>=1 && openinghand.NumberOfOath==0) {KeepHand=false;}
- }
- }
- }
- return openinghand;
- }//end of GiveOpeningHandAfterMulls
- static int SimulateGame(Deck remainingdeck, OpeningHand openinghand) {
- int TypeOfCardDrawn;
- int LandsInHand=openinghand.NumberOfLands;
- int ChandrasInHand=openinghand.NumberOfChandra;
- int OathsInHand=openinghand.NumberOfOath;
- int LandsInPlay=0;
- boolean OathInPlay=false;
- boolean ChandraPlayed=false;
- boolean ChandraFailure=false;
- for (int Turn=1; Turn<=10; Turn++){
- //We only go through the turn if we hadn't had the ability to cast a 6-drop yet
- if (ChandraPlayed==false && ChandraFailure==false){
- if (Turn>1) {
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {OathsInHand++;}
- if (TypeOfCardDrawn==2) {ChandrasInHand++;}
- if (TypeOfCardDrawn==3) {LandsInHand++;}
- }
- boolean LandPlayed=false;
- //1. If we can play a land, we do so.
- if (LandsInHand>=1) {
- LandsInHand--;
- LandsInPlay++;
- LandPlayed=true;
- }
- //2. If we can play a Chandra, we do so.
- if (ChandrasInHand>=1 && LandsInPlay>=6 && OathInPlay==true) {
- ChandrasInHand--;
- ChandraPlayed=true;
- }
- //3. If we cannot cast Chandra, then that is an issue
- if (ChandrasInHand>=1 && LandsInPlay>=6 && OathInPlay==false) {
- ChandraFailure=true;
- }
- //4. If we can cast Oath of Nissa, we do so. (Only one per turn in this implementation, but that shouldn't matter.)
- if (OathsInHand>=1 && LandsInPlay>=1) {
- boolean LandAvailable=false;
- boolean ChandraTaken=false;
- OathsInHand--;
- for (int CardsSeen=1; CardsSeen<=3; CardsSeen++){
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==2) {ChandrasInHand++; ChandraTaken=true;} //Might get 2 Chandra in hand this way, but that doesn't matter
- if (TypeOfCardDrawn==3) {LandAvailable=true;}
- }
- if (ChandraTaken==false && LandAvailable==true) {LandsInHand++;}
- OathInPlay=true;
- }
- //5. If we can make our land drop via Oath, we do so
- if (LandsInHand>=1 && LandPlayed==false) {
- LandsInHand--;
- LandsInPlay++;
- LandPlayed=true;
- }
- //6. If we can cast Chandra via Oath this turn, for which we need 7 lands total, we do so
- if (ChandrasInHand>=1 && LandsInPlay>=7 && OathInPlay==true) {
- ChandrasInHand--;
- ChandraPlayed=true;
- }
- }
- }//end of the for-loop over the turns
- int Outcome=0;
- if (ChandraPlayed) {Outcome=2;}
- if (ChandraFailure) {Outcome=1;}
- return Outcome;
- }//end of SimulateGame
- }
- class OpeningHand {
- int NumberOfOath;
- int NumberOfChandra;
- int NumberOfLands;
- int NumberOfOther;
- int NrOfCards(){
- return NumberOfOath+NumberOfChandra+NumberOfLands+NumberOfOther;
- }
- void SetHand (int Nr1, int Nr2, int Nr3, int Nr4) {
- NumberOfOath=Nr1;
- NumberOfChandra=Nr2;
- NumberOfLands=Nr3;
- NumberOfOther=Nr4;
- }
- }//end of OpeningHand
- class Deck {
- int NumberOfOath;
- int NumberOfChandra;
- int NumberOfLands;
- int NumberOfOther;
- void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4) {
- NumberOfOath=Nr1;
- NumberOfChandra=Nr2;
- NumberOfLands=Nr3;
- NumberOfOther=Nr4;
- }
- int NrOfCards(){
- return NumberOfOath+NumberOfChandra+NumberOfLands+NumberOfOther;
- }
- int DrawCard (){
- Random generator = new Random();
- int CardType=0;
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
- int OneCutoff=NumberOfOath;
- int TwoCutoff=OneCutoff+NumberOfChandra;
- int ThreeCutoff=TwoCutoff+NumberOfLands;
- int FourCutoff=ThreeCutoff+NumberOfOther;
- if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfOath--;}
- if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfChandra--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfOther--;}
- return CardType;
- }
- }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement