frankkarsten

How often does the deck on the play win?

Sep 14th, 2014
897
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package playfirst;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class PlayFirst {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck1=new Deck();
  11.         Deck deck2=new Deck();
  12.         OpeningHand openinghand1;
  13.         OpeningHand openinghand2;
  14.         int NumberOfSimulations=100000000;
  15.         int WinningPlayer;
  16.         int PlayFirstWins=0;
  17.         int DrawFirstWins=0;
  18.        
  19.         for (int SimulationCounter=1; SimulationCounter<=NumberOfSimulations; SimulationCounter++){
  20.             if (SimulationCounter%1000000==0){System.out.println("Just did simulation number "+SimulationCounter);}
  21.             deck1.SetDeck(44,16);
  22.             deck2.SetDeck(44,16);
  23.             openinghand1=GiveOpeningHandAfterMulls(deck1);
  24.             openinghand2=GiveOpeningHandAfterMulls(deck2);
  25.             WinningPlayer=DetermineWinner(deck1, openinghand1, deck2, openinghand2);
  26.             if (WinningPlayer==1){PlayFirstWins++;}
  27.             if (WinningPlayer==2){DrawFirstWins++;}
  28.         }
  29.        
  30.         System.out.println("----------------");
  31.         System.out.print("The number of times that the deck on the play won:"+PlayFirstWins);
  32.         System.out.print("The number of times that the deck on the draw won:"+DrawFirstWins);
  33.        
  34.     }//end of main
  35.  
  36.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck) {
  37.        
  38.         Deck remainingdeck=new Deck();
  39.         OpeningHand openinghand=new OpeningHand();
  40.         int TypeOfCardDrawn;
  41.         boolean KeepHand=false;
  42.        
  43.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  44.             if (KeepHand==false){
  45.                 openinghand.ResetHand();
  46.                 remainingdeck.SetDeck(deck.NumberOfBolts,deck.NumberOfLands);
  47.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  48.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  49.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfBolts++;}
  50.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfLands++;}
  51.                 }
  52.                 if (OpeningHandSize>=4 && openinghand.NumberOfLands>=1 && openinghand.NumberOfLands<=3) {KeepHand=true;}
  53.                 if (OpeningHandSize<=3) {KeepHand=true;}    
  54.            }
  55.         }
  56.     deck.SetDeck(deck.NumberOfBolts-openinghand.NumberOfBolts, deck.NumberOfLands-openinghand.NumberOfLands);
  57.     return openinghand;
  58.     }//end of GiveOpeningHandAfterMulls
  59.    
  60.     static int DetermineWinner(Deck remainingdeck1, OpeningHand openinghand1, Deck remainingdeck2, OpeningHand openinghand2) {
  61.        
  62.         //Deck 1 is going to play first
  63.        
  64.         int BoltDamage=3;
  65.         int Turn=0;
  66.         int Winner=0;
  67.         int CastableBolts;
  68.         int TypeOfCardDrawn=0;
  69.  
  70.         int Player1Life=20;
  71.         int Player2Life=20;
  72.         int Player1LandsInPlay=0;
  73.         int Player2LandsInPlay=0;
  74.         int Player1BoltsInHand=openinghand1.NumberOfBolts;
  75.         int Player1LandsInHand=openinghand1.NumberOfLands;
  76.         int Player2BoltsInHand=openinghand2.NumberOfBolts;
  77.         int Player2LandsInHand=openinghand2.NumberOfLands;
  78.        
  79.         do {
  80.            
  81.             Turn++;
  82.            
  83.             //Player 1's turn
  84.            
  85.        //     System.out.println("====================");
  86.        //     System.out.println("Turn: "+Turn);
  87.        //     System.out.println("====================");
  88.        //     System.out.println("Player 1 has "+Player1BoltsInHand+" Bolts and "+Player1LandsInHand+" lands in hand, at "+Player1Life+" life and "+Player1LandsInPlay+" lands in play. His deck has "+remainingdeck1.NumberOfBolts+" Bolts and "+remainingdeck1.NumberOfLands+" lands.");
  89.        //     System.out.println("Player 2 has "+Player2BoltsInHand+" Bolts and "+Player2LandsInHand+" lands in hand, at "+Player2Life+" life and "+Player2LandsInPlay+" lands in play. His deck has "+remainingdeck2.NumberOfBolts+" Bolts and "+remainingdeck2.NumberOfLands+" lands.");
  90.            
  91.             if (Turn>1) {
  92.                 TypeOfCardDrawn=remainingdeck1.DrawCard();
  93.                 if (TypeOfCardDrawn==4) {Player1BoltsInHand++;}
  94.                 if (TypeOfCardDrawn==5) {Player1LandsInHand++;}
  95.             }
  96.                
  97.             if (Player1LandsInHand>=1) {Player1LandsInPlay++; Player1LandsInHand--;}
  98.             CastableBolts=Math.min(Player1BoltsInHand, Player1LandsInPlay);
  99.             Player2Life=Player2Life-CastableBolts*BoltDamage;
  100.             Player1BoltsInHand=Player1BoltsInHand-CastableBolts;        
  101.            
  102.             if (Player2Life<=0 && Winner==0) {Winner=1;}
  103.  
  104.        //     System.out.print("Player 1 draws ");
  105.        //     if (TypeOfCardDrawn==4){System.out.print("a Bolt");}
  106.        //     if (TypeOfCardDrawn==5){System.out.print("a land");}
  107.        //     if (Turn==1){System.out.print("nothing");}
  108.        //     System.out.println(" and casts "+CastableBolts+" Bolts, bringing Player 2 to "+Player2Life+" life.");
  109.            
  110.             //Player 2's turn
  111.  
  112.             TypeOfCardDrawn=remainingdeck2.DrawCard();
  113.             if (TypeOfCardDrawn==4) {Player2BoltsInHand++;}
  114.             if (TypeOfCardDrawn==5) {Player2LandsInHand++;}
  115.                
  116.             if (Player2LandsInHand>=1) {Player2LandsInPlay++; Player2LandsInHand--;}
  117.             CastableBolts=Math.min(Player2BoltsInHand, Player2LandsInPlay);
  118.             Player1Life=Player1Life-CastableBolts*BoltDamage;
  119.             Player2BoltsInHand=Player2BoltsInHand-CastableBolts;        
  120.  
  121.             if (Player1Life<=0 && Winner==0) {Winner=2;}
  122.            
  123.         //    System.out.print("Player 2 draws a ");
  124.         //    if (TypeOfCardDrawn==4){System.out.print("Bolt");}
  125.         //    if (TypeOfCardDrawn==5){System.out.print("land");}
  126.         //    System.out.println(" and casts "+CastableBolts+" Bolts, bringing Player 1 to "+Player1Life+" life.");
  127.            
  128.         } while (Winner==0);
  129.        
  130.         //System.out.println("THE WINNER WAS PLAYER "+Winner+"!!!");
  131.         return Winner;
  132.     }//end of DetermineWinner
  133.    
  134.    
  135. }//end of OptimalAggroGoldfishDeck
  136.  
  137. class OpeningHand {
  138.     int NumberOfBolts;
  139.     int NumberOfLands;
  140.  
  141.     void ResetHand(){
  142.         NumberOfBolts=0;
  143.         NumberOfLands=0;
  144.     }
  145.            
  146.     void SetHand (int NrBolts, int NrLands) {
  147.         NumberOfBolts=NrBolts;
  148.         NumberOfLands=NrLands;
  149.     }
  150.  
  151. }//end of OpeningHand
  152.  
  153. class Deck {
  154.     int NumberOfBolts;
  155.     int NumberOfLands;
  156.  
  157.     void SetDeck (int NrBolts, int NrLands) {
  158.         NumberOfBolts=NrBolts;
  159.         NumberOfLands=NrLands;
  160.     }
  161.    
  162.     int NrOfCards(){
  163.         return NumberOfBolts+NumberOfLands;
  164.     }
  165.    
  166.     int DrawCard (){
  167.             Random generator = new Random();
  168.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  169.             int CardType=0;
  170.             int BoltCutoff=NumberOfBolts;
  171.             int LandCutoff=BoltCutoff+NumberOfLands;
  172.            
  173.             if (RandomIntegerBetweenOneAndDeckSize<=BoltCutoff) {CardType=4; this.NumberOfBolts--;}
  174.             if (RandomIntegerBetweenOneAndDeckSize>BoltCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=5; this.NumberOfLands--;}
  175.             return CardType;
  176.     }
  177.    
  178. }//end of Deck
RAW Paste Data