Advertisement
frankkarsten

MTG Optimal Deck for 40 life format

Sep 23rd, 2013
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.27 KB | None | 0 0
  1. package doublelifegoldfish;
  2.  
  3. import java.util.Arrays.*;
  4. import java.util.Random;
  5.  
  6. public class DoubleLifeGoldfish {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Deck deck=new Deck();
  11.         boolean[][][][][][] KeepOpeningHand = new boolean[8][8][8][8][8][8];
  12.         boolean TakeTimeToFindOptimalMulliganStrategy = true;
  13.         if (TakeTimeToFindOptimalMulliganStrategy==false) {KeepOpeningHand=GiveLooseMulliganStrategy();}
  14.         int NumberOfSimulationsPerDeck=2000;
  15.         double FastestTurn=50;
  16.         double KillTurn;
  17.         int OptimalOneDrops=0;
  18.         int OptimalTwoDrops=0;
  19.         int OptimalThreeDrops=0;
  20.         int OptimalBolts=0;
  21.         int OptimalLands=0;
  22.  
  23.         for (int TripleOneDropCount=0; TripleOneDropCount<=10; TripleOneDropCount++){
  24.             for (int TripleTwoDropCount=0; TripleTwoDropCount<=10; TripleTwoDropCount++){
  25.                 for (int TripleThreeDropCount=0; TripleThreeDropCount<=20; TripleThreeDropCount++){
  26.                     for (int TripleBoltCount=0; TripleBoltCount<=10; TripleBoltCount++){
  27.                         int TripleLandCount=20-TripleOneDropCount-TripleTwoDropCount-TripleThreeDropCount-TripleBoltCount;
  28.                         if (TripleLandCount>=0 && TripleLandCount<=20) {
  29.                             deck.SetDeck(3*TripleOneDropCount,3*TripleTwoDropCount,3*TripleThreeDropCount,3*TripleBoltCount,3*TripleLandCount);
  30.                             deck.PrintDeckBrief();
  31.                             KillTurn=AverageKillTurnForRandomHand(deck,7,KeepOpeningHand,NumberOfSimulationsPerDeck);
  32.                             System.out.println(" "+KillTurn);
  33.                             if (KillTurn<FastestTurn){
  34.                                 FastestTurn=KillTurn;
  35.                                 OptimalOneDrops=3*TripleOneDropCount;
  36.                                 OptimalTwoDrops=3*TripleTwoDropCount;
  37.                                 OptimalThreeDrops=3*TripleThreeDropCount;
  38.                                 OptimalBolts=3*TripleBoltCount;
  39.                                 OptimalLands=3*TripleLandCount;
  40.                             }
  41.                         }
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.        
  47.         System.out.println("----------------");
  48.         System.out.print("The optimal deck after the grid-enumeration at a small number of simulations per deck was:");
  49.         deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalBolts,OptimalLands);
  50.         deck.PrintDeckBrief();
  51.         System.out.println();
  52.         System.out.println("----------------");
  53.        
  54.         NumberOfSimulationsPerDeck=10000;
  55.         int NewOptimalOneDrops=0;
  56.         int NewOptimalTwoDrops=0;
  57.         int NewOptimalThreeDrops=0;
  58.         int NewOptimalBolts=0;
  59.         int NewOptimalLands=0;
  60.         boolean ContinueLocalSearch=true;
  61.        
  62.         do {
  63.             FastestTurn=50;
  64.             for (int OneDropCount=Math.max(0,OptimalOneDrops-4); OneDropCount<=Math.min(60,OptimalOneDrops+4); OneDropCount++){
  65.                 for (int TwoDropCount=Math.max(0,OptimalTwoDrops-4); TwoDropCount<=Math.min(60,OptimalTwoDrops+4); TwoDropCount++){
  66.                     for (int ThreeDropCount=Math.max(0,OptimalThreeDrops-4); ThreeDropCount<=Math.min(60,OptimalThreeDrops+4); ThreeDropCount++){
  67.                         for (int BoltCount=Math.max(0,OptimalBolts-4); BoltCount<=Math.min(60,OptimalBolts+4); BoltCount++){
  68.                            int LandCount=60-OneDropCount-TwoDropCount-ThreeDropCount-BoltCount;
  69.                            if (LandCount>=Math.max(0,OptimalLands-3) && LandCount<=Math.min(60,OptimalLands+3)) {
  70.                                 deck.SetDeck(OneDropCount,TwoDropCount,ThreeDropCount,BoltCount,LandCount);
  71.                                 deck.PrintDeckBrief();
  72.                                 KillTurn=AverageKillTurnForRandomHand(deck,7,KeepOpeningHand,NumberOfSimulationsPerDeck);
  73.                                 System.out.println(" "+KillTurn);
  74.                                 if (KillTurn<FastestTurn){
  75.                                     FastestTurn=KillTurn;
  76.                                     NewOptimalOneDrops=OneDropCount;
  77.                                     NewOptimalTwoDrops=TwoDropCount;
  78.                                     NewOptimalThreeDrops=ThreeDropCount;
  79.                                     NewOptimalBolts=BoltCount;
  80.                                     NewOptimalLands=LandCount;
  81.                                 }
  82.                             }
  83.                         }
  84.                     }
  85.                 }
  86.             }
  87.             if (Math.abs(NewOptimalOneDrops-OptimalOneDrops)+Math.abs(NewOptimalTwoDrops-OptimalTwoDrops)+Math.abs(NewOptimalThreeDrops-OptimalThreeDrops)+Math.abs(NewOptimalBolts-OptimalBolts)+Math.abs(NewOptimalLands-OptimalLands)<=2) {ContinueLocalSearch=false;}
  88.             OptimalOneDrops=NewOptimalOneDrops;
  89.             OptimalTwoDrops=NewOptimalTwoDrops;
  90.             OptimalThreeDrops=NewOptimalThreeDrops;
  91.             OptimalBolts=NewOptimalBolts;
  92.             OptimalLands=NewOptimalLands;
  93.             System.out.println("----------------");
  94.             System.out.print("The optimal deck after the local search was:");
  95.             deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalBolts,OptimalLands);
  96.             deck.PrintDeckBrief();
  97.             System.out.println();
  98.             System.out.println("----------------");
  99.         } while (ContinueLocalSearch);
  100.        
  101.         TakeTimeToFindOptimalMulliganStrategy=true;
  102.         NumberOfSimulationsPerDeck=50000;
  103.         ContinueLocalSearch=true;
  104.        
  105.         do {
  106.             FastestTurn=50;
  107.             for (int OneDropCount=Math.max(0,OptimalOneDrops-2); OneDropCount<=Math.min(60,OptimalOneDrops+2); OneDropCount++){
  108.                 for (int TwoDropCount=Math.max(0,OptimalTwoDrops-2); TwoDropCount<=Math.min(60,OptimalTwoDrops+2); TwoDropCount++){
  109.                     for (int ThreeDropCount=Math.max(0,OptimalThreeDrops-2); ThreeDropCount<=Math.min(60,OptimalThreeDrops+2); ThreeDropCount++){
  110.                         for (int BoltCount=Math.max(0,OptimalBolts-2); BoltCount<=Math.min(60,OptimalBolts+2); BoltCount++){
  111.                             int LandCount=60-OneDropCount-TwoDropCount-ThreeDropCount-BoltCount;
  112.                             if (LandCount>=Math.max(0,OptimalLands-2) && LandCount<=Math.min(60,OptimalLands+2)) {
  113.                                 deck.SetDeck(OneDropCount,TwoDropCount,ThreeDropCount,BoltCount,LandCount);
  114.                                 deck.PrintDeckBrief();
  115.                                 if (TakeTimeToFindOptimalMulliganStrategy==true) {KeepOpeningHand=GiveOptimalMulliganStrategy(deck);}
  116.                                 KillTurn=AverageKillTurnForRandomHand(deck,7,KeepOpeningHand,NumberOfSimulationsPerDeck);
  117.                                 System.out.println(" "+KillTurn);
  118.                                 if (KillTurn<FastestTurn){
  119.                                     FastestTurn=KillTurn;
  120.                                     NewOptimalOneDrops=OneDropCount;
  121.                                     NewOptimalTwoDrops=TwoDropCount;
  122.                                     NewOptimalThreeDrops=ThreeDropCount;
  123.                                     NewOptimalBolts=BoltCount;
  124.                                     NewOptimalLands=LandCount;
  125.                                 }
  126.                             }
  127.                         }
  128.                     }
  129.                 }
  130.             }
  131.             if (Math.abs(NewOptimalOneDrops-OptimalOneDrops)+Math.abs(NewOptimalTwoDrops-OptimalTwoDrops)+Math.abs(NewOptimalThreeDrops-OptimalThreeDrops)+Math.abs(NewOptimalBolts-OptimalBolts)+Math.abs(NewOptimalLands-OptimalLands)==0) {ContinueLocalSearch=false;}
  132.             OptimalOneDrops=NewOptimalOneDrops;
  133.             OptimalTwoDrops=NewOptimalTwoDrops;
  134.             OptimalThreeDrops=NewOptimalThreeDrops;
  135.             OptimalBolts=NewOptimalBolts;
  136.             OptimalLands=NewOptimalLands;
  137.             System.out.println("----------------");
  138.             System.out.print("The final optimal deck:");
  139.             deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalBolts,OptimalLands);
  140.             deck.PrintDeckBrief();
  141.             System.out.println();
  142.             System.out.println("----------------");
  143.         } while (ContinueLocalSearch);
  144.     }//end of main
  145.  
  146.     public static boolean[][][][][][] GiveOptimalMulliganStrategy(Deck deck) {
  147.         boolean[][][][][][] KeepOpeningHand = new boolean[8][8][8][8][8][8];
  148.         OpeningHand openinghand=new OpeningHand();
  149.         int NumberOfSimulationsPerOpeningHandSize=10000;
  150.         int OriginalNr1Cost=deck.NumberOf1Cost;
  151.         int OriginalNr2Cost=deck.NumberOf2Cost;
  152.         int OriginalNr3Cost=deck.NumberOf3Cost;
  153.         int OriginalNrBolts=deck.NumberOfBolts;
  154.         int OriginalNrLands=deck.NumberOfLands;
  155.         double CutOffTurn = AverageKillTurnForRandomHand(deck,1,KeepOpeningHand,NumberOfSimulationsPerOpeningHandSize);
  156.         for (int StartingCards=2; StartingCards<=7; StartingCards++){
  157.             System.out.print(".");
  158.             for (int OneDropCount=0; OneDropCount<=OriginalNr1Cost && OneDropCount<=StartingCards; OneDropCount++){
  159.                 for (int TwoDropCount=0; TwoDropCount<=OriginalNr2Cost && TwoDropCount+OneDropCount<=StartingCards; TwoDropCount++){
  160.                     for  (int ThreeDropCount=0; ThreeDropCount<=OriginalNr3Cost && ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; ThreeDropCount++){
  161.                         for (int BoltCount=0; BoltCount<=OriginalNrBolts && BoltCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; BoltCount++){
  162.                             int LandCount=StartingCards-OneDropCount-TwoDropCount-ThreeDropCount-BoltCount;
  163.                             if (LandCount<=OriginalNrLands){
  164.                                 openinghand.SetHand(OneDropCount, TwoDropCount, ThreeDropCount, BoltCount, LandCount);
  165.                                 deck.SetDeck(OriginalNr1Cost,OriginalNr2Cost,OriginalNr3Cost,OriginalNrBolts,OriginalNrLands);
  166.                                 double AvgKillTurn=AverageKillTurnForSpecificHand(deck,openinghand);
  167.                                 if (AvgKillTurn<=CutOffTurn) { KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][BoltCount][LandCount]=true;}
  168.                                 if (AvgKillTurn>CutOffTurn) { KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][BoltCount][LandCount]=false;}
  169.                                 }
  170.                             }
  171.                         }
  172.                     }
  173.                 }
  174.             deck.SetDeck(OriginalNr1Cost,OriginalNr2Cost,OriginalNr3Cost,OriginalNrBolts,OriginalNrLands);
  175.             if (StartingCards<7) {CutOffTurn=AverageKillTurnForRandomHand(deck,StartingCards,KeepOpeningHand,NumberOfSimulationsPerOpeningHandSize);}
  176.         }
  177.         return KeepOpeningHand;
  178.     }
  179.  
  180.     public static boolean[][][][][][] GiveLooseMulliganStrategy() {
  181.         boolean[][][][][][] KeepOpeningHand = new boolean[8][8][8][8][8][8];
  182.         for (int StartingCards=2; StartingCards<=7; StartingCards++){
  183.             for (int OneDropCount=0; OneDropCount<=StartingCards; OneDropCount++){
  184.                 for (int TwoDropCount=0; TwoDropCount+OneDropCount<=StartingCards; TwoDropCount++){
  185.                     for  (int ThreeDropCount=0; ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; ThreeDropCount++){
  186.                         for (int BoltCount=0; BoltCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; BoltCount++){
  187.                             int LandCount=StartingCards-OneDropCount-TwoDropCount-ThreeDropCount-BoltCount;
  188.                             KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][BoltCount][LandCount]=false;
  189.                             if (LandCount>=1 && LandCount<=4) {KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][BoltCount][LandCount]=true;}
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.         }
  195.         return KeepOpeningHand;
  196.     }
  197.    
  198.     public static double AverageKillTurnForSpecificHand(Deck deck, OpeningHand openinghand){
  199.         int NumberOfIterations=2000;
  200.         Deck remainingdeck=new Deck();
  201.         double AverageKillTurn=0;
  202.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  203.             remainingdeck.SetDeck(deck.NumberOf1Cost-openinghand.NumberOf1Cost,deck.NumberOf2Cost-openinghand.NumberOf2Cost,deck.NumberOf3Cost-openinghand.NumberOf3Cost,deck.NumberOfBolts-openinghand.NumberOfBolts,deck.NumberOfLands-openinghand.NumberOfLands);
  204.             AverageKillTurn=AverageKillTurn+TurnKill(remainingdeck,openinghand);
  205.         }
  206.         return (AverageKillTurn/(NumberOfIterations+0.0));
  207.     }//end of AverageKillTurnForSpecificHand
  208.  
  209.     public static double AverageKillTurnForRandomHand(Deck deck, int StartingCards, boolean[][][][][][] KeepOpeningHand, int NumberOfIterations){
  210.         Deck remainingdeck=new Deck();
  211.         double AverageKillTurn=0;
  212.         for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
  213.             OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards, KeepOpeningHand);
  214.             remainingdeck.SetDeck(deck.NumberOf1Cost-openinghand.NumberOf1Cost,deck.NumberOf2Cost-openinghand.NumberOf2Cost,deck.NumberOf3Cost-openinghand.NumberOf3Cost,deck.NumberOfBolts-openinghand.NumberOfBolts,deck.NumberOfLands-openinghand.NumberOfLands);
  215.             AverageKillTurn=AverageKillTurn+TurnKill(remainingdeck,openinghand);
  216.             if ( IterationCounter % 200000 == 0) {System.out.print(".");}
  217.         }
  218.         return AverageKillTurn/(NumberOfIterations+0.0);
  219.     }//end of AverageKillTurnForRandomHand
  220.    
  221.     static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards, boolean[][][][][][] KeepOpeningHand) {
  222.        
  223.         Deck remainingdeck=new Deck();
  224.         OpeningHand openinghand=new OpeningHand();
  225.         int TypeOfCardDrawn;
  226.         boolean KeepHand=false;
  227.        
  228.         for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
  229.             if (KeepHand==false && StartingCards>=OpeningHandSize){
  230.                 openinghand.ResetHand();
  231.                 remainingdeck.SetDeck(deck.NumberOf1Cost,deck.NumberOf2Cost,deck.NumberOf3Cost,deck.NumberOfBolts,deck.NumberOfLands);
  232.                 for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
  233.                     TypeOfCardDrawn=remainingdeck.DrawCard();
  234.                     if (TypeOfCardDrawn==1) {openinghand.NumberOf1Cost++;}
  235.                     if (TypeOfCardDrawn==2) {openinghand.NumberOf2Cost++;}
  236.                     if (TypeOfCardDrawn==3) {openinghand.NumberOf3Cost++;}
  237.                     if (TypeOfCardDrawn==4) {openinghand.NumberOfBolts++;}
  238.                     if (TypeOfCardDrawn==5) {openinghand.NumberOfLands++;}
  239.                 }
  240.                 KeepHand=true;
  241.                 if (OpeningHandSize>1) {
  242.                     if (KeepOpeningHand[OpeningHandSize][openinghand.NumberOf1Cost][openinghand.NumberOf2Cost][openinghand.NumberOf3Cost][openinghand.NumberOfBolts][openinghand.NumberOfLands]==false) {KeepHand=false;}
  243.                 }
  244.             }
  245.         }
  246.        
  247.         return openinghand;
  248.     }//end of GiveOpeningHandAfterMulls
  249.    
  250.     static int TurnKill(Deck remainingdeck, OpeningHand openinghand) {
  251.        
  252.         int OneCostPower=2;
  253.         int TwoCostPower=4;
  254.         int ThreeCostPower=6;
  255.         int BoltDamage=3;
  256.        
  257.         int Turn=0;
  258.         int OppLife=40;
  259.         int ManaLeft;
  260.         int TypeOfCardDrawn;
  261.    
  262.         int OneDropsInPlay=0;
  263.         int TwoDropsInPlay=0;
  264.         int ThreeDropsInPlay=0;
  265.         int LandsInPlay=0;
  266.        
  267.         int OneDropsInHand=openinghand.NumberOf1Cost;
  268.         int TwoDropsInHand=openinghand.NumberOf2Cost;
  269.         int ThreeDropsInHand=openinghand.NumberOf3Cost;
  270.         int BoltsInHand=openinghand.NumberOfBolts;
  271.         int LandsInHand=openinghand.NumberOfLands;
  272.        
  273.         do {
  274.            
  275.             Turn++;
  276.            
  277.             if (Turn==1) {
  278.                
  279.                 if (LandsInHand>=1) {LandsInPlay++; LandsInHand--;}
  280.                 ManaLeft=LandsInPlay;
  281.                 if (OneDropsInHand>=1 && ManaLeft==1) {OneDropsInPlay++; ManaLeft--; OneDropsInHand--;}
  282.                 if (BoltsInHand>=1 && ManaLeft==1) {OppLife=OppLife-BoltDamage; ManaLeft--; BoltsInHand--;}
  283.                
  284.             } //end of the first turn
  285.            
  286.             if (Turn>1) {
  287.  
  288.                 TypeOfCardDrawn=remainingdeck.DrawCard();
  289.                 if (TypeOfCardDrawn==1) {OneDropsInHand++;}
  290.                 if (TypeOfCardDrawn==2) {TwoDropsInHand++;}
  291.                 if (TypeOfCardDrawn==3) {ThreeDropsInHand++;}
  292.                 if (TypeOfCardDrawn==4) {BoltsInHand++;}
  293.                 if (TypeOfCardDrawn==5) {LandsInHand++;}
  294.  
  295.                 if (LandsInHand>=1) {LandsInPlay++; LandsInHand--;}
  296.                 ManaLeft=LandsInPlay;
  297.                 OppLife=OppLife-OneCostPower*OneDropsInPlay;
  298.                 OppLife=OppLife-TwoCostPower*TwoDropsInPlay;
  299.                 OppLife=OppLife-ThreeCostPower*ThreeDropsInPlay;
  300.                
  301.                 if (ManaLeft==1) {
  302.                     int CastableBolts=Math.min(BoltsInHand, ManaLeft);
  303.                     if (OppLife<=CastableBolts*BoltDamage) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  304.                     if (OneDropsInHand>=1 && ManaLeft==1) {OneDropsInPlay++; ManaLeft--; OneDropsInHand--;}
  305.                     if (BoltsInHand>=1 && ManaLeft==1) {OppLife=OppLife-BoltDamage; ManaLeft--; BoltsInHand--;}
  306.                 }
  307.                
  308.                 if (ManaLeft==2) {
  309.                     int CastableBolts=Math.min(BoltsInHand, ManaLeft);
  310.                     if (OppLife<=CastableBolts*BoltDamage) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  311.                     if (TwoDropsInHand>=1 && ManaLeft==2) {TwoDropsInPlay++; ManaLeft=ManaLeft-2; TwoDropsInHand--;}
  312.                     int CastableOneDrops=Math.min(OneDropsInHand, ManaLeft);
  313.                     if (CastableOneDrops>=1) {OneDropsInPlay=OneDropsInPlay+CastableOneDrops; ManaLeft=ManaLeft-CastableOneDrops; OneDropsInHand=OneDropsInHand-CastableOneDrops;}
  314.                     CastableBolts=Math.min(BoltsInHand, ManaLeft);
  315.                     if (CastableBolts>=1) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  316.                 }
  317.  
  318.                 if (ManaLeft==3) {
  319.                     int CastableBolts=Math.min(BoltsInHand, ManaLeft);
  320.                     if (OppLife<=CastableBolts*BoltDamage) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  321.                     if (ThreeDropsInHand>=1 && ManaLeft==3) {ThreeDropsInPlay++; ManaLeft=ManaLeft-3; ThreeDropsInHand--;}
  322.                     if (TwoDropsInHand>=1 && ManaLeft>=2) {TwoDropsInPlay++; ManaLeft=ManaLeft-2; TwoDropsInHand--;}
  323.                     int CastableOneDrops=Math.min(OneDropsInHand, ManaLeft);
  324.                     if (CastableOneDrops>=1) {OneDropsInPlay=OneDropsInPlay+CastableOneDrops; ManaLeft=ManaLeft-CastableOneDrops; OneDropsInHand=OneDropsInHand-CastableOneDrops;}
  325.                     CastableBolts=Math.min(BoltsInHand, ManaLeft);
  326.                     if (CastableBolts>=1) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  327.                 }
  328.                
  329.                 if (ManaLeft==4) {
  330.                     int CastableBolts=Math.min(BoltsInHand, ManaLeft);
  331.                     if (OppLife<=CastableBolts*BoltDamage) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  332.                     int CastableTwoDrops=Math.min(TwoDropsInHand, ManaLeft/2);
  333.                     if (CastableTwoDrops==2) {TwoDropsInPlay=TwoDropsInPlay+2; ManaLeft=ManaLeft-4; TwoDropsInHand=TwoDropsInHand-2;}
  334.                     if (ThreeDropsInHand>=1 && ManaLeft>=3) {ThreeDropsInPlay++; ManaLeft=ManaLeft-3; ThreeDropsInHand--;}
  335.                     if (TwoDropsInHand>=1 && ManaLeft>=2) {TwoDropsInPlay++; ManaLeft=ManaLeft-2; TwoDropsInHand--;}
  336.                     int CastableOneDrops=Math.min(OneDropsInHand, ManaLeft);
  337.                     if (CastableOneDrops>=1) {OneDropsInPlay=OneDropsInPlay+CastableOneDrops; ManaLeft=ManaLeft-CastableOneDrops; OneDropsInHand=OneDropsInHand-CastableOneDrops;}
  338.                     CastableBolts=Math.min(BoltsInHand, ManaLeft);
  339.                     if (CastableBolts>=1) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  340.                 }
  341.                        
  342.                 if (ManaLeft>=5) {
  343.                     int CastableBolts=Math.min(BoltsInHand, ManaLeft);
  344.                     if (OppLife<=CastableBolts*BoltDamage) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  345.                     int CastableThreeDrops=Math.min(ThreeDropsInHand, ManaLeft/3);
  346.                     if (CastableThreeDrops>=1) {ThreeDropsInPlay=ThreeDropsInPlay+CastableThreeDrops; ManaLeft=ManaLeft-3*CastableThreeDrops; ThreeDropsInHand=ThreeDropsInHand-CastableThreeDrops;}
  347.                     int CastableTwoDrops=Math.min(TwoDropsInHand, ManaLeft/2);
  348.                     if (CastableTwoDrops>=1) {TwoDropsInPlay=TwoDropsInPlay+CastableTwoDrops; ManaLeft=ManaLeft-2*CastableTwoDrops; TwoDropsInHand=TwoDropsInHand-CastableTwoDrops;}
  349.                     int CastableOneDrops=Math.min(OneDropsInHand, ManaLeft);
  350.                     if (CastableOneDrops>=1) {OneDropsInPlay=OneDropsInPlay+CastableOneDrops; ManaLeft=ManaLeft-CastableOneDrops; OneDropsInHand=OneDropsInHand-CastableOneDrops;}
  351.                     CastableBolts=Math.min(BoltsInHand, ManaLeft);
  352.                     if (CastableBolts>=1) {OppLife=OppLife-CastableBolts*BoltDamage; ManaLeft=ManaLeft-CastableBolts; BoltsInHand=BoltsInHand-CastableBolts;}
  353.                 }
  354.                
  355.             } //end of a turn in which we drew a card and attacked
  356.  
  357.         } while (OppLife>0 &&Turn<=50);
  358.        
  359.         return Turn;
  360.     }//end of TurnKill
  361.  
  362. }//end of OptimalAggroGoldfishDeck
  363.  
  364. class OpeningHand {
  365.     int NumberOf1Cost;
  366.     int NumberOf2Cost;
  367.     int NumberOf3Cost;
  368.     int NumberOfBolts;
  369.     int NumberOfLands;
  370.  
  371.     void ResetHand(){
  372.         NumberOf1Cost=0;
  373.         NumberOf2Cost=0;
  374.         NumberOf3Cost=0;
  375.         NumberOfBolts=0;
  376.         NumberOfLands=0;
  377.     }
  378.            
  379.     void SetHand (int Nr1Cost, int Nr2Cost, int Nr3Cost, int NrBolts, int NrLands) {
  380.         NumberOf1Cost=Nr1Cost;
  381.         NumberOf2Cost=Nr2Cost;
  382.         NumberOf3Cost=Nr3Cost;
  383.         NumberOfBolts=NrBolts;
  384.         NumberOfLands=NrLands;
  385.     }
  386.  
  387. }//end of OpeningHand
  388.  
  389. class Deck {
  390.     int NumberOf1Cost;
  391.     int NumberOf2Cost;
  392.     int NumberOf3Cost;
  393.     int NumberOfBolts;
  394.     int NumberOfLands;
  395.  
  396.     void PrintDeckBrief () {
  397.         if(NumberOf1Cost<10) {System.out.print("0");}
  398.         System.out.print(NumberOf1Cost+" ");
  399.         if(NumberOf2Cost<10) {System.out.print("0");}
  400.         System.out.print(NumberOf2Cost+" ");
  401.         if(NumberOf3Cost<10) {System.out.print("0");}
  402.         System.out.print(NumberOf3Cost+" ");
  403.         if(NumberOfBolts<10) {System.out.print("0");}
  404.         System.out.print(NumberOfBolts+" ");
  405.         if(NumberOfLands<10) {System.out.print("0");}
  406.         System.out.print(NumberOfLands);
  407.         System.out.print(" ");
  408.     }
  409.  
  410.     void SetDeck (int Nr1Cost, int Nr2Cost, int Nr3Cost, int NrBolts, int NrLands) {
  411.         NumberOf1Cost=Nr1Cost;
  412.         NumberOf2Cost=Nr2Cost;
  413.         NumberOf3Cost=Nr3Cost;
  414.         NumberOfBolts=NrBolts;
  415.         NumberOfLands=NrLands;
  416.     }
  417.    
  418.     int NrOfCards(){
  419.         return NumberOf1Cost+NumberOf2Cost+NumberOf3Cost+NumberOfBolts+NumberOfLands;
  420.     }
  421.    
  422.     int DrawCard (){
  423.             Random generator = new Random();
  424.             int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
  425.             int CardType=0;
  426.             int OneCostCutoff=NumberOf1Cost;
  427.             int TwoCostCutoff=OneCostCutoff+NumberOf2Cost;
  428.             int ThreeCostCutoff=TwoCostCutoff+NumberOf3Cost;
  429.             int BoltCutoff=ThreeCostCutoff+NumberOfBolts;
  430.             int LandCutoff=BoltCutoff+NumberOfLands;
  431.            
  432.             if (RandomIntegerBetweenOneAndDeckSize<=OneCostCutoff) {CardType=1; this.NumberOf1Cost--;}
  433.             if (RandomIntegerBetweenOneAndDeckSize>OneCostCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCostCutoff) {CardType=2; this.NumberOf2Cost--;}
  434.             if (RandomIntegerBetweenOneAndDeckSize>TwoCostCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCostCutoff) {CardType=3; this.NumberOf3Cost--;}
  435.             if (RandomIntegerBetweenOneAndDeckSize>ThreeCostCutoff && RandomIntegerBetweenOneAndDeckSize<=BoltCutoff) {CardType=4; this.NumberOfBolts--;}
  436.             if (RandomIntegerBetweenOneAndDeckSize>BoltCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=5; this.NumberOfLands--;}
  437.             return CardType;
  438.     }
  439.    
  440. }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement