Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package shadowlands;
- import java.util.Arrays.*;
- import java.util.Random;
- public class ShadowLands {
- public static void main(String[] args) {
- Deck deck=new Deck();
- //CardType 1 is a Shadow land
- //CardType 2 is a basic land (or Battle land) with the correct basic land type for the Shadow land
- //CardType 3 is another land (e.g., creature-land or pain-land)
- //CardType 4 is a non-land card
- //CardType 5 is not used
- for (int basics=1; basics<=20; basics++){
- deck.SetDeck(4,basics,21-basics,35,0);
- double Probability;
- System.out.println("=================================================");
- System.out.println("We now consider a deck with "+basics+" basic-type lands");
- System.out.println("=================================================");
- //The first output line give the percentage probability that a shadow land would enter the battlefield untapped on turn 1.
- //The second output line gives the percentage probability that a shadow land would enter the battlefield untapped on turn 2.
- //Etc.
- for (int turn=1; turn<=7; turn++){
- Probability=ProbabilityForRandomHand(deck,7,1000000,turn);
- System.out.println(Math.round(Probability*10000)/100.0);
- }
- System.out.println();
- }
- }//end of main
- public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
- //ProbabilityType T: Probability that a Shadow land on turn T would enter the battlefield untapped (outcome: 0=tapped, 1=untapped)
- Deck remainingdeck=new Deck();
- double NumberOfGamesWithFavorableOutcome=0;
- for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
- OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
- remainingdeck.SetDeck(deck.NumberOfShadowLands-openinghand.NumberOfShadowLands,deck.NumberOfBasicLands-openinghand.NumberOfBasicLands,deck.NumberOfOtherLands-openinghand.NumberOfOtherLands,deck.NumberOfNonLandCards-openinghand.NumberOfNonLandCards,deck.NotUsed-openinghand.NotUsed);
- int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
- if (Outcome==1) {NumberOfGamesWithFavorableOutcome++;}
- }
- return NumberOfGamesWithFavorableOutcome/(NumberOfIterations+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,0);
- remainingdeck.SetDeck(deck.NumberOfShadowLands,deck.NumberOfBasicLands,deck.NumberOfOtherLands,deck.NumberOfNonLandCards,deck.NotUsed);
- int NumberOfLands=0;
- for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {openinghand.NumberOfShadowLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==2) {openinghand.NumberOfBasicLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==3) {openinghand.NumberOfOtherLands++; NumberOfLands++;}
- if (TypeOfCardDrawn==4) {openinghand.NumberOfNonLandCards++;}
- if (TypeOfCardDrawn==5) {openinghand.NotUsed++;}
- }
- KeepHand=true;
- if (OpeningHandSize>1) {
- // We mulligan a hand if it contains 0, 1, 6, or 7 lands
- if (NumberOfLands<=1 || NumberOfLands>=6) {KeepHand=false;}
- //
- }
- }
- }
- return openinghand;
- }//end of GiveOpeningHandAfterMulls
- static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
- int TypeOfCardDrawn=0;
- int Outcome=2;
- boolean GotAShadowLandThisTurn=false;
- boolean ThisLandEnteredTapped=false;
- boolean BasicLandInHandAtStartFirstMainPhase=false;
- int ShadowLandsInHand=openinghand.NumberOfShadowLands;
- int BasicLandsInHand=openinghand.NumberOfBasicLands;
- int OtherLandsInHand=openinghand.NumberOfOtherLands;
- for (int Turn=1; Turn<=7; Turn++){
- if (Turn>1) {
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {ShadowLandsInHand++;}
- if (TypeOfCardDrawn==2) {BasicLandsInHand++;}
- if (TypeOfCardDrawn==3) {OtherLandsInHand++;}
- }
- boolean LandPlayed=false;
- if (Turn==ProbabilityType && BasicLandsInHand>=1) {BasicLandInHandAtStartFirstMainPhase=true;}
- //1. If we can play an untapped Shadow land, we do so.
- if (BasicLandsInHand>=1 && ShadowLandsInHand>=1) {
- ShadowLandsInHand--;
- LandPlayed=true;
- }
- //2. Otherwise, if we can play an other land, we do so.
- if (LandPlayed==false && OtherLandsInHand>=1) {
- OtherLandsInHand--;
- LandPlayed=true;
- }
- //3. Otherwise, if we can play a tapped Shadow land, we do so.
- if (LandPlayed==false && BasicLandsInHand==0 && ShadowLandsInHand>=1) {
- ShadowLandsInHand--;
- LandPlayed=true;
- }
- //4. Otherwise, finally, if we can play a basic land, we do so.
- if (LandPlayed==false && BasicLandsInHand>=1) {
- BasicLandsInHand--;
- LandPlayed=true;
- }
- }//end of the for-loop over the turns
- if (!BasicLandInHandAtStartFirstMainPhase) {Outcome=0;}
- if (BasicLandInHandAtStartFirstMainPhase) {Outcome=1;}
- return Outcome;
- }//end of SimulateGame
- }
- class OpeningHand {
- int NumberOfShadowLands;
- int NumberOfBasicLands;
- int NumberOfOtherLands;
- int NumberOfNonLandCards;
- int NotUsed;
- int NrOfCards(){
- return NumberOfShadowLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfNonLandCards+NotUsed;
- }
- void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
- NumberOfShadowLands=Nr1;
- NumberOfBasicLands=Nr2;
- NumberOfOtherLands=Nr3;
- NumberOfNonLandCards=Nr4;
- NotUsed=Nr5;
- }
- }//end of OpeningHand
- class Deck {
- int NumberOfShadowLands;
- int NumberOfBasicLands;
- int NumberOfOtherLands;
- int NumberOfNonLandCards;
- int NotUsed;
- void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
- NumberOfShadowLands=Nr1;
- NumberOfBasicLands=Nr2;
- NumberOfOtherLands=Nr3;
- NumberOfNonLandCards=Nr4;
- NotUsed=Nr5;
- }
- int NrOfCards(){
- return NumberOfShadowLands+NumberOfBasicLands+NumberOfOtherLands+NumberOfNonLandCards+NotUsed;
- }
- int DrawCard (){
- Random generator = new Random();
- int CardType=0;
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
- int OneCutoff=NumberOfShadowLands;
- int TwoCutoff=OneCutoff+NumberOfBasicLands;
- int ThreeCutoff=TwoCutoff+NumberOfOtherLands;
- int FourCutoff=ThreeCutoff+NumberOfNonLandCards;
- int FiveCutoff=FourCutoff+NotUsed;
- if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfShadowLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfBasicLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfOtherLands--;}
- if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfNonLandCards--;}
- if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NotUsed--;}
- return CardType;
- }
- }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement