SHARE
TWEET

How often do you have green for Atarka's Command?

frankkarsten Apr 12th, 2015 840 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package cardsimulator;
  2.  
  3. import java.util.Random;
  4.  
  5. public class CardSimulator {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         int NrSims=10000000;
  10.         //CardType1=Mountain
  11.         //CardType2=Mana Confluence
  12.         //CardType3=Atarka's Command
  13.         //CardType4=other
  14.         int NrGamesWithCommand=0;
  15.         int NrGamesWithCommandAndMana=0;
  16.             for (int i=1; i<=NrSims; i++){
  17.             int Outcome=Simulate();
  18.                 if (Outcome>=1) {NrGamesWithCommand++;}
  19.                 if (Outcome==2) {NrGamesWithCommandAndMana++;}
  20.             }
  21.        
  22.         System.out.println((NrGamesWithCommandAndMana+0.0)/NrGamesWithCommand);
  23.        
  24.         }
  25.  
  26.     static int Simulate() {
  27.         int TypeOfCardDrawn;
  28.         Deck deck=new Deck();
  29.         int Outcome=0;
  30.         Random generator = new Random();
  31.         int ExtraCardBecauseWeAreOnTheDraw=0;
  32.         if (generator.nextDouble()<=0.5) {ExtraCardBecauseWeAreOnTheDraw++;}
  33.         //We keep a seven-card hand if and only if it has 2 or 3 lands
  34.         deck.SetDeck(10, 10, 4, 36, 0, 0);
  35.         int NrLands=0;
  36.         int NrGreenSources=0;
  37.         int NrCommand=0;
  38.         for (int i=1; i<=7; i++){
  39.             TypeOfCardDrawn=deck.DrawCard();
  40.             if (TypeOfCardDrawn==1) {NrLands++;}
  41.             if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
  42.             if (TypeOfCardDrawn==3) {NrCommand++;}
  43.         }
  44.         if (NrLands==2 || NrLands==3) {
  45.             for (int i=1; i<=3+ExtraCardBecauseWeAreOnTheDraw; i++){
  46.                 TypeOfCardDrawn=deck.DrawCard();
  47.                 if (TypeOfCardDrawn==1) {NrLands++;}
  48.                 if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
  49.                 if (TypeOfCardDrawn==3) {NrCommand++;}
  50.             }
  51.             if (NrCommand==0) {Outcome=0;}
  52.             if (NrCommand>=1 && NrGreenSources==0) {Outcome=1;}
  53.             if (NrCommand>=1 && NrGreenSources>0) {Outcome=2;}
  54.         }
  55.         else {
  56.             //We keep a six-card hand if and only if it has 1, 2, or 3 lands
  57.             deck.SetDeck(10, 10, 4, 36, 0, 0);
  58.             NrLands=0;
  59.             NrGreenSources=0;
  60.             NrCommand=0;
  61.             for (int i=1; i<=6; i++){
  62.                 TypeOfCardDrawn=deck.DrawCard();
  63.                 if (TypeOfCardDrawn==1) {NrLands++;}
  64.                 if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
  65.                 if (TypeOfCardDrawn==3) {NrCommand++;}
  66.             }
  67.             if (NrLands>=1 || NrLands<=3) {
  68.                 for (int i=1; i<=3+ExtraCardBecauseWeAreOnTheDraw; i++){
  69.                     TypeOfCardDrawn=deck.DrawCard();
  70.                     if (TypeOfCardDrawn==1) {NrLands++;}
  71.                     if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
  72.                     if (TypeOfCardDrawn==3) {NrCommand++;}
  73.                 }
  74.                 if (NrCommand==0) {Outcome=0;}
  75.                 if (NrCommand>=1 && NrGreenSources==0) {Outcome=1;}
  76.                 if (NrCommand>=1 && NrGreenSources>0) {Outcome=2;}
  77.             }
  78.             else {
  79.                 //We always keep every five-card hand
  80.                 deck.SetDeck(10, 10, 4, 36, 0, 0);
  81.                 NrLands=0;
  82.                 NrGreenSources=0;
  83.                 NrCommand=0;
  84.                 for (int i=1; i<=5+3+ExtraCardBecauseWeAreOnTheDraw; i++){
  85.                     TypeOfCardDrawn=deck.DrawCard();
  86.                     if (TypeOfCardDrawn==1) {NrLands++;}
  87.                     if (TypeOfCardDrawn==2) {NrLands++; NrGreenSources++;}
  88.                     if (TypeOfCardDrawn==3) {NrCommand++;}
  89.                 }
  90.                 if (NrCommand==0) {Outcome=0;}
  91.                 if (NrCommand>=1 && NrGreenSources==0) {Outcome=1;}
  92.                 if (NrCommand>=1 && NrGreenSources>0) {Outcome=2;}
  93.             }
  94.         }
  95.         return Outcome;
  96.     }
  97.        
  98.      
  99.  
  100.  
  101. static class Deck {
  102.     int NrCardType1;
  103.     int NrCardType2;
  104.     int NrCardType3;
  105.     int NrCardType4;
  106.     int NrCardType5;
  107.     int NrCardType6;
  108.  
  109.     void PrintDeckBrief () {
  110.         if(NrCardType1<10) {System.out.print("0");}
  111.         System.out.print(NrCardType1+" ");
  112.         if(NrCardType2<10) {System.out.print("0");}
  113.         System.out.print(NrCardType2+" ");
  114.         if(NrCardType3<10) {System.out.print("0");}
  115.         System.out.print(NrCardType3+" ");
  116.         if(NrCardType4<10) {System.out.print("0");}
  117.         System.out.print(NrCardType4+" ");
  118.         if(NrCardType5<10) {System.out.print("0");}
  119.         System.out.print(NrCardType5+" ");
  120.         if(NrCardType6<10) {System.out.print("0");}
  121.         System.out.print(NrCardType6);
  122.         System.out.print(" ");
  123.     }
  124.  
  125.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
  126.         NrCardType1=Nr1;
  127.         NrCardType2=Nr2;
  128.         NrCardType3=Nr3;
  129.         NrCardType4=Nr4;
  130.         NrCardType5=Nr5;
  131.         NrCardType6=Nr6;
  132.     }
  133.    
  134.     int NrOfCards(){
  135.         return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
  136.     }
  137.    
  138.     int DrawCard (){
  139.             Random generator = new Random();
  140.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  141.             int CardType=0;
  142.             int OneCutoff=NrCardType1;
  143.             int TwoCutoff=OneCutoff+NrCardType2;
  144.             int ThreeCutoff=TwoCutoff+NrCardType3;
  145.             int FourCutoff=ThreeCutoff+NrCardType4;
  146.             int FiveCutoff=FourCutoff+NrCardType5;
  147.             int SixCutoff=FiveCutoff+NrCardType6;
  148.            
  149.             if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
  150.             if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
  151.             if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
  152.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
  153.             if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
  154.             if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
  155.             return CardType;
  156.     }
  157.    
  158. }
  159. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top