frankkarsten

MOR Sylvan Messenger

Jul 12th, 2015
459
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package mor_sylvanmessenger;
  2.  
  3. import java.util.Random;
  4.  
  5. public class MOR_SylvanMessenger {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         int NrSims=10000000;
  10.         //CardType1=Empath
  11.         //CardType2=Other Elf
  12.         //CardType3=Non-Elf, Non-Land
  13.         //CardType4=Land
  14.         //CardType5=N/A
  15.         //CardType6=N/A
  16.         for (int NrOtherElves=20; NrOtherElves<=34; NrOtherElves++){
  17.             int[] NrFlipsWithXElves= new int[5];
  18.             Deck deck=new Deck();
  19.             deck.SetDeck(4, NrOtherElves, 34-NrOtherElves, 22, 0, 0);
  20.             for (int i=1; i<=NrSims; i++){
  21.                 int Outcome=Simulate(deck);
  22.                 for (int NrElves=0; NrElves<=4; NrElves++){
  23.                     if (Outcome==NrElves) {NrFlipsWithXElves[NrElves]++;}
  24.                 }
  25.             }
  26.             double EV=0;
  27.             System.out.println("-----The results for a deck with "+NrOtherElves+" other Elves-----");
  28.             for (int NrElves=0; NrElves<=4; NrElves++){
  29.                 System.out.println("P["+NrElves+" Elves]= "+NrFlipsWithXElves[NrElves]/(NrSims+0.0));
  30.                 EV=EV+NrElves*NrFlipsWithXElves[NrElves]/(NrSims+0.0);
  31.             }
  32.             System.out.println("EV="+EV);
  33.             System.out.println();
  34.         }
  35.     }
  36.    
  37.     static int Simulate(Deck deck) {
  38.         int TypeOfCardDrawn=0;
  39.         Random generator = new Random();
  40.         int NrLands=0;
  41.         int NrEmpaths=0;
  42.         Deck remainingdeck=new Deck();
  43.         remainingdeck.SetDeck(deck.NrCardType1, deck.NrCardType2, deck.NrCardType3, deck.NrCardType4, 0, 0);
  44.         for (int i=1; i<=10; i++){
  45.             TypeOfCardDrawn=remainingdeck.DrawCard(generator);
  46.             if (TypeOfCardDrawn==1) {NrEmpaths++;}
  47.             if (TypeOfCardDrawn==4) {NrLands++;}
  48.         }
  49.         int NrCardsDrawn=10;
  50.         boolean WeCanCastEmpath=false;
  51.         if (NrEmpaths>=1 && NrLands>=4) {WeCanCastEmpath=true;}
  52.         if (!WeCanCastEmpath){
  53.             do {    
  54.                 TypeOfCardDrawn=remainingdeck.DrawCard(generator);
  55.                 NrCardsDrawn++;
  56.                 if (TypeOfCardDrawn==1) {NrEmpaths++;}
  57.                 if (TypeOfCardDrawn==4) {NrLands++;}
  58.                 if (NrEmpaths>=1 && NrLands>=4) {WeCanCastEmpath=true;}
  59.             } while (!WeCanCastEmpath);
  60.         }
  61.         //We'll now cast Empath
  62.         int NrElvesHit=0;
  63.         for (int i=1; i<=Math.min(4, 60-NrCardsDrawn); i++) {
  64.             TypeOfCardDrawn=remainingdeck.DrawCard(generator);
  65.             if (TypeOfCardDrawn==1) {NrElvesHit++;}
  66.             if (TypeOfCardDrawn==2) {NrElvesHit++;}
  67.         }
  68.         return NrElvesHit;
  69.     }
  70.        
  71.     static class Deck {
  72.     int NrCardType1;
  73.     int NrCardType2;
  74.     int NrCardType3;
  75.     int NrCardType4;
  76.     int NrCardType5;
  77.     int NrCardType6;
  78.  
  79.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
  80.         NrCardType1=Nr1;
  81.         NrCardType2=Nr2;
  82.         NrCardType3=Nr3;
  83.         NrCardType4=Nr4;
  84.         NrCardType5=Nr5;
  85.         NrCardType6=Nr6;
  86.     }
  87.    
  88.     int NrOfCards(){
  89.         return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
  90.     }
  91.    
  92.     int DrawCard (Random generator){
  93.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  94.             int CardType=0;
  95.             int OneCutoff=NrCardType1;
  96.             int TwoCutoff=OneCutoff+NrCardType2;
  97.             int ThreeCutoff=TwoCutoff+NrCardType3;
  98.             int FourCutoff=ThreeCutoff+NrCardType4;
  99.             int FiveCutoff=FourCutoff+NrCardType5;
  100.             int SixCutoff=FiveCutoff+NrCardType6;
  101.            
  102.             if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
  103.             if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
  104.             if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
  105.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
  106.             if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
  107.             if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
  108.             return CardType;
  109.     }
  110.    
  111. }
  112. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×