Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cardsimulator;
- import java.util.Random;
- public class CardSimulator {
- public static void main(String[] args) {
- int NrSims=10000000;
- //CardType1=Mountain
- //CardType2=Mana Confluence
- //CardType3=Atarka's Command
- //CardType4=other
- int NrGamesWithCommand=0;
- int NrGamesWithCommandAndMana=0;
- for (int i=1; i<=NrSims; i++){
- int Outcome=Simulate();
- if (Outcome>=1) {NrGamesWithCommand++;}
- if (Outcome==2) {NrGamesWithCommandAndMana++;}
- }
- System.out.println((NrGamesWithCommandAndMana+0.0)/NrGamesWithCommand);
- }
- static int Simulate() {
- int TypeOfCardDrawn;
- Deck deck=new Deck();
- int Outcome=0;
- Random generator = new Random();
- int ExtraCardBecauseWeAreOnTheDraw=0;
- if (generator.nextDouble()<=0.5) {ExtraCardBecauseWeAreOnTheDraw++;}
- //We keep a seven-card hand if and only if it has 2 or 3 lands
- deck.SetDeck(10, 10, 4, 36, 0, 0);
- int NrLands=0;
- int NrGreenSources=0;
- int NrCommand=0;
- for (int i=1; i<=7; i++){
- TypeOfCardDrawn=deck.DrawCard();
- if (TypeOfCardDrawn==1) {NrLands++;}
- if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
- if (TypeOfCardDrawn==3) {NrCommand++;}
- }
- if (NrLands==2 || NrLands==3) {
- for (int i=1; i<=3+ExtraCardBecauseWeAreOnTheDraw; i++){
- TypeOfCardDrawn=deck.DrawCard();
- if (TypeOfCardDrawn==1) {NrLands++;}
- if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
- if (TypeOfCardDrawn==3) {NrCommand++;}
- }
- if (NrCommand==0) {Outcome=0;}
- if (NrCommand>=1 && NrGreenSources==0) {Outcome=1;}
- if (NrCommand>=1 && NrGreenSources>0) {Outcome=2;}
- }
- else {
- //We keep a six-card hand if and only if it has 1, 2, or 3 lands
- deck.SetDeck(10, 10, 4, 36, 0, 0);
- NrLands=0;
- NrGreenSources=0;
- NrCommand=0;
- for (int i=1; i<=6; i++){
- TypeOfCardDrawn=deck.DrawCard();
- if (TypeOfCardDrawn==1) {NrLands++;}
- if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
- if (TypeOfCardDrawn==3) {NrCommand++;}
- }
- if (NrLands>=1 || NrLands<=3) {
- for (int i=1; i<=3+ExtraCardBecauseWeAreOnTheDraw; i++){
- TypeOfCardDrawn=deck.DrawCard();
- if (TypeOfCardDrawn==1) {NrLands++;}
- if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
- if (TypeOfCardDrawn==3) {NrCommand++;}
- }
- if (NrCommand==0) {Outcome=0;}
- if (NrCommand>=1 && NrGreenSources==0) {Outcome=1;}
- if (NrCommand>=1 && NrGreenSources>0) {Outcome=2;}
- }
- else {
- //We always keep every five-card hand
- deck.SetDeck(10, 10, 4, 36, 0, 0);
- NrLands=0;
- NrGreenSources=0;
- NrCommand=0;
- for (int i=1; i<=5+3+ExtraCardBecauseWeAreOnTheDraw; i++){
- TypeOfCardDrawn=deck.DrawCard();
- if (TypeOfCardDrawn==1) {NrLands++;}
- if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
- if (TypeOfCardDrawn==3) {NrCommand++;}
- }
- if (NrCommand==0) {Outcome=0;}
- if (NrCommand>=1 && NrGreenSources==0) {Outcome=1;}
- if (NrCommand>=1 && NrGreenSources>0) {Outcome=2;}
- }
- }
- return Outcome;
- }
- static class Deck {
- int NrCardType1;
- int NrCardType2;
- int NrCardType3;
- int NrCardType4;
- int NrCardType5;
- int NrCardType6;
- void PrintDeckBrief () {
- if(NrCardType1<10) {System.out.print("0");}
- System.out.print(NrCardType1+" ");
- if(NrCardType2<10) {System.out.print("0");}
- System.out.print(NrCardType2+" ");
- if(NrCardType3<10) {System.out.print("0");}
- System.out.print(NrCardType3+" ");
- if(NrCardType4<10) {System.out.print("0");}
- System.out.print(NrCardType4+" ");
- if(NrCardType5<10) {System.out.print("0");}
- System.out.print(NrCardType5+" ");
- if(NrCardType6<10) {System.out.print("0");}
- System.out.print(NrCardType6);
- System.out.print(" ");
- }
- void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
- NrCardType1=Nr1;
- NrCardType2=Nr2;
- NrCardType3=Nr3;
- NrCardType4=Nr4;
- NrCardType5=Nr5;
- NrCardType6=Nr6;
- }
- int NrOfCards(){
- return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
- }
- int DrawCard (){
- Random generator = new Random();
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
- int CardType=0;
- int OneCutoff=NrCardType1;
- int TwoCutoff=OneCutoff+NrCardType2;
- int ThreeCutoff=TwoCutoff+NrCardType3;
- int FourCutoff=ThreeCutoff+NrCardType4;
- int FiveCutoff=FourCutoff+NrCardType5;
- int SixCutoff=FiveCutoff+NrCardType6;
- if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
- if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
- if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
- if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
- if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
- return CardType;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement