fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.07s 380160KB
stdin
	

    package manabase;
     
    import java.util.Arrays.*;
    import java.util.Random;
     
    public class ManaBase {
     
        public static void main(String[] args) {
     
            Deck deck=new Deck();
            int NrIterations=1000000;
            int NrGoodLandsNeeded=2;
            int TurnAllowed=2;
            int NrCards=99;
            int NrLands=40;
            int CardType;
            int LandsInHand;
            int GoodLandsInHand;
            boolean Mulligan;
           
            for (int NrGoodLands=6; NrGoodLands<=24; NrGoodLands++){
               
                double CountOK=0.0;
                double CountConditional=0.0;
               
                for (int i=1; i<=NrIterations; i++){
                   
                    //Draw opening 7
                    deck.SetDeck(NrLands, NrGoodLands, NrCards);
                    LandsInHand=0;
                    GoodLandsInHand=0;
                    for (int j=1; j<=7; j++){
                        CardType=deck.DrawCard();
                        if (CardType<3) {LandsInHand++;}
                        if (CardType==1) {GoodLandsInHand++;}  
                    }
                    Mulligan=false;
                    if (LandsInHand<2) {Mulligan=true;}
                    if (LandsInHand>5) {Mulligan=true;}
                   
                    //Mulligan to 6
                    if (Mulligan){
                        deck.SetDeck(NrLands, NrGoodLands, NrCards);
                        LandsInHand=0;
                        GoodLandsInHand=0;
                        for (int j=1; j<=6; j++){
                            CardType=deck.DrawCard();
                            if (CardType<3) {LandsInHand++;}
                            if (CardType==1) {GoodLandsInHand++;}  
                        }
                        Mulligan=false;
                        if (LandsInHand<2) {Mulligan=true;}
                        if (LandsInHand>4) {Mulligan=true;}
                    }
                   
                    //Mulligan to 5
                    if (Mulligan){
                        deck.SetDeck(NrLands, NrGoodLands, NrCards);
                        LandsInHand=0;
                        GoodLandsInHand=0;
                        for (int j=1; j<=5; j++){
                            CardType=deck.DrawCard();
                            if (CardType<3) {LandsInHand++;}
                            if (CardType==1) {GoodLandsInHand++;}  
                        }
                        Mulligan=false;
                        if (LandsInHand<1) {Mulligan=true;}
                        if (LandsInHand>4) {Mulligan=true;}
                    }
                   
                    //Mulligan to 4
                    if (Mulligan){
                        deck.SetDeck(NrLands, NrGoodLands, NrCards);
                        LandsInHand=0;
                        GoodLandsInHand=0;
                        for (int j=1; j<=4; j++){
                            CardType=deck.DrawCard();
                            if (CardType<3) {LandsInHand++;}
                            if (CardType==1) {GoodLandsInHand++;}  
                        }
                    }
                   
                    //Draw cards for the number of turns available
                    for (int turn=1; turn<=TurnAllowed-1; turn++){
                        CardType=deck.DrawCard();
                        if (CardType<3) {LandsInHand++;}
                        if (CardType==1) {GoodLandsInHand++;}  
                    }
                   
                    if (GoodLandsInHand>=NrGoodLandsNeeded) {CountOK++;}
                    if (LandsInHand>=NrGoodLandsNeeded) {CountConditional++;}
                   
                } // end of 1000000 iterations
               
                System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
            }
        }
       
    }
     
    class Deck {
        int NumberOfLands;
        int NumberOfGoodLands;
        int NumberOfCards;
     
        void SetDeck (int NrLands, int NrGoodLands, int NrCards) {
            NumberOfLands=NrLands;
            NumberOfGoodLands=NrGoodLands;
            NumberOfCards=NrCards;
        }
       
        int DrawCard (){
                Random generator = new Random();
                int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
                int CardType=0;
                int GoodLandCutoff=NumberOfGoodLands;
                int LandCutoff=NumberOfLands;
               
                if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoff) {CardType=1; this.NumberOfGoodLands--; this.NumberOfLands--; this.NumberOfCards--;}
                if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=2; this.NumberOfLands--; this.NumberOfCards--;}
                if (RandomIntegerBetweenOneAndDeckSize>LandCutoff) {CardType=3; this.NumberOfCards--;}
                return CardType;
        }
    }

stdout
Standard output is empty