frankkarsten

Finding the best Ripple deck

Jul 31st, 2018
658
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package surgingflame;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class SurgingFlame {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.            
  12.         //CardType 1 is a SSG
  13.         //CardType 2 is a SurgFlame
  14.         //CardType 3-5 are not used
  15.        
  16.         for (int NrSSG=25; NrSSG<=35; NrSSG++){
  17.             deck.SetDeck(NrSSG,60-NrSSG,0,0,0);
  18.             double Probability=ProbabilityForRandomHand(deck,7,10000000);
  19.             System.out.print("Probability of t0 win in deck with "+NrSSG+" SSG: ");
  20.             System.out.println(Math.round(Probability*10000)/100.0);
  21.         }
  22.                
  23.     }//end of main
  24.  
  25.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
  26.         Deck remainingdeck=new Deck();
  27.         double NumberOfGamesWithfavorableOutcome=0;
  28.         double NumberOfGames=0;
  29.         //On the play
  30.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  31.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  32.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  33.            
  34.             int Outcome=SimulateGame(remainingdeck,openinghand,true);
  35.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++; NumberOfGames++;}
  36.             if (Outcome==1) {NumberOfGames++;}
  37.         }
  38.         return NumberOfGamesWithfavorableOutcome/(NumberOfGames+0.0);
  39.     }//end of AverageKillTurnForRandomHand
  40.    
  41.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  42.        
  43.         Deck remainingdeck=new Deck();
  44.         OpeningHand openinghand=new OpeningHand();
  45.         int TypeOfCardDrawn;
  46.         boolean KeepHand=false;
  47.        
  48.         openinghand.SetHand(0,0,0,0,0);
  49.         remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
  50.         int NumberOfLands=0;
  51.         for (int CardsDrawn=0; CardsDrawn<7; CardsDrawn++){
  52.             TypeOfCardDrawn=remainingdeck.DrawCard();
  53.             if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
  54.             if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
  55.             if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
  56.             if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
  57.             if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
  58.         }
  59.         //We don't actually mulligan
  60.        
  61.         return openinghand;
  62.     }//end of GiveOpeningHandAfterMulls
  63.    
  64.    
  65.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, boolean OnThePlay) {
  66.        
  67.         int Outcome=1;
  68.         int TypeOfCardDrawn=0;
  69.         int SSGInHand=openinghand.NumberOfLands;
  70.         int SurgFlameInHand=openinghand.NumberOfCardType2;
  71.         int CastableFlames=0;
  72.         if (SSGInHand>=2 && SSGInHand<4 && SurgFlameInHand>=1) {CastableFlames=1;}
  73.         if (SSGInHand>=4 && SurgFlameInHand==1) {CastableFlames=1;}
  74.         if (SSGInHand>=4 && SurgFlameInHand>=2) {CastableFlames=2;}
  75.         int TotDMG=0;
  76.  
  77.         if (CastableFlames>0){
  78.             do {
  79.                 CastableFlames--; TotDMG=TotDMG+2;
  80.                 for (int i=1; i<=4; i++){
  81.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  82.                     if (TypeOfCardDrawn==2) {CastableFlames++;}
  83.                 }
  84.             } while (CastableFlames>0 && TotDMG<20);
  85.         }
  86.         if (TotDMG>=20) {Outcome=0;}
  87.                
  88.         return Outcome;
  89.     }//end of SimulateGame
  90.    
  91. }
  92.  
  93. class OpeningHand {
  94.     int NumberOfLands;
  95.     int NumberOfCardType2;
  96.     int NumberOfCardType3;
  97.     int NumberOfCardType4;
  98.     int NumberOfSpells;
  99.  
  100.     int NrOfCards(){
  101.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  102.     }
  103.  
  104.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  105.         NumberOfLands=Nr1;
  106.         NumberOfCardType2=Nr2;
  107.         NumberOfCardType3=Nr3;
  108.         NumberOfCardType4=Nr4;
  109.         NumberOfSpells=Nr5;
  110.     }
  111.  
  112. }//end of OpeningHand
  113.  
  114. class Deck {
  115.     int NumberOfLands;
  116.     int NumberOfCardType2;
  117.     int NumberOfCardType3;
  118.     int NumberOfCardType4;
  119.     int NumberOfSpells;
  120.    
  121.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  122.         NumberOfLands=Nr1;
  123.         NumberOfCardType2=Nr2;
  124.         NumberOfCardType3=Nr3;
  125.         NumberOfCardType4=Nr4;
  126.         NumberOfSpells=Nr5;
  127.     }
  128.    
  129.     int NrOfCards(){
  130.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  131.     }
  132.    
  133.     int DrawCard (){
  134.         Random generator = new Random();
  135.         int CardType=0;
  136.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  137.         int OneCutoff=NumberOfLands;
  138.         int TwoCutoff=OneCutoff+NumberOfCardType2;
  139.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
  140.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
  141.         int FiveCutoff=FourCutoff+NumberOfSpells;
  142.  
  143.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfLands--;}
  144.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
  145.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
  146.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
  147.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
  148.         return CardType;
  149.     }
  150.    
  151. }//end of Deck
RAW Paste Data