frankkarsten

Transgress the Mind

Sep 27th, 2015
260
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package transgressthemind;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class TransgressTheMind {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.  
  12.         //CardType 1 is a land
  13.         //CardType 2 is a two-drop
  14.         //CardType 3 is a three-drop
  15.         //CardType 4 is a four-drop
  16.         //CardType 5 is a five-drop
  17.        
  18.         deck.SetDeck(25,16,9,6,4);
  19.         double Probability;
  20.        
  21.         System.out.println("Below, you'll get percentage probability of hitting an expensive card on turn 1 on the first line, for turn 2 on the second line, etc.");
  22.         for (int Turn=1; Turn<=10; Turn++){
  23.             Probability=ProbabilityForRandomHand(deck,7,10000000,Turn);
  24.             System.out.println(Math.round(Probability*10000)/100.0);
  25.         }        
  26.     }//end of main
  27.  
  28.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations, int ProbabilityType){
  29.         Deck remainingdeck=new Deck();
  30.         double NumberOfGamesWithfavorableOutcome=0;
  31.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  32.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  33.             remainingdeck.SetDeck(deck.NumberOfLands-openinghand.NumberOfLands,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfSpells-openinghand.NumberOfSpells);
  34.             int Outcome=SimulateGame(remainingdeck,openinghand,ProbabilityType);
  35.             if (Outcome==0) {NumberOfGamesWithfavorableOutcome++;}
  36.         }
  37.         return NumberOfGamesWithfavorableOutcome/(NumberOfIterations+0.0);
  38.     }//end of AverageKillTurnForRandomHand
  39.    
  40.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  41.        
  42.         Deck remainingdeck=new Deck();
  43.         OpeningHand openinghand=new OpeningHand();
  44.         int TypeOfCardDrawn;
  45.         boolean KeepHand=false;
  46.        
  47.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  48.             if (KeepHand==false){
  49.                 openinghand.SetHand(0,0,0,0,0);
  50.                 remainingdeck.SetDeck(deck.NumberOfLands,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfSpells);
  51.                 int NumberOfLands=0;
  52.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  53.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  54.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfLands++; NumberOfLands++;}
  55.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
  56.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
  57.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
  58.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfSpells++;}
  59.                 }
  60.                 KeepHand=true;
  61.                 if (OpeningHandSize>1) {
  62.                     // The opponent will mulligan a hand if it contains 0, 1, 5, 6, or 7 lands
  63.                     if (NumberOfLands<=1 || NumberOfLands>=5) {KeepHand=false;}
  64.                 }
  65.             }
  66.         }
  67.        
  68.         return openinghand;
  69.     }//end of GiveOpeningHandAfterMulls
  70.    
  71.    
  72.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand, int ProbabilityType) {
  73.        
  74.         //Initializing
  75.         int TypeOfCardDrawn=0;
  76.         int Outcome=2;
  77.         boolean DiscardACard=false;
  78.  
  79.         //The opponent is on the draw with probability 0.5
  80.         boolean OppOnTheDraw=false;
  81.         Random generator = new Random();
  82.         if (generator.nextDouble()>=0.5) {OppOnTheDraw=true;}
  83.        
  84.         int LandsInPlay=0;
  85.         int LandsInHand=openinghand.NumberOfLands;
  86.         int TwoDropsInHand=openinghand.NumberOfCardType2;
  87.         int ThreeDropsInHand=openinghand.NumberOfCardType3;
  88.         int FourDropsInHand=openinghand.NumberOfCardType4;
  89.         int FiveDropsInHand=openinghand.NumberOfSpells;
  90.        
  91.         for (int Turn=1; Turn<=ProbabilityType; Turn++){
  92.            
  93.             //If the opponent is on the draw then we play our Transgress the Mind now
  94.             if (Turn==ProbabilityType && OppOnTheDraw) {
  95.                 if (ThreeDropsInHand+FourDropsInHand+FiveDropsInHand>=1) {DiscardACard=true;}
  96.             }
  97.            
  98.             if (Turn>1 || (Turn==1 && OppOnTheDraw)) {
  99.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  100.                 if (TypeOfCardDrawn==1) {LandsInHand++;}
  101.                 if (TypeOfCardDrawn==2) {TwoDropsInHand++;}
  102.                 if (TypeOfCardDrawn==3) {ThreeDropsInHand++;}
  103.                 if (TypeOfCardDrawn==4) {FourDropsInHand++;}
  104.                 if (TypeOfCardDrawn==5) {FiveDropsInHand++;}
  105.             }
  106.  
  107.             if (LandsInHand>=1) {LandsInHand--; LandsInPlay++;}
  108.            
  109.             int ManaLeft=LandsInPlay;
  110.            
  111.             int CastableFiveDrops=Math.min(FiveDropsInHand, ManaLeft/5);
  112.             if (CastableFiveDrops>=1) {ManaLeft=ManaLeft-5*CastableFiveDrops; FiveDropsInHand=FiveDropsInHand-CastableFiveDrops;}
  113.            
  114.             int CastableFourDrops=Math.min(FourDropsInHand, ManaLeft/4);
  115.             if (CastableFourDrops>=1) {ManaLeft=ManaLeft-4*CastableFourDrops; FourDropsInHand=FourDropsInHand-CastableFourDrops;}
  116.            
  117.             int CastableThreeDrops=Math.min(ThreeDropsInHand, ManaLeft/3);
  118.             if (CastableThreeDrops>=1) {ManaLeft=ManaLeft-3*CastableThreeDrops; ThreeDropsInHand=ThreeDropsInHand-CastableThreeDrops;}
  119.  
  120.             //We don't care about two-drops
  121.            
  122.             //If the opponent is on the play then we play our Transgress the Mind now
  123.             if (Turn==ProbabilityType && !OppOnTheDraw) {
  124.                 if (ThreeDropsInHand+FourDropsInHand+FiveDropsInHand>=1) {DiscardACard=true;}
  125.             }
  126.            
  127.         }
  128.        
  129.         if (DiscardACard) {Outcome=0;}
  130.         if (!DiscardACard) {Outcome=1;}
  131.        
  132.         return Outcome;
  133.        
  134.     }//end of SimulateGame
  135.    
  136. }
  137.  
  138. class OpeningHand {
  139.     int NumberOfLands;
  140.     int NumberOfCardType2;
  141.     int NumberOfCardType3;
  142.     int NumberOfCardType4;
  143.     int NumberOfSpells;
  144.  
  145.     int NrOfCards(){
  146.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  147.     }
  148.  
  149.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  150.         NumberOfLands=Nr1;
  151.         NumberOfCardType2=Nr2;
  152.         NumberOfCardType3=Nr3;
  153.         NumberOfCardType4=Nr4;
  154.         NumberOfSpells=Nr5;
  155.     }
  156.  
  157. }//end of OpeningHand
  158.  
  159. class Deck {
  160.     int NumberOfLands;
  161.     int NumberOfCardType2;
  162.     int NumberOfCardType3;
  163.     int NumberOfCardType4;
  164.     int NumberOfSpells;
  165.    
  166.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5) {
  167.         NumberOfLands=Nr1;
  168.         NumberOfCardType2=Nr2;
  169.         NumberOfCardType3=Nr3;
  170.         NumberOfCardType4=Nr4;
  171.         NumberOfSpells=Nr5;
  172.     }
  173.    
  174.     int NrOfCards(){
  175.         return NumberOfLands+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfSpells;
  176.     }
  177.    
  178.     int DrawCard (){
  179.         Random generator = new Random();
  180.         int CardType=0;
  181.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  182.         int OneCutoff=NumberOfLands;
  183.         int TwoCutoff=OneCutoff+NumberOfCardType2;
  184.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
  185.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
  186.         int FiveCutoff=FourCutoff+NumberOfSpells;
  187.  
  188.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfLands--;}
  189.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
  190.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
  191.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
  192.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfSpells--;}
  193.         return CardType;
  194.     }
  195.    
  196. }//end of Deck
RAW Paste Data