frankkarsten

Lupine Prototype Traditional Affinity Simulation

Jul 10th, 2016
1,731
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package lupineprototypetraditionalaffinity;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class LupinePrototypeTraditionalAffinity {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.  
  12.         //CardType 1 is a Darksteel Citadel
  13.         //CardType 2 is a Glimmervoid or basic Mountain
  14.         //CardType 3 is an Inkmoth Nexus or Blinkmoth Nexus
  15.         //CardType 4 is a Chrome Mox
  16.         //CardType 5 is a Springleaf Drum
  17.         //CardType 6 is a Memnite or Ornithopter
  18.         //CardType 7 is a one-drop creature
  19.         //CardType 8 is a two-drop apart from Lupine Prototype
  20.         //CardType 9 is a Lupine Prototype (instead of Steel overseer)
  21.         //CardType 10 is an Etched Champion
  22.         //CardType 11 is a Galvanic Blast
  23.         //CardType 12 is not used
  24.        
  25.         deck.SetDeck(4,5,8,4,4,7,8,8,4,4,4,0);
  26.         double Probability=Probability=ProbabilityForRandomHand(deck,7,10000000);
  27.         System.out.println("Probability:"+Math.round(Probability*10000)/100.0);
  28.        
  29.     }//end of main
  30.  
  31.     public static double ProbabilityForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
  32.        
  33.         Deck remainingdeck=new Deck();
  34.         int NumberOfAttackingLupineOnTurn=0;
  35.         int NumberOfRelevantGames=0;
  36.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  37.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
  38.             remainingdeck.SetDeck(deck.NumberOfCardType1-openinghand.NumberOfCardType1,deck.NumberOfCardType2-openinghand.NumberOfCardType2,deck.NumberOfCardType3-openinghand.NumberOfCardType3,deck.NumberOfCardType4-openinghand.NumberOfCardType4,deck.NumberOfCardType5-openinghand.NumberOfCardType5,deck.NumberOfCardType6-openinghand.NumberOfCardType6,deck.NumberOfCardType7-openinghand.NumberOfCardType7,deck.NumberOfCardType8-openinghand.NumberOfCardType8,deck.NumberOfCardType9-openinghand.NumberOfCardType9,deck.NumberOfCardType10-openinghand.NumberOfCardType10,deck.NumberOfCardType11-openinghand.NumberOfCardType11,deck.NumberOfCardType12-openinghand.NumberOfCardType12);
  39.             int Outcome=SimulateGame(remainingdeck,openinghand);
  40.             if (Outcome==2) {NumberOfAttackingLupineOnTurn++; NumberOfRelevantGames++;}
  41.             if (Outcome==1) {NumberOfRelevantGames++;}
  42.         }
  43.         return NumberOfAttackingLupineOnTurn/(NumberOfRelevantGames+0.0);
  44.     }
  45.    
  46.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
  47.        
  48.         Deck remainingdeck=new Deck();
  49.         OpeningHand openinghand=new OpeningHand();
  50.         int TypeOfCardDrawn;
  51.         boolean KeepHand=false;
  52.        
  53.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  54.             if (KeepHand==false){
  55.                 int NrLands=0;
  56.                 //Note: I view Springleaf Drum and Chrome Mox as lands as well here
  57.                 openinghand.SetHand(0,0,0,0,0,0,0,0,0,0,0,0);
  58.                 remainingdeck.SetDeck(deck.NumberOfCardType1,deck.NumberOfCardType2,deck.NumberOfCardType3,deck.NumberOfCardType4,deck.NumberOfCardType5,deck.NumberOfCardType6,deck.NumberOfCardType7,deck.NumberOfCardType8,deck.NumberOfCardType9,deck.NumberOfCardType10,deck.NumberOfCardType11,deck.NumberOfCardType12);
  59.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  60.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  61.                     if (TypeOfCardDrawn==1) {openinghand.NumberOfCardType1++; NrLands++;}
  62.                     if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++; NrLands++;}
  63.                     if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++; NrLands++;}
  64.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++; NrLands++;}
  65.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfCardType5++; NrLands++;}
  66.                     if (TypeOfCardDrawn==6) {openinghand.NumberOfCardType6++;}
  67.                     if (TypeOfCardDrawn==7) {openinghand.NumberOfCardType7++;}
  68.                     if (TypeOfCardDrawn==8) {openinghand.NumberOfCardType8++;}
  69.                     if (TypeOfCardDrawn==9) {openinghand.NumberOfCardType9++;}
  70.                     if (TypeOfCardDrawn==10) {openinghand.NumberOfCardType10++;}
  71.                     if (TypeOfCardDrawn==11) {openinghand.NumberOfCardType11++;}
  72.                     if (TypeOfCardDrawn==12) {openinghand.NumberOfCardType12++;}
  73.                 }
  74.                 if (NrLands>=2 && NrLands<=5) {KeepHand=true;}
  75.             }
  76.         }
  77.        
  78.         return openinghand;
  79.     }//end of GiveOpeningHandAfterMulls
  80.    
  81.    
  82.     static int SimulateGame(Deck remainingdeck, OpeningHand openinghand) {
  83.        
  84.         int TypeOfCardDrawn;
  85.        
  86.         int CitadelInHand=openinghand.NumberOfCardType1;
  87.         int GlimmervoidInHand=openinghand.NumberOfCardType2;
  88.         int NexusInHand=openinghand.NumberOfCardType3;
  89.         int MoxInHand=openinghand.NumberOfCardType4;
  90.         int DrumInHand=openinghand.NumberOfCardType5;
  91.         int MemniteInHand=openinghand.NumberOfCardType6;
  92.         int OneDropInHand=openinghand.NumberOfCardType7;
  93.         int TwoDropInHand=openinghand.NumberOfCardType8;
  94.         int LupineInHand=openinghand.NumberOfCardType9;
  95.         int EtchedInHand=openinghand.NumberOfCardType10;
  96.         int BlastInHand=openinghand.NumberOfCardType11;
  97.        
  98.         int CitadelInPlay=0;
  99.         int GlimmervoidInPlay=0;
  100.         int NexusInPlay=0;
  101.         int MoxInPlay=0;
  102.         int DrumInPlay=0;
  103.         int MemniteInPlay=0;
  104.         int OneDropInPlay=0;
  105.         int TwoDropInPlay=0;
  106.         int LupineInPlay=0;
  107.         int EtchedInPlay=0;
  108.        
  109.         int AffinityForArtifacts;
  110.         int Metalcraft;
  111.         int TappedMox;
  112.         int TappedDrum;
  113.         int TappedCreature;
  114.         int CreaturesInPlay;
  115.         boolean LandPlayed;
  116.        
  117.         for (int Turn=1; Turn<=5; Turn++){
  118.                        
  119.                 TappedMox=0;
  120.                 TappedDrum=0;
  121.                 TappedCreature=0;
  122.                 LandPlayed=false;
  123.                                
  124.                 if (Turn>1) {
  125.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  126.                     if (TypeOfCardDrawn==1) {CitadelInHand++;}
  127.                     if (TypeOfCardDrawn==2) {GlimmervoidInHand++;}
  128.                     if (TypeOfCardDrawn==3) {NexusInHand++;}
  129.                     if (TypeOfCardDrawn==4) {MoxInHand++;}
  130.                     if (TypeOfCardDrawn==5) {DrumInHand++;}
  131.                     if (TypeOfCardDrawn==6) {MemniteInHand++;}
  132.                     if (TypeOfCardDrawn==7) {OneDropInHand++;}
  133.                     if (TypeOfCardDrawn==8) {TwoDropInHand++;}
  134.                     if (TypeOfCardDrawn==9) {LupineInHand++;}
  135.                     if (TypeOfCardDrawn==10) {EtchedInHand++;}
  136.                     if (TypeOfCardDrawn==11) {BlastInHand++;}
  137.                 }
  138.                
  139.                 //System.out.println("Start Turn "+Turn+" hand: "+CitadelInHand+"Cit "+GlimmervoidInHand+"Gli "+NexusInHand+"Nex "+MoxInHand+"Mox "+DrumInHand+"Dru "+MemniteInHand+"Mem "+OneDropInHand+"One "+TwoDropInHand+"Two "+LupineInHand+"Lup "+FrogmiteInHand+"Fro "+EnforcerInHand+"Enf"+".");
  140.                 //System.out.println("Start Turn "+Turn+" Play: "+CitadelInPlay+"Cit "+GlimmervoidInPlay+"Gli "+NexusInPlay+"Nex "+MoxInPlay+"Mox "+DrumInPlay+"Dru "+MemniteInPlay+"Mem "+OneDropInPlay+"One "+TwoDropInPlay+"Two "+LupineInPlay+"Lup "+FrogmiteInPlay+"Fro "+EnforcerInPlay+"Enf"+".");
  141.  
  142.                 //1. If we can play a land, we do so.
  143.                 if (CitadelInHand>=1) {
  144.                     CitadelInHand--;
  145.                     CitadelInPlay++;
  146.                     LandPlayed=true;
  147.                 }
  148.                
  149.                 if (GlimmervoidInHand>=1 && LandPlayed==false) {
  150.                     GlimmervoidInHand--;
  151.                     GlimmervoidInPlay++;
  152.                     LandPlayed=true;
  153.                 }
  154.  
  155.                 if (NexusInHand>=1 && LandPlayed==false) {
  156.                     NexusInHand--;
  157.                     NexusInPlay++;
  158.                     LandPlayed=true;
  159.                 }
  160.                
  161.                 //2. Dump all Memnites and Ornithopters, and a first Chrome Mox
  162.                
  163.                 MemniteInPlay=MemniteInPlay+MemniteInHand;
  164.                 MemniteInHand=0;
  165.                                
  166.                 if (MoxInHand>=1 && MoxInPlay==0) {
  167.                     MoxInHand--;
  168.                     MoxInPlay=1;
  169.                 }
  170.                
  171.                 //3. Tap all lands for mana.
  172.                
  173.                 int ManaAvailable=CitadelInPlay+GlimmervoidInPlay+NexusInPlay;
  174.                
  175.                 //4. Now, iterating over Moxen and Drums max 4 times realistically, we attempt to play some stuff
  176.                
  177.                 for (int AttemptNumber=1; AttemptNumber<=4; AttemptNumber++){
  178.  
  179.                     Metalcraft=CitadelInPlay+MoxInPlay+DrumInPlay+MemniteInPlay+OneDropInPlay+LupineInPlay+TwoDropInPlay+EtchedInPlay;
  180.                     if (Metalcraft>=3 && MoxInPlay==1 && TappedMox==0){
  181.                         TappedMox=1;
  182.                         ManaAvailable++;
  183.                         ManaAvailable=ManaAvailable+MoxInHand;
  184.                         MoxInHand=0;
  185.                     }
  186.                    
  187.                     CreaturesInPlay=MemniteInPlay+OneDropInPlay+LupineInPlay+TwoDropInPlay+EtchedInPlay;
  188.                     int TappableDrums=Math.min(DrumInPlay-TappedDrum, CreaturesInPlay-TappedCreature);
  189.                     ManaAvailable=ManaAvailable+TappableDrums;
  190.                     TappedDrum=TappableDrums;
  191.                     TappedCreature=TappableDrums;
  192.                    
  193.                     //Attempt to cast Drums
  194.  
  195.                     int CastableDrum=Math.min(DrumInHand, ManaAvailable);
  196.                     DrumInPlay=DrumInPlay+CastableDrum;
  197.                     DrumInHand=DrumInHand-CastableDrum;
  198.                     ManaAvailable=ManaAvailable-CastableDrum;
  199.  
  200.                     //Attempt to cast Etched Champ
  201.                    
  202.                     int CastableEtched=Math.min(EtchedInHand, ManaAvailable/3);
  203.                     EtchedInPlay=EtchedInPlay+CastableEtched;
  204.                     EtchedInHand=EtchedInHand-CastableEtched;
  205.                     ManaAvailable=ManaAvailable-CastableEtched*3;
  206.  
  207.                     // Attempt to cast Lupine
  208.  
  209.                     int CastableLupine=Math.min(LupineInHand, ManaAvailable/2);
  210.                     LupineInPlay=LupineInPlay+CastableLupine;
  211.                     LupineInHand=LupineInHand-CastableLupine;
  212.                     ManaAvailable=ManaAvailable-CastableLupine*2;
  213.  
  214.                     //6. Attempt to cast other 2-drops
  215.  
  216.                     int CastableTwoDrop=Math.min(TwoDropInHand, ManaAvailable/2);
  217.                     TwoDropInPlay=TwoDropInPlay+CastableTwoDrop;
  218.                     TwoDropInHand=TwoDropInHand-CastableTwoDrop;
  219.                     ManaAvailable=ManaAvailable-CastableTwoDrop*2;
  220.  
  221.                     //6. Attempt to cast 1-drops
  222.  
  223.                     int CastableOneDrop=Math.min(OneDropInHand, ManaAvailable);
  224.                     OneDropInPlay=OneDropInPlay+CastableOneDrop;
  225.                     OneDropInHand=OneDropInHand-CastableOneDrop;
  226.                     ManaAvailable=ManaAvailable-CastableOneDrop;
  227.  
  228.                 }
  229.                
  230.                 //7. Cast Blasts
  231.                                
  232.                 int CastableBlasts=Math.min(Math.min(BlastInHand, ManaAvailable),MoxInPlay+DrumInPlay+GlimmervoidInPlay);
  233.                 BlastInHand=BlastInHand-CastableBlasts;
  234.                
  235.                        
  236.         }//end of the for-loop over the turns
  237.        
  238.         int NumberOfCardsInHand=CitadelInHand+GlimmervoidInHand+NexusInHand+MoxInHand+DrumInHand+MemniteInHand+OneDropInHand+TwoDropInHand+LupineInHand+EtchedInHand+BlastInHand;
  239.                
  240.         int Outcome=0;
  241.         if (NumberOfCardsInHand==0 && LupineInPlay>=1) {Outcome=2;}
  242.         if (NumberOfCardsInHand>0 && LupineInPlay>=1) {Outcome=1;}
  243.        
  244.         return Outcome;
  245.        
  246.     }//end of SimulateGame
  247.    
  248.  
  249. }
  250.  
  251. class OpeningHand {
  252.     int NumberOfCardType1;
  253.     int NumberOfCardType2;
  254.     int NumberOfCardType3;
  255.     int NumberOfCardType4;
  256.     int NumberOfCardType5;
  257.     int NumberOfCardType6;
  258.     int NumberOfCardType7;
  259.     int NumberOfCardType8;
  260.     int NumberOfCardType9;
  261.     int NumberOfCardType10;
  262.     int NumberOfCardType11;
  263.     int NumberOfCardType12;
  264.     //I really should've used arrays here, lol
  265.  
  266.     int NrOfCards(){
  267.         return NumberOfCardType1+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfCardType5+NumberOfCardType6+NumberOfCardType7+NumberOfCardType8+NumberOfCardType9+NumberOfCardType10+NumberOfCardType11+NumberOfCardType12;
  268.     }
  269.  
  270.     void SetHand (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6, int Nr7, int Nr8, int Nr9, int Nr10, int Nr11, int Nr12) {
  271.         NumberOfCardType1=Nr1;
  272.         NumberOfCardType2=Nr2;
  273.         NumberOfCardType3=Nr3;
  274.         NumberOfCardType4=Nr4;
  275.         NumberOfCardType5=Nr5;
  276.         NumberOfCardType6=Nr6;
  277.         NumberOfCardType7=Nr7;
  278.         NumberOfCardType8=Nr8;
  279.         NumberOfCardType9=Nr9;
  280.         NumberOfCardType10=Nr10;
  281.         NumberOfCardType11=Nr11;
  282.         NumberOfCardType11=Nr12;
  283.     }
  284.  
  285. }//end of OpeningHand
  286.  
  287. class Deck {
  288.     int NumberOfCardType1;
  289.     int NumberOfCardType2;
  290.     int NumberOfCardType3;
  291.     int NumberOfCardType4;
  292.     int NumberOfCardType5;
  293.     int NumberOfCardType6;
  294.     int NumberOfCardType7;
  295.     int NumberOfCardType8;
  296.     int NumberOfCardType9;
  297.     int NumberOfCardType10;
  298.     int NumberOfCardType11;
  299.     int NumberOfCardType12;
  300.     //I really should've used arrays here, lol
  301.  
  302.     void SetDeck (int Nr1, int Nr2, int Nr3, int Nr4, int Nr5, int Nr6, int Nr7, int Nr8, int Nr9, int Nr10, int Nr11, int Nr12) {
  303.         NumberOfCardType1=Nr1;
  304.         NumberOfCardType2=Nr2;
  305.         NumberOfCardType3=Nr3;
  306.         NumberOfCardType4=Nr4;
  307.         NumberOfCardType5=Nr5;
  308.         NumberOfCardType6=Nr6;
  309.         NumberOfCardType7=Nr7;
  310.         NumberOfCardType8=Nr8;
  311.         NumberOfCardType9=Nr9;
  312.         NumberOfCardType10=Nr10;
  313.         NumberOfCardType11=Nr11;
  314.         NumberOfCardType12=Nr12;
  315.     }
  316.    
  317.     int NrOfCards(){
  318.         return NumberOfCardType1+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfCardType5+NumberOfCardType6+NumberOfCardType7+NumberOfCardType8+NumberOfCardType9+NumberOfCardType10+NumberOfCardType11+NumberOfCardType12;
  319.     }
  320.    
  321.     int DrawCard (){
  322.         Random generator = new Random();
  323.         int CardType=0;
  324.         int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  325.         int OneCutoff=NumberOfCardType1;
  326.         int TwoCutoff=OneCutoff+NumberOfCardType2;
  327.         int ThreeCutoff=TwoCutoff+NumberOfCardType3;
  328.         int FourCutoff=ThreeCutoff+NumberOfCardType4;
  329.         int FiveCutoff=FourCutoff+NumberOfCardType5;
  330.         int SixCutoff=FiveCutoff+NumberOfCardType6;
  331.         int SevenCutoff=SixCutoff+NumberOfCardType7;
  332.         int EightCutoff=SevenCutoff+NumberOfCardType8;
  333.         int NineCutoff=EightCutoff+NumberOfCardType9;
  334.         int TenCutoff=NineCutoff+NumberOfCardType10;
  335.         int ElevenCutoff=TenCutoff+NumberOfCardType11;
  336.         int TwelveCutoff=ElevenCutoff+NumberOfCardType12;
  337.        
  338.         if (RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfCardType1--;}
  339.         if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
  340.         if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
  341.         if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
  342.         if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfCardType5--;}
  343.         if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff && RandomIntegerBetweenOneAndDeckSize<=SixCutoff) {CardType=6; this.NumberOfCardType6--;}
  344.         if (RandomIntegerBetweenOneAndDeckSize>SixCutoff && RandomIntegerBetweenOneAndDeckSize<=SevenCutoff) {CardType=7; this.NumberOfCardType7--;}
  345.         if (RandomIntegerBetweenOneAndDeckSize>SevenCutoff && RandomIntegerBetweenOneAndDeckSize<=EightCutoff) {CardType=8; this.NumberOfCardType8--;}
  346.         if (RandomIntegerBetweenOneAndDeckSize>EightCutoff && RandomIntegerBetweenOneAndDeckSize<=NineCutoff) {CardType=9; this.NumberOfCardType9--;}
  347.         if (RandomIntegerBetweenOneAndDeckSize>NineCutoff && RandomIntegerBetweenOneAndDeckSize<=TenCutoff) {CardType=10; this.NumberOfCardType10--;}
  348.         if (RandomIntegerBetweenOneAndDeckSize>TenCutoff && RandomIntegerBetweenOneAndDeckSize<=ElevenCutoff) {CardType=11; this.NumberOfCardType11--;}
  349.         if (RandomIntegerBetweenOneAndDeckSize>ElevenCutoff && RandomIntegerBetweenOneAndDeckSize<=TwelveCutoff) {CardType=12; this.NumberOfCardType12--;}
  350.  
  351.         return CardType;
  352.     }
  353.    
  354. }//end of Deck
RAW Paste Data