Advertisement
frankkarsten

How many boosters to open for one of each card in M19?

Jul 16th, 2018
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.63 KB | None | 0 0
  1. package fullset;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class FullSet {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         //Intialization
  11.         boolean FullSet;
  12.         Random generator = new Random();
  13.         boolean WeHaveANewCard;
  14.         int RandomIntegerBetweenOneAndNrPossibleCards=0;
  15.         double EVcontrib=0;
  16.         int[] NumberFasterThan=new int[3001];
  17.        
  18.         for (int Iteration=1; Iteration<=1000000; Iteration++){
  19.             int Booster=0;
  20.             int[] Common=new int[111+1];
  21.             int[] Uncommon=new int[80+1];
  22.             int[] Rare=new int[53+1];
  23.             int[] Mythic=new int[16+1];
  24.             int[] DualLand=new int[10+1];
  25.             do{
  26.                 //Let's open a booster!
  27.                 Booster++;
  28.                
  29.                 //We need to make sure that there are 10 DIFFERENT commons
  30.                 int[] CurrentCardsInBooster=new int[11]; for (int SetToZero=1; SetToZero<=10; SetToZero++) {CurrentCardsInBooster[SetToZero]=0;}
  31.                 for (int Commons=1; Commons<=10; Commons++){
  32.                     do {    
  33.                         WeHaveANewCard=true;
  34.                         RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 111 )+1;
  35.                         for (int Check=1; Check<=Commons; Check++){
  36.                             if (RandomIntegerBetweenOneAndNrPossibleCards==CurrentCardsInBooster[Check]) {WeHaveANewCard=false;}
  37.                         }
  38.                     } while (!WeHaveANewCard);
  39.                     CurrentCardsInBooster[Commons]=RandomIntegerBetweenOneAndNrPossibleCards;
  40.                     Common[RandomIntegerBetweenOneAndNrPossibleCards]++;
  41.                 }
  42.                
  43.                 //We need to make sure that there are 3 DIFFERENT uncommons
  44.                 CurrentCardsInBooster=new int[4]; for (int SetToZero=1; SetToZero<=3; SetToZero++) {CurrentCardsInBooster[SetToZero]=0;}
  45.                 for (int UnCommons=1; UnCommons<=3; UnCommons++){
  46.                     do {
  47.                         WeHaveANewCard=true;
  48.                         RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 80 )+1;
  49.                         for (int Check=1; Check<=UnCommons; Check++){
  50.                             if (RandomIntegerBetweenOneAndNrPossibleCards==CurrentCardsInBooster[Check]) {WeHaveANewCard=false;}
  51.                         }
  52.                     } while (!WeHaveANewCard);
  53.                     CurrentCardsInBooster[UnCommons]=RandomIntegerBetweenOneAndNrPossibleCards;
  54.                     Uncommon[RandomIntegerBetweenOneAndNrPossibleCards]++;
  55.                 }
  56.  
  57.                 //We assume that each booster has a mythic rare with probability 1/8
  58.                 if (generator.nextDouble()<=0.125) {
  59.                     RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 16 )+1;
  60.                     Mythic[RandomIntegerBetweenOneAndNrPossibleCards]++;
  61.                 }
  62.                 else {
  63.                     RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 53 )+1;
  64.                     Rare[RandomIntegerBetweenOneAndNrPossibleCards]++;
  65.                 }
  66.                
  67.                 if (generator.nextDouble()<=(5.0/12.0)) {
  68.                     RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 10 )+1;
  69.                     DualLand[RandomIntegerBetweenOneAndNrPossibleCards]++;
  70.                 }
  71.                
  72.                 //Check if full set is complete
  73.                 FullSet=true;
  74.                 for (int Com=1; Com<=111; Com++) { if (Common[Com]<1) {FullSet=false;} }
  75.                 for (int UNCom=1; UNCom<=80; UNCom++) { if (Uncommon[UNCom]<1) {FullSet=false;} }
  76.                 for (int Rar=1; Rar<=53; Rar++) { if (Rare[Rar]<1) {FullSet=false;} }
  77.                 for (int Myt=1; Myt<=16; Myt++) { if (Mythic[Myt]<1) {FullSet=false;} }
  78.                 for (int Dual=1; Dual<=10; Dual++) { if (DualLand[Dual]<1) {FullSet=false;} }
  79.                
  80.             } while (FullSet==false);
  81.             //The number of boosters we needed to open in this iteration is stored by Booster
  82.             //For any reasonable integer X, the number of iterations where we needed X boosters or less to complete the set is stored in NumberFasterThan[X]
  83.             for (int X=1; X<=3000; X++){
  84.                 if (Booster<=X) {NumberFasterThan[X]++;}
  85.             }
  86.             EVcontrib=EVcontrib+Booster;
  87.         }
  88.        
  89.         for (int X=1; X<=3000; X++){
  90.             System.out.println(NumberFasterThan[X]);
  91.         }
  92.         System.out.println("Expected number of boosters needed:"+EVcontrib/1000000.0);
  93.        
  94.     }
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement