frankkarsten

Collected Company analysis for Modern

Jun 22nd, 2015
603
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package collected.company;
  2.  
  3. import java.util.Random;
  4.  
  5. public class CollectedCompany {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         Deck deck=new Deck();
  10.         int NrSims=10000000;
  11.         //CardType1=1-cost creature
  12.         //CardType2=2-cost creature
  13.         //CardType3=3-cost creature
  14.         //CardType4=Collected Company
  15.         //CardType5=Other spell
  16.         //CardType6=Land
  17.             double TotalCreatures=0;
  18.             double TotalMana=0;
  19.             double TotalCCs=0;
  20.             double TotalZeroCreatures=0;
  21.             double TotalOneCreature=0;
  22.             double TotalTwoCreatures=0;
  23.             for (int i=1; i<=NrSims; i++){
  24.                 deck.SetDeck(9,10,8,4,29,0);
  25.                 CollectedCompanyOutcome CCO=Simulate(deck);
  26.                 //Here, I condition on drawing at least one CC in the top 10 cards before casting it. I don't check available mana.
  27.                 if (CCO.CCDrawnInTop10){
  28.                     TotalCreatures=TotalCreatures+CCO.TotalNumberOfCreatures;
  29.                     TotalMana=TotalMana+1*CCO.Number1Cost+2*CCO.Number2Cost+3*CCO.Number3Cost;
  30.                     TotalCCs++;
  31.                     if (CCO.TotalNumberOfCreatures==0) {TotalZeroCreatures++;}
  32.                     if (CCO.TotalNumberOfCreatures==1) {TotalOneCreature++;}
  33.                     if (CCO.TotalNumberOfCreatures==2) {TotalTwoCreatures++;}
  34.                 }
  35.             }
  36.        
  37.         System.out.println("E[Mana]="+TotalMana/TotalCCs);
  38.         System.out.println("E[Creatures]="+TotalCreatures/TotalCCs);
  39.         System.out.println("P[0 creatures]="+TotalZeroCreatures/TotalCCs);
  40.         System.out.println("P[1 creature]="+TotalOneCreature/TotalCCs);
  41.         System.out.println("P[2 creatures]="+TotalTwoCreatures/TotalCCs);
  42.        
  43.        
  44.  
  45.     }//end of main
  46.  
  47.  
  48.  
  49.  
  50.    
  51.     static CollectedCompanyOutcome Simulate(Deck remainingdeck) {
  52.         CollectedCompanyOutcome CCO=new CollectedCompanyOutcome();
  53.         int TypeOfCardDrawn;
  54.         CCO.Number1Cost=0;
  55.         CCO.Number2Cost=0;
  56.         CCO.Number3Cost=0;
  57.         CCO.TotalNumberOfCreatures=0;
  58.        
  59.         CCO.CCDrawnInTop10=false;
  60.         for (int i=1; i<=10; i++){
  61.             TypeOfCardDrawn=remainingdeck.DrawCard();
  62.             if (TypeOfCardDrawn==4) {CCO.CCDrawnInTop10=true;}
  63.         }
  64.         if (CCO.CCDrawnInTop10){
  65.             for (int i=1; i<=6; i++){
  66.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  67.                 if (TypeOfCardDrawn==2 && CCO.TotalNumberOfCreatures==2 && CCO.Number1Cost>=1) {CCO.Number2Cost++; CCO.Number1Cost--;}
  68.                 boolean CardReplaced=false;
  69.                 if (TypeOfCardDrawn==3 && CCO.TotalNumberOfCreatures==2 && CCO.Number1Cost>=1) {CCO.Number3Cost++; CCO.Number1Cost--; CardReplaced=true;}
  70.                 if (TypeOfCardDrawn==3 && CCO.TotalNumberOfCreatures==2 && CCO.Number2Cost>=1 && CardReplaced==false) {CCO.Number3Cost++; CCO.Number2Cost--;}
  71.                 if (TypeOfCardDrawn==1 && CCO.TotalNumberOfCreatures<2) {CCO.Number1Cost++; CCO.TotalNumberOfCreatures++;}
  72.                 if (TypeOfCardDrawn==2 && CCO.TotalNumberOfCreatures<2) {CCO.Number2Cost++; CCO.TotalNumberOfCreatures++;}
  73.                 if (TypeOfCardDrawn==3 && CCO.TotalNumberOfCreatures<2) {CCO.Number3Cost++; CCO.TotalNumberOfCreatures++;}
  74.             }
  75.         }
  76.         return CCO;
  77.     }
  78.        
  79.      
  80.  
  81. static class CollectedCompanyOutcome {
  82.     int Number1Cost;
  83.     int Number2Cost;
  84.     int Number3Cost;
  85.     int TotalNumberOfCreatures;
  86.     boolean CCDrawnInTop10;
  87.     void PrintOutcome() {
  88.         System.out.println("NumberOf1Cost:"+Number1Cost+", NumberOf2Cost:"+Number2Cost+", NumberOf3Cost:"+Number3Cost+", Total:"+TotalNumberOfCreatures);
  89.     }
  90. }
  91.  
  92. static class Deck {
  93.     int NrCardType1;
  94.     int NrCardType2;
  95.     int NrCardType3;
  96.     int NrCardType4;
  97.     int NrCardType5;
  98.     int NrCardType6;
  99.  
  100.     void PrintDeckBrief () {
  101.         if(NrCardType1<10) {System.out.print("0");}
  102.         System.out.print(NrCardType1+" ");
  103.         if(NrCardType2<10) {System.out.print("0");}
  104.         System.out.print(NrCardType2+" ");
  105.         if(NrCardType3<10) {System.out.print("0");}
  106.         System.out.print(NrCardType3+" ");
  107.         if(NrCardType4<10) {System.out.print("0");}
  108.         System.out.print(NrCardType4+" ");
  109.         if(NrCardType5<10) {System.out.print("0");}
  110.         System.out.print(NrCardType5+" ");
  111.         if(NrCardType6<10) {System.out.print("0");}
  112.         System.out.print(NrCardType6);
  113.         System.out.print(" ");
  114.     }
  115.  
  116.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
  117.         NrCardType1=Nr1;
  118.         NrCardType2=Nr2;
  119.         NrCardType3=Nr3;
  120.         NrCardType4=Nr4;
  121.         NrCardType5=Nr5;
  122.         NrCardType6=Nr6;
  123.     }
  124.    
  125.     int NrOfCards(){
  126.         return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
  127.     }
  128.    
  129.     int DrawCard (){
  130.             Random generator = new Random();
  131.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  132.             int CardType=0;
  133.             int OneCutoff=NrCardType1;
  134.             int TwoCutoff=OneCutoff+NrCardType2;
  135.             int ThreeCutoff=TwoCutoff+NrCardType3;
  136.             int FourCutoff=ThreeCutoff+NrCardType4;
  137.             int FiveCutoff=FourCutoff+NrCardType5;
  138.             int SixCutoff=FiveCutoff+NrCardType6;
  139.            
  140.             if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
  141.             if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
  142.             if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
  143.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
  144.             if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
  145.             if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
  146.             return CardType;
  147.     }
  148.    
  149. }
  150. }
RAW Paste Data