frankkarsten

Lupine Prototype Affinity Affinity Simulation

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