frankkarsten

Expected mana worth of creatures from Collected Company

Mar 23rd, 2015
1,274
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.         Deck deck=new Deck();
  10.         int NrSims=1000000;
  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.         for (int NrCrits=1; NrCrits<=38; NrCrits++){
  18.             double TotalCreatures=0;
  19.             double TotalMana=0;
  20.             double TotalCCs=0;
  21.             for (int i=1; i<=NrSims; i++){
  22.                 int OneThird=NrCrits/3;
  23.                 if (NrCrits-3*OneThird==0) {deck.SetDeck(OneThird, OneThird , OneThird, 4, 0, 60-4-NrCrits);}
  24.                 if (NrCrits-3*OneThird==1) {deck.SetDeck(OneThird, OneThird , OneThird+1, 4, 0, 60-4-NrCrits);}
  25.                 if (NrCrits-3*OneThird==2) {deck.SetDeck(OneThird, OneThird+1, OneThird+1, 4, 0, 60-4-NrCrits);}
  26.                 if (i==1) {deck.PrintDeckBrief();}
  27.                 CollectedCompanyOutcome CCO=Simulate(deck);
  28.                 //Here, I condition on drawing at least one CC in the top 10 cards before casting it. (I didn't do this for the calculation of the expected number of creatures hit off of CC.)
  29.                 if (CCO.CCDrawnInTop10){
  30.                     TotalCreatures=TotalCreatures+CCO.TotalNumberOfCreatures;
  31.                     TotalMana=TotalMana+1*CCO.Number1Cost+2*CCO.Number2Cost+3*CCO.Number3Cost;
  32.                     TotalCCs++;
  33.                 }
  34.             }
  35.        
  36.         System.out.println("E[Mana]="+TotalMana/TotalCCs);
  37.         }
  38.  
  39.     }//end of main
  40.  
  41.  
  42.  
  43.  
  44.    
  45.     static CollectedCompanyOutcome Simulate(Deck remainingdeck) {
  46.         CollectedCompanyOutcome CCO=new CollectedCompanyOutcome();
  47.         int TypeOfCardDrawn;
  48.         CCO.Number1Cost=0;
  49.         CCO.Number2Cost=0;
  50.         CCO.Number3Cost=0;
  51.         CCO.TotalNumberOfCreatures=0;
  52.        
  53.         CCO.CCDrawnInTop10=false;
  54.         for (int i=1; i<=6; i++){
  55.             TypeOfCardDrawn=remainingdeck.DrawCard();
  56.             if (TypeOfCardDrawn==4) {CCO.CCDrawnInTop10=true;}
  57.         }
  58.         if (CCO.CCDrawnInTop10){
  59.             for (int i=1; i<=6; i++){
  60.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  61.                 if (TypeOfCardDrawn==2 && CCO.TotalNumberOfCreatures==2 && CCO.Number1Cost>=1) {CCO.Number2Cost++; CCO.Number1Cost--;}
  62.                 boolean CardReplaced=false;
  63.                 if (TypeOfCardDrawn==3 && CCO.TotalNumberOfCreatures==2 && CCO.Number1Cost>=1) {CCO.Number3Cost++; CCO.Number1Cost--; CardReplaced=true;}
  64.                 if (TypeOfCardDrawn==3 && CCO.TotalNumberOfCreatures==2 && CCO.Number2Cost>=1 && CardReplaced==false) {CCO.Number3Cost++; CCO.Number2Cost--;}
  65.                 if (TypeOfCardDrawn==1 && CCO.TotalNumberOfCreatures<2) {CCO.Number1Cost++; CCO.TotalNumberOfCreatures++;}
  66.                 if (TypeOfCardDrawn==2 && CCO.TotalNumberOfCreatures<2) {CCO.Number2Cost++; CCO.TotalNumberOfCreatures++;}
  67.                 if (TypeOfCardDrawn==3 && CCO.TotalNumberOfCreatures<2) {CCO.Number3Cost++; CCO.TotalNumberOfCreatures++;}
  68.             }
  69.         }
  70.         return CCO;
  71.     }
  72.        
  73.      
  74.  
  75. static class CollectedCompanyOutcome {
  76.     int Number1Cost;
  77.     int Number2Cost;
  78.     int Number3Cost;
  79.     int TotalNumberOfCreatures;
  80.     boolean CCDrawnInTop10;
  81.     void PrintOutcome() {
  82.         System.out.println("NumberOf1Cost:"+Number1Cost+", NumberOf2Cost:"+Number2Cost+", NumberOf3Cost:"+Number3Cost+", Total:"+TotalNumberOfCreatures);
  83.     }
  84. }
  85.  
  86. static class Deck {
  87.     int NrCardType1;
  88.     int NrCardType2;
  89.     int NrCardType3;
  90.     int NrCardType4;
  91.     int NrCardType5;
  92.     int NrCardType6;
  93.  
  94.     void PrintDeckBrief () {
  95.         if(NrCardType1<10) {System.out.print("0");}
  96.         System.out.print(NrCardType1+" ");
  97.         if(NrCardType2<10) {System.out.print("0");}
  98.         System.out.print(NrCardType2+" ");
  99.         if(NrCardType3<10) {System.out.print("0");}
  100.         System.out.print(NrCardType3+" ");
  101.         if(NrCardType4<10) {System.out.print("0");}
  102.         System.out.print(NrCardType4+" ");
  103.         if(NrCardType5<10) {System.out.print("0");}
  104.         System.out.print(NrCardType5+" ");
  105.         if(NrCardType6<10) {System.out.print("0");}
  106.         System.out.print(NrCardType6);
  107.         System.out.print(" ");
  108.     }
  109.  
  110.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
  111.         NrCardType1=Nr1;
  112.         NrCardType2=Nr2;
  113.         NrCardType3=Nr3;
  114.         NrCardType4=Nr4;
  115.         NrCardType5=Nr5;
  116.         NrCardType6=Nr6;
  117.     }
  118.    
  119.     int NrOfCards(){
  120.         return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
  121.     }
  122.    
  123.     int DrawCard (){
  124.             Random generator = new Random();
  125.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  126.             int CardType=0;
  127.             int OneCutoff=NrCardType1;
  128.             int TwoCutoff=OneCutoff+NrCardType2;
  129.             int ThreeCutoff=TwoCutoff+NrCardType3;
  130.             int FourCutoff=ThreeCutoff+NrCardType4;
  131.             int FiveCutoff=FourCutoff+NrCardType5;
  132.             int SixCutoff=FiveCutoff+NrCardType6;
  133.            
  134.             if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
  135.             if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
  136.             if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
  137.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
  138.             if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
  139.             if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
  140.             return CardType;
  141.     }
  142.    
  143. }
  144. }
RAW Paste Data