Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package optimalmanacurve;
- import java.util.Arrays.*;
- import java.util.Random;
- public class OptimalManaCurve {
- public static void main(String[] args) {
- Deck deck=new Deck();
- boolean[][][][][][][][] KeepOpeningHand = new boolean[8][8][8][8][8][8][8][8];
- KeepOpeningHand=GiveLooseMulliganStrategy();
- int NumberOfSimulationsPerDeck=2500;
- double TotalManaSpent;
- double MostManaSpent=1;
- int OptimalOneDrops=0;
- int OptimalTwoDrops=0;
- int OptimalThreeDrops=0;
- int OptimalFourDrops=0;
- int OptimalFiveDrops=0;
- int OptimalSixDrops=0;
- int OptimalLands=0;
- int NumberOfCardsInDeck=40;
- //Doing a grid search (increasing each card by 3) to quickly zoom in on, hopefully, the optimal configuration)
- for (int TripleOneDropCount=0; TripleOneDropCount<=10; TripleOneDropCount++){
- for (int TripleTwoDropCount=0; TripleTwoDropCount<=10; TripleTwoDropCount++){
- for (int TripleThreeDropCount=0; TripleThreeDropCount<=7; TripleThreeDropCount++){
- for (int TripleFourDropCount=0; TripleFourDropCount<=4; TripleFourDropCount++){
- for (int TripleFiveDropCount=0; TripleFiveDropCount<=3; TripleFiveDropCount++){
- for (int TripleSixDropCount=0; TripleSixDropCount<=2; TripleSixDropCount++){
- int LandCount=NumberOfCardsInDeck-3*TripleOneDropCount-3*TripleTwoDropCount-3*TripleThreeDropCount-3*TripleFourDropCount-3*TripleFiveDropCount-3*TripleSixDropCount;
- if (LandCount>=13 && LandCount<=32) {
- deck.SetDeck(3*TripleOneDropCount,3*TripleTwoDropCount,3*TripleThreeDropCount,3*TripleFourDropCount,3*TripleFiveDropCount,3*TripleSixDropCount,LandCount);
- deck.PrintDeckBrief();
- TotalManaSpent=AverageManaSpentForRandomHand(deck,7,KeepOpeningHand,NumberOfSimulationsPerDeck);
- System.out.println(" "+TotalManaSpent);
- if (TotalManaSpent>MostManaSpent){
- MostManaSpent=TotalManaSpent;
- OptimalOneDrops=3*TripleOneDropCount;
- OptimalTwoDrops=3*TripleTwoDropCount;
- OptimalThreeDrops=3*TripleThreeDropCount;
- OptimalFourDrops=3*TripleFourDropCount;
- OptimalFiveDrops=3*TripleFiveDropCount;
- OptimalSixDrops=3*TripleSixDropCount;
- OptimalLands=LandCount;
- }
- }
- //Seven drops are no longer considered due to the curse of dimensionality
- }
- }
- }
- }
- }
- }
- System.out.println("----------------");
- System.out.print("The optimal deck after the grid-enumeration at a small number of simulations per deck was:");
- deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalFourDrops,OptimalFiveDrops,OptimalSixDrops,OptimalLands);
- deck.PrintDeckBrief();
- System.out.println();
- System.out.println("The expected mana spent for this deck:"+MostManaSpent);
- System.out.println("----------------");
- NumberOfSimulationsPerDeck=10000;
- int NewOptimalOneDrops=OptimalOneDrops;
- int NewOptimalTwoDrops=OptimalTwoDrops;
- int NewOptimalThreeDrops=OptimalThreeDrops;
- int NewOptimalFourDrops=OptimalFourDrops;
- int NewOptimalFiveDrops=OptimalFiveDrops;
- int NewOptimalSixDrops=OptimalSixDrops;
- int NewOptimalLands=OptimalLands;
- boolean ContinueLocalSearch=true;
- //Doing a local search, starting with the best deck from the previous step, all with a loose mulligan strategy under a reasonable number of simulations per deck
- do {
- MostManaSpent=1;
- for (int OneDropCount=Math.max(0,OptimalOneDrops-2); OneDropCount<=Math.min(NumberOfCardsInDeck,OptimalOneDrops+2); OneDropCount++){
- for (int TwoDropCount=Math.max(0,OptimalTwoDrops-2); TwoDropCount<=Math.min(NumberOfCardsInDeck,OptimalTwoDrops+2); TwoDropCount++){
- for (int ThreeDropCount=Math.max(0,OptimalThreeDrops-2); ThreeDropCount<=Math.min(NumberOfCardsInDeck,OptimalThreeDrops+2); ThreeDropCount++){
- for (int FourDropCount=Math.max(0,OptimalFourDrops-2); FourDropCount<=Math.min(NumberOfCardsInDeck,OptimalFourDrops+2); FourDropCount++){
- for (int FiveDropCount=Math.max(0,OptimalFiveDrops-2); FiveDropCount<=Math.min(NumberOfCardsInDeck,OptimalFiveDrops+2); FiveDropCount++){
- for (int SixDropCount=Math.max(0,OptimalSixDrops-2); SixDropCount<=Math.min(NumberOfCardsInDeck,OptimalSixDrops+2); SixDropCount++){
- int LandCount=NumberOfCardsInDeck-OneDropCount-TwoDropCount-ThreeDropCount-FourDropCount-FiveDropCount-SixDropCount;
- if (LandCount>=Math.max(0,OptimalLands-2) && LandCount<=Math.min(NumberOfCardsInDeck,OptimalLands+2)) {
- deck.SetDeck(OneDropCount,TwoDropCount,ThreeDropCount,FourDropCount,FiveDropCount,SixDropCount,LandCount);
- deck.PrintDeckBrief();
- TotalManaSpent=AverageManaSpentForRandomHand(deck,7,KeepOpeningHand,NumberOfSimulationsPerDeck);
- System.out.println(" "+TotalManaSpent);
- if (TotalManaSpent>MostManaSpent){
- MostManaSpent=TotalManaSpent;
- NewOptimalOneDrops=OneDropCount;
- NewOptimalTwoDrops=TwoDropCount;
- NewOptimalThreeDrops=ThreeDropCount;
- NewOptimalFourDrops=FourDropCount;
- NewOptimalFiveDrops=FiveDropCount;
- NewOptimalSixDrops=SixDropCount;
- OptimalLands=LandCount;
- }
- }
- //Seven drops are no longer considered due to the curse of dimensionality
- }
- }
- }
- }
- }
- }
- if (Math.abs(NewOptimalOneDrops-OptimalOneDrops)+Math.abs(NewOptimalTwoDrops-OptimalTwoDrops)+Math.abs(NewOptimalThreeDrops-OptimalThreeDrops)+Math.abs(NewOptimalFourDrops-OptimalFourDrops)+Math.abs(NewOptimalFiveDrops-OptimalFiveDrops)+Math.abs(NewOptimalSixDrops-OptimalSixDrops)+Math.abs(NewOptimalLands-OptimalLands)<=2) {ContinueLocalSearch=false;}
- OptimalOneDrops=NewOptimalOneDrops;
- OptimalTwoDrops=NewOptimalTwoDrops;
- OptimalThreeDrops=NewOptimalThreeDrops;
- OptimalFourDrops=NewOptimalFourDrops;
- OptimalFiveDrops=NewOptimalFiveDrops;
- OptimalSixDrops=NewOptimalSixDrops;
- OptimalLands=NewOptimalLands;
- System.out.println("----------------");
- System.out.print("The optimal deck after the local search was:");
- deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalFourDrops,OptimalFiveDrops,OptimalSixDrops,OptimalLands);
- deck.PrintDeckBrief();
- System.out.println();
- System.out.println("The expected mana spent for this deck:"+MostManaSpent);
- System.out.println("----------------");
- } while (ContinueLocalSearch);
- NumberOfSimulationsPerDeck=200000;
- ContinueLocalSearch=true;
- //Doing another local search, starting with the best deck from the previous step, but more fine-grained and with the optimal mulligan strategy
- do {
- MostManaSpent=1;
- for (int OneDropCount=Math.max(0,OptimalOneDrops-1); OneDropCount<=Math.min(NumberOfCardsInDeck,OptimalOneDrops+1); OneDropCount++){
- for (int TwoDropCount=Math.max(0,OptimalTwoDrops-1); TwoDropCount<=Math.min(NumberOfCardsInDeck,OptimalTwoDrops+1); TwoDropCount++){
- for (int ThreeDropCount=Math.max(0,OptimalThreeDrops-1); ThreeDropCount<=Math.min(NumberOfCardsInDeck,OptimalThreeDrops+1); ThreeDropCount++){
- for (int FourDropCount=Math.max(0,OptimalFourDrops-1); FourDropCount<=Math.min(NumberOfCardsInDeck,OptimalFourDrops+1); FourDropCount++){
- for (int FiveDropCount=Math.max(0,OptimalFiveDrops-1); FiveDropCount<=Math.min(NumberOfCardsInDeck,OptimalFiveDrops+1); FiveDropCount++){
- for (int SixDropCount=Math.max(0,OptimalSixDrops-1); SixDropCount<=Math.min(NumberOfCardsInDeck,OptimalSixDrops+1); SixDropCount++){
- int LandCount=NumberOfCardsInDeck-OneDropCount-TwoDropCount-ThreeDropCount-FourDropCount-FiveDropCount-SixDropCount;
- if (LandCount>=Math.max(0,OptimalLands-1) && LandCount<=Math.min(NumberOfCardsInDeck,OptimalLands+1)) {
- deck.SetDeck(OneDropCount,TwoDropCount,ThreeDropCount,FourDropCount,FiveDropCount,SixDropCount,LandCount);
- //deck.PrintDeckBrief();
- KeepOpeningHand=GiveOptimalMulliganStrategy(deck);
- TotalManaSpent=AverageManaSpentForRandomHand(deck,7,KeepOpeningHand,NumberOfSimulationsPerDeck);
- //System.out.println(" "+TotalManaSpent);
- if (TotalManaSpent>MostManaSpent){
- MostManaSpent=TotalManaSpent;
- NewOptimalOneDrops=OneDropCount;
- NewOptimalTwoDrops=TwoDropCount;
- NewOptimalThreeDrops=ThreeDropCount;
- NewOptimalFourDrops=FourDropCount;
- NewOptimalFiveDrops=FiveDropCount;
- NewOptimalSixDrops=SixDropCount;
- NewOptimalLands=LandCount;
- }
- }
- }
- }
- }
- }
- }
- System.out.println();
- }
- if (Math.abs(NewOptimalOneDrops-OptimalOneDrops)+Math.abs(NewOptimalTwoDrops-OptimalTwoDrops)+Math.abs(NewOptimalThreeDrops-OptimalThreeDrops)+Math.abs(NewOptimalFourDrops-OptimalFourDrops)+Math.abs(NewOptimalFiveDrops-OptimalFiveDrops)+Math.abs(NewOptimalSixDrops-OptimalSixDrops)+Math.abs(NewOptimalLands-OptimalLands)==0) {ContinueLocalSearch=false;}
- OptimalOneDrops=NewOptimalOneDrops;
- OptimalTwoDrops=NewOptimalTwoDrops;
- OptimalThreeDrops=NewOptimalThreeDrops;
- OptimalFourDrops=NewOptimalFourDrops;
- OptimalFiveDrops=NewOptimalFiveDrops;
- OptimalSixDrops=NewOptimalSixDrops;
- OptimalLands=NewOptimalLands;
- System.out.println("----------------");
- System.out.print("Found a better deck:");
- deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalFourDrops,OptimalFiveDrops,OptimalSixDrops,OptimalLands);
- deck.PrintDeckBrief();
- System.out.println();
- System.out.println("The expected mana spent for this deck:"+MostManaSpent);
- System.out.println("----------------");
- } while (ContinueLocalSearch);
- System.out.println("----------------");
- System.out.print("The final optimal deck:");
- deck.SetDeck(OptimalOneDrops,OptimalTwoDrops,OptimalThreeDrops,OptimalFourDrops,OptimalFiveDrops,OptimalSixDrops,OptimalLands);
- deck.PrintDeckBrief();
- System.out.println();
- System.out.println("The expected mana spent for this deck:"+MostManaSpent);
- System.out.println("----------------");
- }//end of main
- public static boolean[][][][][][][][] GiveOptimalMulliganStrategy(Deck deck) {
- boolean[][][][][][][][] KeepOpeningHand = new boolean[8][8][8][8][8][8][8][8];
- OpeningHand openinghand=new OpeningHand();
- int NumberOfSimulationsPerOpeningHandSize=1000;
- int OriginalNr1Cost=deck.NumberOf1Cost;
- int OriginalNr2Cost=deck.NumberOf2Cost;
- int OriginalNr3Cost=deck.NumberOf3Cost;
- int OriginalNr4Cost=deck.NumberOf4Cost;
- int OriginalNr5Cost=deck.NumberOf5Cost;
- int OriginalNr6Cost=deck.NumberOf6Cost;
- int OriginalNrLands=deck.NumberOfLands;
- double CutOffManaSpent = 1;
- //Let's just keep every 2-card hand. That simplifies things.
- for (int StartingCards=2; StartingCards<=7; StartingCards++){
- //System.out.print(".");
- for (int OneDropCount=0; OneDropCount<=StartingCards; OneDropCount++){
- for (int TwoDropCount=0; TwoDropCount+OneDropCount<=StartingCards; TwoDropCount++){
- for (int ThreeDropCount=0; ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; ThreeDropCount++){
- for (int FourDropCount=0; FourDropCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; FourDropCount++){
- for (int FiveDropCount=0; FiveDropCount+FourDropCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; FiveDropCount++){
- for (int SixDropCount=0; SixDropCount+FiveDropCount+FourDropCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; SixDropCount++){
- int LandCount=StartingCards-OneDropCount-TwoDropCount-ThreeDropCount-FourDropCount-FiveDropCount-SixDropCount;
- if (OneDropCount<=OriginalNr1Cost && TwoDropCount<=OriginalNr2Cost && ThreeDropCount<=OriginalNr3Cost && FourDropCount<=OriginalNr4Cost && FiveDropCount<=OriginalNr5Cost && SixDropCount<=OriginalNr6Cost && LandCount<=OriginalNrLands){
- openinghand.SetHand(OneDropCount, TwoDropCount, ThreeDropCount, FourDropCount, FiveDropCount, SixDropCount, LandCount);
- deck.SetDeck(OriginalNr1Cost,OriginalNr2Cost,OriginalNr3Cost,OriginalNr4Cost,OriginalNr5Cost,OriginalNr6Cost,OriginalNrLands);
- double AvgManaSpent=AverageManaSpentForSpecificHand(deck,openinghand);
- if (AvgManaSpent>CutOffManaSpent) { KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][FourDropCount][FiveDropCount][SixDropCount][LandCount]=true;}
- if (AvgManaSpent<=CutOffManaSpent) { KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][FourDropCount][FiveDropCount][SixDropCount][LandCount]=false;}
- if (StartingCards==2) {KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][FourDropCount][FiveDropCount][SixDropCount][LandCount]=true;}
- }
- }
- }
- }
- }
- }
- }
- deck.SetDeck(OriginalNr1Cost,OriginalNr2Cost,OriginalNr3Cost,OriginalNr4Cost,OriginalNr5Cost,OriginalNr6Cost,OriginalNrLands);
- if (StartingCards<7) {CutOffManaSpent=AverageManaSpentForRandomHand(deck,StartingCards,KeepOpeningHand,NumberOfSimulationsPerOpeningHandSize);}
- }
- return KeepOpeningHand;
- }
- public static boolean[][][][][][][][] GiveLooseMulliganStrategy() {
- boolean[][][][][][][][] KeepOpeningHand = new boolean[8][8][8][8][8][8][8][8];
- for (int StartingCards=2; StartingCards<=7; StartingCards++){
- for (int OneDropCount=0; OneDropCount<=StartingCards; OneDropCount++){
- for (int TwoDropCount=0; TwoDropCount+OneDropCount<=StartingCards; TwoDropCount++){
- for (int ThreeDropCount=0; ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; ThreeDropCount++){
- for (int FourDropCount=0; FourDropCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; FourDropCount++){
- for (int FiveDropCount=0; FiveDropCount+FourDropCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; FiveDropCount++){
- for (int SixDropCount=0; SixDropCount+FiveDropCount+FourDropCount+ThreeDropCount+TwoDropCount+OneDropCount<=StartingCards; SixDropCount++){
- int LandCount=StartingCards-OneDropCount-TwoDropCount-ThreeDropCount-FourDropCount-FiveDropCount-SixDropCount;
- KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][FourDropCount][FiveDropCount][SixDropCount][LandCount]=false;
- //The simple idea is that we're keeping a hand if it contains between 2 and 5 lands and at least one spell of 3 mana or less. Also, keep any 2-card hand.
- if (LandCount>=2 && LandCount<=5 && (OneDropCount+TwoDropCount+ThreeDropCount)>=1) {KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][FourDropCount][FiveDropCount][SixDropCount][LandCount]=true;}
- if (StartingCards<=2) {KeepOpeningHand[StartingCards][OneDropCount][TwoDropCount][ThreeDropCount][FourDropCount][FiveDropCount][SixDropCount][LandCount]=true;}
- }
- }
- }
- }
- }
- }
- }
- return KeepOpeningHand;
- }
- public static double AverageManaSpentForSpecificHand(Deck deck, OpeningHand openinghand){
- int NumberOfIterations=250;
- Deck remainingdeck=new Deck();
- double TotalManaSpent=0;
- for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
- remainingdeck.SetDeck(deck.NumberOf1Cost-openinghand.NumberOf1Cost,deck.NumberOf2Cost-openinghand.NumberOf2Cost,deck.NumberOf3Cost-openinghand.NumberOf3Cost,deck.NumberOf4Cost-openinghand.NumberOf4Cost,deck.NumberOf5Cost-openinghand.NumberOf5Cost,deck.NumberOf6Cost-openinghand.NumberOf6Cost,deck.NumberOfLands-openinghand.NumberOfLands);
- TotalManaSpent=TotalManaSpent+ManaSpent(remainingdeck,openinghand);
- }
- return (TotalManaSpent/(NumberOfIterations+0.0));
- }//end of AverageManaSpentForSpecificHand
- public static double AverageManaSpentForRandomHand(Deck deck, int StartingCards, boolean[][][][][][][][] KeepOpeningHand, int NumberOfIterations){
- Deck remainingdeck=new Deck();
- double TotalManaSpent=0;
- for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
- OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards, KeepOpeningHand);
- remainingdeck.SetDeck(deck.NumberOf1Cost-openinghand.NumberOf1Cost,deck.NumberOf2Cost-openinghand.NumberOf2Cost,deck.NumberOf3Cost-openinghand.NumberOf3Cost,deck.NumberOf4Cost-openinghand.NumberOf4Cost,deck.NumberOf5Cost-openinghand.NumberOf5Cost,deck.NumberOf6Cost-openinghand.NumberOf6Cost,deck.NumberOfLands-openinghand.NumberOfLands);
- TotalManaSpent=TotalManaSpent+ManaSpent(remainingdeck,openinghand);
- if ( IterationCounter % 10000 == 0) {System.out.print(".");}
- }
- return TotalManaSpent/(NumberOfIterations+0.0);
- }//end of AverageManaSpentForRandomHand
- static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards, boolean[][][][][][][][] KeepOpeningHand) {
- Deck remainingdeck=new Deck();
- OpeningHand openinghand=new OpeningHand();
- int TypeOfCardDrawn;
- boolean KeepHand=false;
- for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
- if (KeepHand==false && StartingCards>=OpeningHandSize){
- openinghand.ResetHand();
- remainingdeck.SetDeck(deck.NumberOf1Cost,deck.NumberOf2Cost,deck.NumberOf3Cost,deck.NumberOf4Cost,deck.NumberOf5Cost,deck.NumberOf6Cost,deck.NumberOfLands);
- for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {openinghand.NumberOf1Cost++;}
- if (TypeOfCardDrawn==2) {openinghand.NumberOf2Cost++;}
- if (TypeOfCardDrawn==3) {openinghand.NumberOf3Cost++;}
- if (TypeOfCardDrawn==4) {openinghand.NumberOf4Cost++;}
- if (TypeOfCardDrawn==5) {openinghand.NumberOf5Cost++;}
- if (TypeOfCardDrawn==6) {openinghand.NumberOf6Cost++;}
- if (TypeOfCardDrawn==9) {openinghand.NumberOfLands++;}
- }
- KeepHand=true;
- if (OpeningHandSize>1) {
- if (KeepOpeningHand[OpeningHandSize][openinghand.NumberOf1Cost][openinghand.NumberOf2Cost][openinghand.NumberOf3Cost][openinghand.NumberOf4Cost][openinghand.NumberOf5Cost][openinghand.NumberOf6Cost][openinghand.NumberOfLands]==false) {KeepHand=false;}
- }
- }
- }
- return openinghand;
- }//end of GiveOpeningHandAfterMulls
- static int ManaSpent(Deck remainingdeck, OpeningHand openinghand) {
- int TotalManaSpent=0;
- //Here we put in the speed of the format
- int FinalTurn=7;
- int Turn=0;
- int ManaLeft;
- int TypeOfCardDrawn;
- int LandsInPlay=0;
- /*This is old code when the final turn was random, and we took the average of one turn slower, the expected game-over turn, and one turn faster, which all happen with equal probability
- OpeningHand openinghand=new OpeningHand();
- openinghand.NumberOf1Cost=openinghandOrig.NumberOf1Cost;
- openinghand.NumberOf2Cost=openinghandOrig.NumberOf2Cost;
- openinghand.NumberOf3Cost=openinghandOrig.NumberOf3Cost;
- openinghand.NumberOf4Cost=openinghandOrig.NumberOf4Cost;
- openinghand.NumberOf5Cost=openinghandOrig.NumberOf5Cost;
- openinghand.NumberOf6Cost=openinghandOrig.NumberOf6Cost;
- openinghand.NumberOfLands=openinghandOrig.NumberOfLands;
- Deck remainingdeck=new Deck();
- remainingdeck.NumberOf1Cost=remainingdeckOrig.NumberOf1Cost;
- remainingdeck.NumberOf2Cost=remainingdeckOrig.NumberOf2Cost;
- remainingdeck.NumberOf3Cost=remainingdeckOrig.NumberOf3Cost;
- remainingdeck.NumberOf4Cost=remainingdeckOrig.NumberOf4Cost;
- remainingdeck.NumberOf5Cost=remainingdeckOrig.NumberOf5Cost;
- remainingdeck.NumberOf6Cost=remainingdeckOrig.NumberOf6Cost;
- remainingdeck.NumberOfLands=remainingdeckOrig.NumberOfLands;
- */
- int OneDropsInHand=openinghand.NumberOf1Cost;
- int TwoDropsInHand=openinghand.NumberOf2Cost;
- int ThreeDropsInHand=openinghand.NumberOf3Cost;
- int FourDropsInHand=openinghand.NumberOf4Cost;
- int FiveDropsInHand=openinghand.NumberOf5Cost;
- int SixDropsInHand=openinghand.NumberOf6Cost;
- int LandsInHand=openinghand.NumberOfLands;
- do {
- Turn++;
- if (Turn==1) {
- if (LandsInHand>=1) {LandsInPlay++; LandsInHand--;}
- ManaLeft=LandsInPlay;
- if (OneDropsInHand>=1 && ManaLeft==1) {TotalManaSpent++; ManaLeft--; OneDropsInHand--;}
- //TotalManaSpent=TotalManaSpent+(LandsInPlay-ManaLeft)*0.5;
- } //end of the first turn
- if (Turn>1) {
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {OneDropsInHand++;}
- if (TypeOfCardDrawn==2) {TwoDropsInHand++;}
- if (TypeOfCardDrawn==3) {ThreeDropsInHand++;}
- if (TypeOfCardDrawn==4) {FourDropsInHand++;}
- if (TypeOfCardDrawn==5) {FiveDropsInHand++;}
- if (TypeOfCardDrawn==6) {SixDropsInHand++;}
- if (TypeOfCardDrawn==9) {LandsInHand++;}
- if (LandsInHand>=1) {LandsInPlay++; LandsInHand--;}
- ManaLeft=LandsInPlay;
- int CastableSixDrops=Math.min(SixDropsInHand, ManaLeft/6);
- if (CastableSixDrops>=1) {TotalManaSpent=TotalManaSpent+6*CastableSixDrops; ManaLeft=ManaLeft-6*CastableSixDrops; SixDropsInHand=SixDropsInHand-CastableSixDrops;}
- int CastableFiveDrops=Math.min(FiveDropsInHand, ManaLeft/5);
- if (CastableFiveDrops>=1) {TotalManaSpent=TotalManaSpent+5*CastableFiveDrops; ManaLeft=ManaLeft-5*CastableFiveDrops; FiveDropsInHand=FiveDropsInHand-CastableFiveDrops;}
- int CastableFourDrops=Math.min(FourDropsInHand, ManaLeft/4);
- if (CastableFourDrops>=1) {TotalManaSpent=TotalManaSpent+4*CastableFourDrops; ManaLeft=ManaLeft-4*CastableFourDrops; FourDropsInHand=FourDropsInHand-CastableFourDrops;}
- int CastableThreeDrops=Math.min(ThreeDropsInHand, ManaLeft/3);
- if (CastableThreeDrops>=1) {TotalManaSpent=TotalManaSpent+3*CastableThreeDrops; ManaLeft=ManaLeft-3*CastableThreeDrops; ThreeDropsInHand=ThreeDropsInHand-CastableThreeDrops;}
- int CastableTwoDrops=Math.min(TwoDropsInHand, ManaLeft/2);
- if (CastableTwoDrops>=1) {TotalManaSpent=TotalManaSpent+2*CastableTwoDrops; ManaLeft=ManaLeft-2*CastableTwoDrops; TwoDropsInHand=TwoDropsInHand-CastableTwoDrops;}
- int CastableOneDrops=Math.min(OneDropsInHand, ManaLeft);
- if (CastableOneDrops>=1) {TotalManaSpent=TotalManaSpent+CastableOneDrops; ManaLeft=ManaLeft-CastableOneDrops; OneDropsInHand=OneDropsInHand-CastableOneDrops;}
- } //end of a turn in which we drew a card and attacked
- } while (Turn<FinalTurn);
- return TotalManaSpent;
- }//end of TurnKill
- }//end of OptimalAggroGoldfishDeck
- class OpeningHand {
- int NumberOf1Cost;
- int NumberOf2Cost;
- int NumberOf3Cost;
- int NumberOf4Cost;
- int NumberOf5Cost;
- int NumberOf6Cost;
- int NumberOfLands;
- void ResetHand(){
- NumberOf1Cost=0;
- NumberOf2Cost=0;
- NumberOf3Cost=0;
- NumberOf4Cost=0;
- NumberOf5Cost=0;
- NumberOf6Cost=0;
- NumberOfLands=0;
- }
- void SetHand (int Nr1Cost, int Nr2Cost, int Nr3Cost, int Nr4Cost, int Nr5Cost, int Nr6Cost, int NrLands) {
- NumberOf1Cost=Nr1Cost;
- NumberOf2Cost=Nr2Cost;
- NumberOf3Cost=Nr3Cost;
- NumberOf4Cost=Nr4Cost;
- NumberOf5Cost=Nr5Cost;
- NumberOf6Cost=Nr6Cost;
- NumberOfLands=NrLands;
- }
- }//end of OpeningHand
- class Deck {
- int NumberOf1Cost;
- int NumberOf2Cost;
- int NumberOf3Cost;
- int NumberOf4Cost;
- int NumberOf5Cost;
- int NumberOf6Cost;
- int NumberOfLands;
- void PrintDeckBrief () {
- if(NumberOf1Cost<10) {System.out.print("0");}
- System.out.print(NumberOf1Cost+" ");
- if(NumberOf2Cost<10) {System.out.print("0");}
- System.out.print(NumberOf2Cost+" ");
- if(NumberOf3Cost<10) {System.out.print("0");}
- System.out.print(NumberOf3Cost+" ");
- if(NumberOf4Cost<10) {System.out.print("0");}
- System.out.print(NumberOf4Cost+" ");
- if(NumberOf5Cost<10) {System.out.print("0");}
- System.out.print(NumberOf5Cost+" ");
- if(NumberOf6Cost<10) {System.out.print("0");}
- System.out.print(NumberOf6Cost+" ");
- if(NumberOfLands<10) {System.out.print("0");}
- System.out.print(NumberOfLands);
- System.out.print(" ");
- }
- void SetDeck (int Nr1Cost, int Nr2Cost, int Nr3Cost, int Nr4Cost, int Nr5Cost, int Nr6Cost, int NrLands) {
- NumberOf1Cost=Nr1Cost;
- NumberOf2Cost=Nr2Cost;
- NumberOf3Cost=Nr3Cost;
- NumberOf4Cost=Nr4Cost;
- NumberOf5Cost=Nr5Cost;
- NumberOf6Cost=Nr6Cost;
- NumberOfLands=NrLands;
- }
- int NrOfCards(){
- return NumberOf1Cost+NumberOf2Cost+NumberOf3Cost+NumberOf4Cost+NumberOf5Cost+NumberOf6Cost+NumberOfLands;
- }
- int DrawCard (){
- Random generator = new Random();
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
- int CardType=0;
- int OneCostCutoff=NumberOf1Cost;
- int TwoCostCutoff=OneCostCutoff+NumberOf2Cost;
- int ThreeCostCutoff=TwoCostCutoff+NumberOf3Cost;
- int FourCostCutoff=ThreeCostCutoff+NumberOf4Cost;
- int FiveCostCutoff=FourCostCutoff+NumberOf5Cost;
- int SixCostCutoff=FiveCostCutoff+NumberOf6Cost;
- int LandCutoff=SixCostCutoff+NumberOfLands;
- if (RandomIntegerBetweenOneAndDeckSize<=OneCostCutoff) {CardType=1; this.NumberOf1Cost--;}
- if (RandomIntegerBetweenOneAndDeckSize>OneCostCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCostCutoff) {CardType=2; this.NumberOf2Cost--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwoCostCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCostCutoff) {CardType=3; this.NumberOf3Cost--;}
- if (RandomIntegerBetweenOneAndDeckSize>ThreeCostCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCostCutoff) {CardType=4; this.NumberOf4Cost--;}
- if (RandomIntegerBetweenOneAndDeckSize>FourCostCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCostCutoff) {CardType=5; this.NumberOf5Cost--;}
- if (RandomIntegerBetweenOneAndDeckSize>FiveCostCutoff && RandomIntegerBetweenOneAndDeckSize<=SixCostCutoff) {CardType=6; this.NumberOf6Cost--;}
- if (RandomIntegerBetweenOneAndDeckSize>SixCostCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=9; this.NumberOfLands--;}
- return CardType;
- }
- }//end of Deck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement