SHARE
TWEET

Probability of transforming Delver with new mull rule

frankkarsten Jul 6th, 2015 842 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package delvernewmullrule;
  2.  
  3. import java.util.Random;
  4.  
  5. public class DelverNewMullRule {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         int NrSims=10000000;
  10.         //CardType1=Delver
  11.         //CardType2=Spell
  12.         //CardType3=Fetchland
  13.         //CardType4=OtherLand
  14.         //CardType5=OtherCard
  15.         int NrGamesWithDelver=0;
  16.         int NrGamesWithImmediateFlippedDelver=0;
  17.         //System.out.println(NrGamesWithImmediateFlippedDelver);
  18.         //System.out.println(NrGamesWithDelver);
  19.         boolean NewMullRuleActive=false;
  20.         int Mull=0;
  21.         for (int i=1; i<=NrSims; i++){
  22.             //System.out.println();
  23.             //System.out.println("-----NrSim "+NrSims+" -----");
  24.             int Outcome=Simulate(NewMullRuleActive);
  25.             if (Outcome==1) {NrGamesWithDelver++;}
  26.             if (Outcome==2) {NrGamesWithDelver++; NrGamesWithImmediateFlippedDelver++;}
  27.         }
  28.        
  29.         System.out.println("P[Flip Delver Immediately]= "+(NrGamesWithImmediateFlippedDelver+0.0)/NrGamesWithDelver);
  30.         }
  31.  
  32.     static int Simulate(boolean NewMullRule) {
  33.         int TypeOfCardDrawn;
  34.         Deck deck=new Deck();
  35.         int Outcome=0;
  36.         int OpeningHandSize=8;
  37.         boolean KeepHand=false;
  38.         int TypeOfCardScried=0;
  39.         int NrFetchLands=0;
  40.         int NrOtherLands=0;
  41.         int NrDelvers=0;
  42.         Random generator = new Random();
  43.         do {        
  44.             OpeningHandSize--;
  45.             //So for the first iteration, OpeningHandSize will be 7
  46.             for (int i=OpeningHandSize; i>=1; i--){
  47.                 deck.SetDeck(4, 29, 8, 9, 10, 0);
  48.                 NrFetchLands=0;
  49.                 NrOtherLands=0;
  50.                 NrDelvers=0;
  51.                 for (int j=1; j<=OpeningHandSize; j++){
  52.                     TypeOfCardDrawn=deck.DrawCard();
  53.                     if (TypeOfCardDrawn==1) {NrDelvers++;}
  54.                     if (TypeOfCardDrawn==3) {NrFetchLands++;}
  55.                     if (TypeOfCardDrawn==4) {NrOtherLands++;}
  56.                 }
  57.             }
  58.             //System.out.println("OpeningHandSize "+OpeningHandSize);
  59.             //We mull a hand if it has no lands. If the hand has >=1 lands, we mull it in 15% of the games to indicate weak opening hands.
  60.             double RandomMull=generator.nextDouble();
  61.             if (NrFetchLands+NrOtherLands>=1) {KeepHand=true;}
  62.             if (RandomMull<=0.15) {KeepHand=false;}
  63.             if (OpeningHandSize==1) {KeepHand=true;}
  64.         } while (KeepHand==false);
  65.         boolean CardOnTopFixedSpell=false;
  66.         if (NewMullRule && OpeningHandSize<=6) {
  67.             //We now scry the top card by actually drawing it and and setting it aside.
  68.             TypeOfCardScried=deck.DrawCard();
  69.             if (TypeOfCardScried==2) {CardOnTopFixedSpell=true;}
  70.             //Why use arrays when you can use copy-paste, right? #Kappa
  71.         }
  72.         if (NrOtherLands+NrFetchLands>0 && NrDelvers>0) {
  73.             if (NrOtherLands==0) {
  74.                 //We have to shuffle to fetch
  75.                 //System.out.println("We're in business!");
  76.                 deck.NrCardType4--;
  77.                 //If applicable, we put the card scried back into the deck
  78.                 if (TypeOfCardScried>0) {
  79.                     if (TypeOfCardScried==1) {deck.NrCardType1++;}
  80.                     if (TypeOfCardScried==2) {deck.NrCardType2++;}
  81.                     if (TypeOfCardScried==3) {deck.NrCardType3++;}
  82.                     if (TypeOfCardScried==4) {deck.NrCardType4++;}
  83.                     if (TypeOfCardScried==5) {deck.NrCardType5++;}
  84.                     if (TypeOfCardScried==6) {deck.NrCardType6++;}
  85.                 }
  86.                 CardOnTopFixedSpell=false;
  87.             }
  88.             if (CardOnTopFixedSpell) {Outcome=2;}
  89.             if (!CardOnTopFixedSpell) {
  90.                 TypeOfCardDrawn=deck.DrawCard();
  91.                 if (TypeOfCardDrawn==2) {Outcome=2;}
  92.                 else {Outcome=1;}
  93.             }
  94.         }
  95.         else {Outcome=0;}
  96.         //Outcome 0=No Delver or land in opening hand
  97.         //Outcome 1=Turn 1 Delver, no flip
  98.         //Outcome 2=Turn 1 Delver, flip
  99.         return Outcome;
  100.     }
  101.        
  102.     static class Deck {
  103.     int NrCardType1;
  104.     int NrCardType2;
  105.     int NrCardType3;
  106.     int NrCardType4;
  107.     int NrCardType5;
  108.     int NrCardType6;
  109.  
  110.     void PrintDeckBrief () {
  111.         if(NrCardType1<10) {System.out.print("0");}
  112.         System.out.print(NrCardType1+" ");
  113.         if(NrCardType2<10) {System.out.print("0");}
  114.         System.out.print(NrCardType2+" ");
  115.         if(NrCardType3<10) {System.out.print("0");}
  116.         System.out.print(NrCardType3+" ");
  117.         if(NrCardType4<10) {System.out.print("0");}
  118.         System.out.print(NrCardType4+" ");
  119.         if(NrCardType5<10) {System.out.print("0");}
  120.         System.out.print(NrCardType5+" ");
  121.         if(NrCardType6<10) {System.out.print("0");}
  122.         System.out.print(NrCardType6);
  123.         System.out.print(" ");
  124.     }
  125.  
  126.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6) {
  127.         NrCardType1=Nr1;
  128.         NrCardType2=Nr2;
  129.         NrCardType3=Nr3;
  130.         NrCardType4=Nr4;
  131.         NrCardType5=Nr5;
  132.         NrCardType6=Nr6;
  133.     }
  134.    
  135.     int NrOfCards(){
  136.         return NrCardType1+NrCardType2+NrCardType3+NrCardType4+NrCardType5+NrCardType6;
  137.     }
  138.    
  139.     int DrawCard (){
  140.             Random generator = new Random();
  141.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  142.             int CardType=0;
  143.             int OneCutoff=NrCardType1;
  144.             int TwoCutoff=OneCutoff+NrCardType2;
  145.             int ThreeCutoff=TwoCutoff+NrCardType3;
  146.             int FourCutoff=ThreeCutoff+NrCardType4;
  147.             int FiveCutoff=FourCutoff+NrCardType5;
  148.             int SixCutoff=FiveCutoff+NrCardType6;
  149.            
  150.             if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NrCardType1--;}
  151.             if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NrCardType2--;}
  152.             if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NrCardType3--;}
  153.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NrCardType4--;}
  154.             if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NrCardType5--;}
  155.             if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff) {CardType=6; this.NrCardType6--;}
  156.             return CardType;
  157.     }
  158.    
  159. }
  160. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top