Advertisement
frankkarsten

Building a better mana base

Dec 30th, 2013
10,771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.60 KB | None | 0 0
  1. package manabase;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class ManaBase {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         Deck deck=new Deck();
  11.         int NrIterations=1000000;
  12.         int NrGoodLandsNeeded=2;
  13.         int TurnAllowed=2;
  14.         int NrCards=99;
  15.         int NrLands=40;
  16.         int CardType;
  17.         int LandsInHand;
  18.         int GoodLandsInHand;
  19.         boolean Mulligan;
  20.        
  21.         for (int NrGoodLands=6; NrGoodLands<=24; NrGoodLands++){
  22.            
  23.             double CountOK=0.0;
  24.             double CountConditional=0.0;
  25.            
  26.             for (int i=1; i<=NrIterations; i++){
  27.                
  28.                 //Draw opening 7
  29.                 deck.SetDeck(NrLands, NrGoodLands, NrCards);
  30.                 LandsInHand=0;
  31.                 GoodLandsInHand=0;
  32.                 for (int j=1; j<=7; j++){
  33.                     CardType=deck.DrawCard();
  34.                     if (CardType<3) {LandsInHand++;}
  35.                     if (CardType==1) {GoodLandsInHand++;}  
  36.                 }
  37.                 Mulligan=false;
  38.                 if (LandsInHand<2) {Mulligan=true;}
  39.                 if (LandsInHand>5) {Mulligan=true;}
  40.                
  41.                 //Mulligan to 6
  42.                 if (Mulligan){
  43.                     deck.SetDeck(NrLands, NrGoodLands, NrCards);
  44.                     LandsInHand=0;
  45.                     GoodLandsInHand=0;
  46.                     for (int j=1; j<=6; j++){
  47.                         CardType=deck.DrawCard();
  48.                         if (CardType<3) {LandsInHand++;}
  49.                         if (CardType==1) {GoodLandsInHand++;}  
  50.                     }
  51.                     Mulligan=false;
  52.                     if (LandsInHand<2) {Mulligan=true;}
  53.                     if (LandsInHand>4) {Mulligan=true;}
  54.                 }
  55.                
  56.                 //Mulligan to 5
  57.                 if (Mulligan){
  58.                     deck.SetDeck(NrLands, NrGoodLands, NrCards);
  59.                     LandsInHand=0;
  60.                     GoodLandsInHand=0;
  61.                     for (int j=1; j<=5; j++){
  62.                         CardType=deck.DrawCard();
  63.                         if (CardType<3) {LandsInHand++;}
  64.                         if (CardType==1) {GoodLandsInHand++;}  
  65.                     }
  66.                     Mulligan=false;
  67.                     if (LandsInHand<1) {Mulligan=true;}
  68.                     if (LandsInHand>4) {Mulligan=true;}
  69.                 }
  70.                
  71.                 //Mulligan to 4
  72.                 if (Mulligan){
  73.                     deck.SetDeck(NrLands, NrGoodLands, NrCards);
  74.                     LandsInHand=0;
  75.                     GoodLandsInHand=0;
  76.                     for (int j=1; j<=4; j++){
  77.                         CardType=deck.DrawCard();
  78.                         if (CardType<3) {LandsInHand++;}
  79.                         if (CardType==1) {GoodLandsInHand++;}  
  80.                     }
  81.                 }
  82.                
  83.                 //Draw cards for the number of turns available
  84.                 for (int turn=1; turn<=TurnAllowed-1; turn++){
  85.                     CardType=deck.DrawCard();
  86.                     if (CardType<3) {LandsInHand++;}
  87.                     if (CardType==1) {GoodLandsInHand++;}  
  88.                 }
  89.                
  90.                 if (GoodLandsInHand>=NrGoodLandsNeeded) {CountOK++;}
  91.                 if (LandsInHand>=NrGoodLandsNeeded) {CountConditional++;}
  92.                
  93.             } // end of 1000000 iterations
  94.            
  95.             System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
  96.         }
  97.     }
  98.    
  99. }
  100.  
  101. class Deck {
  102.     int NumberOfLands;
  103.     int NumberOfGoodLands;
  104.     int NumberOfCards;
  105.  
  106.     void SetDeck (int NrLands, int NrGoodLands, int NrCards) {
  107.         NumberOfLands=NrLands;
  108.         NumberOfGoodLands=NrGoodLands;
  109.         NumberOfCards=NrCards;
  110.     }
  111.    
  112.     int DrawCard (){
  113.             Random generator = new Random();
  114.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
  115.             int CardType=0;
  116.             int GoodLandCutoff=NumberOfGoodLands;
  117.             int LandCutoff=NumberOfLands;
  118.            
  119.             if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoff) {CardType=1; this.NumberOfGoodLands--; this.NumberOfLands--; this.NumberOfCards--;}
  120.             if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=2; this.NumberOfLands--; this.NumberOfCards--;}
  121.             if (RandomIntegerBetweenOneAndDeckSize>LandCutoff) {CardType=3; this.NumberOfCards--;}
  122.             return CardType;
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement