Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package optimalnrtapduals;
- import java.util.Arrays.*;
- import java.util.Random;
- public class OptimalNrTapDuals {
- public static void main(String[] args) {
- Deck deck=new Deck();
- //CardType 1 is Crested Herdcaller: 6 power for 3GG
- //CardType 2 is Wind Strider: 3 power for 4U
- //CardType 3 is Ripjaw Raptor: 4 power for 2GG
- //CardType 4 is Jade Guardian: 3 power for 3G
- //CardType 5 is Deadeye Rig Hauler: 3 power for 3U
- //CardType 6 is Swift Warden: 3 power for 1GG
- //CardType 7 is Jungleborn Pioneer: 3 power for 2G
- //CardType 8 is Watertrap Weaver: 2 power for 2U
- //CardType 9 is Deeproot Warrior: 2 power for 1G
- //CardType 10 is Shaper Apprentice: 2 power for 1U
- //CardType 11 is Jungle Delver: 1 power for G
- //CardType 12 is Mist-Cloaked Herald: 1 power for U
- //And finally we have Forest, Island, and Woodland Stream (U/G tap-dual)
- for (int NrForest=7; NrForest<=11; NrForest++){
- for (int NrIsland=4; NrIsland<=8; NrIsland++){
- if (NrForest+NrIsland>=12 && NrForest+NrIsland<=17){
- deck.SetDeck(1,2,1,2,3,1,4,2,3,2,1,1,NrForest,NrIsland,17-NrForest-NrIsland);
- double ExpKillTurn=Math.round(KillTurnForRandomHand(deck,7,10000000)*10000)/10000.0;
- System.out.println("For the deck with "+NrForest+" Forests, "+NrIsland+" Islands, "+(17-NrForest-NrIsland)+" Duals, the expected kill-turn is: "+ ExpKillTurn);
- }
- }
- }
- }//end of main
- public static double KillTurnForRandomHand(Deck deck, int StartingCards, int NumberOfIterations){
- Deck remainingdeck=new Deck();
- int SumOfKillTurns=0;
- for (int IterationCounter=1; IterationCounter<=NumberOfIterations; IterationCounter++){
- OpeningHand openinghand=GiveOpeningHandAfterMulls(deck, StartingCards);
- 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,deck.NumberOfForest-openinghand.NumberOfForest,deck.NumberOfIsland-openinghand.NumberOfIsland,deck.NumberOfDuals-openinghand.NumberOfDuals);
- SumOfKillTurns=SumOfKillTurns+SimulateGame(remainingdeck,openinghand);
- }
- return SumOfKillTurns/(NumberOfIterations+0.0);
- }//end of AverageKillTurnForRandomHand
- static OpeningHand GiveOpeningHandAfterMulls (Deck deck, int StartingCards) {
- Deck remainingdeck=new Deck();
- OpeningHand openinghand=new OpeningHand();
- int TypeOfCardDrawn;
- boolean KeepHand=false;
- for (int OpeningHandSize=7; OpeningHandSize>=1; OpeningHandSize--){
- if (KeepHand==false){
- int NrLands=0;
- openinghand.SetHand(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
- 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,deck.NumberOfForest-openinghand.NumberOfForest,deck.NumberOfIsland-openinghand.NumberOfIsland,deck.NumberOfDuals-openinghand.NumberOfDuals);
- for (int CardsDrawn=0; CardsDrawn<OpeningHandSize; CardsDrawn++){
- TypeOfCardDrawn=remainingdeck.DrawCard();
- if (TypeOfCardDrawn==1) {openinghand.NumberOfCardType1++;}
- if (TypeOfCardDrawn==2) {openinghand.NumberOfCardType2++;}
- if (TypeOfCardDrawn==3) {openinghand.NumberOfCardType3++;}
- if (TypeOfCardDrawn==4) {openinghand.NumberOfCardType4++;}
- if (TypeOfCardDrawn==5) {openinghand.NumberOfCardType5++;}
- if (TypeOfCardDrawn==6) {openinghand.NumberOfCardType6++;}
- if (TypeOfCardDrawn==7) {openinghand.NumberOfCardType7++;}
- if (TypeOfCardDrawn==8) {openinghand.NumberOfCardType8++;}
- if (TypeOfCardDrawn==9) {openinghand.NumberOfCardType9++;}
- if (TypeOfCardDrawn==10) {openinghand.NumberOfCardType10++;}
- if (TypeOfCardDrawn==11) {openinghand.NumberOfCardType11++;}
- if (TypeOfCardDrawn==12) {openinghand.NumberOfCardType12++;}
- if (TypeOfCardDrawn==20) {openinghand.NumberOfForest++; NrLands++;}
- if (TypeOfCardDrawn==21) {openinghand.NumberOfIsland++; NrLands++;}
- if (TypeOfCardDrawn==22) {openinghand.NumberOfDuals++; NrLands++;}
- }
- //Keep any hand that has 3 or 4 lands with at least one card that can be cast with those lands. Keep any hand that has 5 lands with both colors of mana. Keep any hand with 2 lands with both colors of mana or at least one card that can be cast with those lands. Keep every 4-card opening hand; we have to stop somewhere. Mulligan the rest.
- boolean AtLeastOneCastableSpell=false;
- int NrGreenSources=openinghand.NumberOfDuals+openinghand.NumberOfForest;
- int NrBlueSources=openinghand.NumberOfDuals+openinghand.NumberOfIsland;
- if (openinghand.NumberOfCardType1>=1 && NrGreenSources>=2 && NrLands>=5) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType2>=1 && NrBlueSources>=1 && NrLands>=5) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType3>=1 && NrGreenSources>=2 && NrLands>=4) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType4>=1 && NrGreenSources>=1 && NrLands>=4) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType5>=1 && NrBlueSources>=1 && NrLands>=4) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType6>=1 && NrGreenSources>=2 && NrLands>=3) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType7>=1 && NrGreenSources>=1 && NrLands>=3) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType8>=1 && NrBlueSources>=1 && NrLands>=3) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType9>=1 && NrGreenSources>=1 && NrLands>=2) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType10>=1 && NrBlueSources>=1 && NrLands>=2) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType11>=1 && NrGreenSources>=1 && NrLands>=1) {AtLeastOneCastableSpell=true;}
- if (openinghand.NumberOfCardType12>=1 && NrBlueSources>=1 && NrLands>=1) {AtLeastOneCastableSpell=true;}
- if ( (NrLands==3 || NrLands==4) && AtLeastOneCastableSpell) {KeepHand=true;}
- if (NrLands==5 && NrGreenSources>=1 && NrBlueSources>=1) {KeepHand=true;}
- if (NrLands==2 && ( (NrGreenSources>=1 && NrBlueSources>=1) || AtLeastOneCastableSpell) ) {KeepHand=true;}
- if (OpeningHandSize<=4) {KeepHand=true;}
- }
- }
- return openinghand;
- }//end of GiveOpeningHandAfterMulls
- static int SimulateGame(Deck remainingdeck, OpeningHand openinghand) {
- //Initializing
- int TypeOfCardDrawn=0;
- int Turn=0;
- int OppLife=20;
- int PowerInPlay=0;
- int ForestInPlay=0;
- int IslandInPlay=0;
- int DualInPlay=0;
- int NrCountersThatOurOpponentStillHas=2;
- boolean DebugMode=false;
- //Better late than never: an array to keep track of this nonsense
- int[] CardsInHand = new int[23];
- CardsInHand[1]=openinghand.NumberOfCardType1;
- CardsInHand[2]=openinghand.NumberOfCardType2;
- CardsInHand[3]=openinghand.NumberOfCardType3;
- CardsInHand[4]=openinghand.NumberOfCardType4;
- CardsInHand[5]=openinghand.NumberOfCardType5;
- CardsInHand[6]=openinghand.NumberOfCardType6;
- CardsInHand[7]=openinghand.NumberOfCardType7;
- CardsInHand[8]=openinghand.NumberOfCardType8;
- CardsInHand[9]=openinghand.NumberOfCardType9;
- CardsInHand[10]=openinghand.NumberOfCardType10;
- CardsInHand[11]=openinghand.NumberOfCardType11;
- CardsInHand[12]=openinghand.NumberOfCardType12;
- CardsInHand[20]=openinghand.NumberOfForest;
- CardsInHand[21]=openinghand.NumberOfIsland;
- CardsInHand[22]=openinghand.NumberOfDuals;
- do {
- Turn++;
- //Draw step: Draw a card
- if (Turn>1) {
- TypeOfCardDrawn=remainingdeck.DrawCard();
- CardsInHand[TypeOfCardDrawn]++;
- }
- //Combat step: Attack!
- OppLife=OppLife-PowerInPlay;
- if (DebugMode) {System.out.print("TURN "+ Turn +": Our hand is ");}
- if (CardsInHand[1]>0) {if (DebugMode) {System.out.print(CardsInHand[1]+" 3GG, ");}}
- if (CardsInHand[2]>0) {if (DebugMode) {System.out.print(CardsInHand[2]+" 4U, ");}}
- if (CardsInHand[3]>0) {if (DebugMode) {System.out.print(CardsInHand[3]+" 2GG, ");}}
- if (CardsInHand[4]>0) {if (DebugMode) {System.out.print(CardsInHand[4]+" 3G, ");}}
- if (CardsInHand[5]>0) {if (DebugMode) {System.out.print(CardsInHand[5]+" 3U, ");}}
- if (CardsInHand[6]>0) {if (DebugMode) {System.out.print(CardsInHand[6]+" 1GG, ");}}
- if (CardsInHand[7]>0) {if (DebugMode) {System.out.print(CardsInHand[7]+" 2G, ");}}
- if (CardsInHand[8]>0) {if (DebugMode) {System.out.print(CardsInHand[8]+" 2U, ");}}
- if (CardsInHand[9]>0) {if (DebugMode) {System.out.print(CardsInHand[9]+" 1G, ");}}
- if (CardsInHand[10]>0) {if (DebugMode) {System.out.print(CardsInHand[10]+" 1U, ");}}
- if (CardsInHand[11]>0) {if (DebugMode) {System.out.print(CardsInHand[11]+" G, ");}}
- if (CardsInHand[12]>0) {if (DebugMode) {System.out.print(CardsInHand[12]+" U, ");}}
- if (CardsInHand[20]>0) {if (DebugMode) {System.out.print(" "+CardsInHand[20]+" For");}}
- if (CardsInHand[21]>0) {if (DebugMode) {System.out.print(" "+CardsInHand[21]+" Isl");}}
- if (CardsInHand[22]>0) {if (DebugMode) {System.out.print(" "+CardsInHand[22]+" Dual");}}
- if (DebugMode) {System.out.print(". We own "+ForestInPlay+" For, "+IslandInPlay+" Isl, "+DualInPlay+" Dual, and "+PowerInPlay+" power. Opp at "+OppLife+" and "+ NrCountersThatOurOpponentStillHas+" counters. ");}
- if (DebugMode) {System.out.print("Land drop is ");}
- //Second main phase: Let's figure out which land and spells to play
- LandDropAndPlayRecommendation Recommendation = new LandDropAndPlayRecommendation();
- Recommendation = WhichLandAndSpellsToPlay(CardsInHand, ForestInPlay, IslandInPlay, DualInPlay);
- if (Recommendation.LandTypeDrop==0) {if (DebugMode) {System.out.print("N/A.");}}
- if (Recommendation.LandTypeDrop==1) {ForestInPlay++; CardsInHand[20]--; if (DebugMode) {System.out.print("Forest.");}}
- if (Recommendation.LandTypeDrop==2) {IslandInPlay++; CardsInHand[21]--; if (DebugMode) {System.out.print("Island.");}}
- if (Recommendation.LandTypeDrop==3) {DualInPlay++; CardsInHand[22]--; if (DebugMode) {System.out.print("Dual.");}}
- for (int CardType=1; CardType<=12; CardType++){
- CardsInHand[CardType]=CardsInHand[CardType]-Recommendation.NumberToPlayOfThisCardType[CardType];
- for (int NumberOfCasts=1; NumberOfCasts<=Recommendation.NumberToPlayOfThisCardType[CardType]; NumberOfCasts++){
- if (DebugMode) {
- System.out.print(" We cast");
- if (CardType==1) {System.out.print(" 3GG.");}
- if (CardType==2) {System.out.print(" 4U. ");}
- if (CardType==3) {System.out.print(" 2GG. ");}
- if (CardType==4) {System.out.print(" 3G. ");}
- if (CardType==5) {System.out.print(" 3U. ");}
- if (CardType==6) {System.out.print(" 1GG. ");}
- if (CardType==7) {System.out.print(" 2G. ");}
- if (CardType==8) {System.out.print(" 2U. ");}
- if (CardType==9) {System.out.print(" 1G. ");}
- if (CardType==10) {System.out.print(" 1U. ");}
- if (CardType==11) {System.out.print(" G. ");}
- if (CardType==12) {System.out.print(" U. ");}
- }
- if (NrCountersThatOurOpponentStillHas==0 || TotalCost(CardType)==1) {PowerInPlay=PowerInPlay+Recommendation.NumberToPlayOfThisCardType[CardType]*Power(CardType);}
- if (NrCountersThatOurOpponentStillHas>0 && TotalCost(CardType)>1) {NrCountersThatOurOpponentStillHas--;}
- }
- }
- if (DebugMode) {System.out.println(); }
- } while (OppLife>0);
- return Turn;
- }//end of SimulateGame
- static int GreenCost(int CardType){
- int Outcome=0;
- if (CardType==1) {Outcome=2;}
- if (CardType==2) {Outcome=0;}
- if (CardType==3) {Outcome=2;}
- if (CardType==4) {Outcome=1;}
- if (CardType==5) {Outcome=0;}
- if (CardType==6) {Outcome=2;}
- if (CardType==7) {Outcome=1;}
- if (CardType==8) {Outcome=0;}
- if (CardType==9) {Outcome=1;}
- if (CardType==10) {Outcome=0;}
- if (CardType==11) {Outcome=1;}
- if (CardType==12) {Outcome=0;}
- return Outcome;
- }
- static int BlueCost(int CardType){
- int Outcome=0;
- if (CardType==1) {Outcome=0;}
- if (CardType==2) {Outcome=1;}
- if (CardType==3) {Outcome=0;}
- if (CardType==4) {Outcome=0;}
- if (CardType==5) {Outcome=1;}
- if (CardType==6) {Outcome=0;}
- if (CardType==7) {Outcome=0;}
- if (CardType==8) {Outcome=1;}
- if (CardType==9) {Outcome=0;}
- if (CardType==10) {Outcome=1;}
- if (CardType==11) {Outcome=0;}
- if (CardType==12) {Outcome=1;}
- return Outcome;
- }
- static int TotalCost(int CardType){
- int Outcome=0;
- if (CardType==1) {Outcome=5;}
- if (CardType==2) {Outcome=5;}
- if (CardType==3) {Outcome=4;}
- if (CardType==4) {Outcome=4;}
- if (CardType==5) {Outcome=4;}
- if (CardType==6) {Outcome=3;}
- if (CardType==7) {Outcome=3;}
- if (CardType==8) {Outcome=3;}
- if (CardType==9) {Outcome=2;}
- if (CardType==10) {Outcome=2;}
- if (CardType==11) {Outcome=1;}
- if (CardType==12) {Outcome=1;}
- return Outcome;
- }
- static int Power(int CardType){
- int Outcome=0;
- if (CardType==1) {Outcome=6;}
- if (CardType==2) {Outcome=3;}
- if (CardType==3) {Outcome=4;}
- if (CardType==4) {Outcome=3;}
- if (CardType==5) {Outcome=3;}
- if (CardType==6) {Outcome=3;}
- if (CardType==7) {Outcome=3;}
- if (CardType==8) {Outcome=2;}
- if (CardType==9) {Outcome=2;}
- if (CardType==10) {Outcome=2;}
- if (CardType==11) {Outcome=1;}
- if (CardType==12) {Outcome=1;}
- return Outcome;
- }
- static LandDropAndPlayRecommendation WhichLandAndSpellsToPlay(int[] CardsInHand, int ForestInPlay, int IslandInPlay, int DualInPlay){
- int LandsInHand=CardsInHand[20]+CardsInHand[21]+CardsInHand[22];
- LandDropAndPlayRecommendation Outcome=new LandDropAndPlayRecommendation();
- Outcome.NumberToPlayOfThisCardType=new int[23];
- if (LandsInHand==0) {
- PlayRecommendation WithNoLand=new PlayRecommendation();
- WithNoLand=GiveRecommendation(CardsInHand,ForestInPlay,IslandInPlay,DualInPlay);
- Outcome.LandTypeDrop=0;
- Outcome.NumberToPlayOfThisCardType=WithNoLand.NumberToPlayOfThisCardType;
- }
- if (LandsInHand>=1) {
- int TotalManaSpentWithForest = -1;
- int TotalManaSpentWithIsland = -1;
- int TotalManaSpentWithDual = -1;
- if (CardsInHand[20]>=1){
- PlayRecommendation WithForest=new PlayRecommendation();
- WithForest=GiveRecommendation(CardsInHand,ForestInPlay+1,IslandInPlay,DualInPlay);
- TotalManaSpentWithForest = WithForest.TotalManaSpentThisTurn;
- Outcome.LandTypeDrop=1;
- Outcome.NumberToPlayOfThisCardType=WithForest.NumberToPlayOfThisCardType;
- }
- if (CardsInHand[21]>=1){
- PlayRecommendation WithIsland=new PlayRecommendation();
- WithIsland=GiveRecommendation(CardsInHand,ForestInPlay,IslandInPlay+1,DualInPlay);
- TotalManaSpentWithIsland = WithIsland.TotalManaSpentThisTurn;
- if (TotalManaSpentWithIsland>TotalManaSpentWithForest || (TotalManaSpentWithIsland==TotalManaSpentWithForest && ForestInPlay>IslandInPlay) ) {
- Outcome.LandTypeDrop=2;
- Outcome.NumberToPlayOfThisCardType=WithIsland.NumberToPlayOfThisCardType;
- }
- }
- if (CardsInHand[22]>=1){
- PlayRecommendation WithDual=new PlayRecommendation();
- WithDual=GiveRecommendation(CardsInHand,ForestInPlay,IslandInPlay,DualInPlay);
- TotalManaSpentWithDual = WithDual.TotalManaSpentThisTurn;
- if (TotalManaSpentWithDual>=Math.max(TotalManaSpentWithForest,TotalManaSpentWithIsland)) {
- Outcome.LandTypeDrop=3;
- Outcome.NumberToPlayOfThisCardType=WithDual.NumberToPlayOfThisCardType;
- }
- }
- }
- return Outcome;
- }
- static PlayRecommendation GiveRecommendation(int[] CardsInHand, int ForestInPlay, int IslandInPlay, int DualInPlay){
- PlayRecommendation Outcome = new PlayRecommendation();
- Outcome.NumberToPlayOfThisCardType = new int[23];
- //We'll iterate over all 3-card combinations that we might play and pick the one. In case of a tie, we take the combination that lexicographically minimizes (CardType 1, CardType 2, CardType 3).
- int BestCardType1=0;
- int BestCardType2=0;
- int BestCardType3=0;
- int BestTotalManaSpent=0;
- int GreenManaToPay; int BlueManaToPay; int ColorlessManaToPay; int GreenManaFromForest; int BlueManaFromIsland;
- for (int CardType1=1; CardType1<=12; CardType1++){
- int TappedForest=0;
- int TappedIsland=0;
- int TappedDual=0;
- int AvailableTotalMana=ForestInPlay+IslandInPlay+DualInPlay;
- int AvailableGreenMana=ForestInPlay+DualInPlay;
- int AvailableBlueMana=IslandInPlay+DualInPlay;
- if (CardsInHand[CardType1]>0 && GreenCost(CardType1)<=AvailableGreenMana && BlueCost(CardType1)<=AvailableBlueMana && TotalCost(CardType1)<=AvailableTotalMana) {
- //Start of the auto-tapping mana logic for the first card
- GreenManaToPay=GreenCost(CardType1);
- BlueManaToPay=BlueCost(CardType1);
- ColorlessManaToPay=TotalCost(CardType1)-GreenCost(CardType1)-BlueCost(CardType1);
- GreenManaFromForest=Math.min(GreenManaToPay,ForestInPlay-TappedForest);
- TappedForest=TappedForest+GreenManaFromForest;
- GreenManaToPay=GreenManaToPay-GreenManaFromForest;
- TappedDual=TappedDual+Math.min(GreenManaToPay,DualInPlay-TappedDual);
- BlueManaFromIsland=Math.min(BlueManaToPay,IslandInPlay-TappedIsland);
- TappedIsland=TappedIsland+BlueManaFromIsland;
- BlueManaToPay=BlueManaToPay-BlueManaFromIsland;
- TappedDual=TappedDual+Math.min(BlueManaToPay,DualInPlay-TappedDual);
- do {
- if ( ( (ForestInPlay-TappedForest)==(IslandInPlay-TappedIsland) )&& ColorlessManaToPay>=2 && (ForestInPlay-TappedForest)>0 && (IslandInPlay-TappedIsland)>0) {
- TappedForest++; TappedIsland++;
- ColorlessManaToPay--; ColorlessManaToPay--;
- }
- if ( ( (ForestInPlay-TappedForest)>(IslandInPlay-TappedIsland))&& ColorlessManaToPay>=1 ) {
- TappedForest++;
- ColorlessManaToPay--;
- }
- if ( ( (IslandInPlay-TappedIsland)>(ForestInPlay-TappedForest))&& ColorlessManaToPay>=1 ) {
- TappedIsland++;
- ColorlessManaToPay--;
- }
- if ( ( (ForestInPlay-TappedForest)==(IslandInPlay-TappedIsland) )&& ColorlessManaToPay==1 && (ForestInPlay-TappedForest)>0 && (IslandInPlay-TappedIsland)>0) {
- boolean TapForest=false;
- if (CardsInHand[12]>0) {TapForest=true;}
- if (TapForest) {
- TappedForest++; ColorlessManaToPay--;
- }
- else {
- TappedIsland++; ColorlessManaToPay--;
- }
- }
- if ( ForestInPlay==TappedForest && IslandInPlay==TappedIsland && ColorlessManaToPay>0 ) {
- TappedDual++;
- ColorlessManaToPay--;
- }
- } while (ColorlessManaToPay>0);
- if (TotalCost(CardType1)>BestTotalManaSpent){
- BestTotalManaSpent=TotalCost(CardType1);
- BestCardType1=CardType1;
- }
- //We have now cast the first card
- for (int CardType2=1; CardType2<=12; CardType2++){
- AvailableTotalMana=ForestInPlay-TappedForest+IslandInPlay-TappedIsland+DualInPlay-TappedDual;
- AvailableGreenMana=ForestInPlay-TappedForest+DualInPlay-TappedDual;
- AvailableBlueMana=IslandInPlay-TappedIsland+DualInPlay-TappedDual;
- boolean WeCastASecondSpell=false;
- int NrRemainingCardsOfThisTypeInHand=CardsInHand[CardType2];
- if (CardType2==CardType1) {NrRemainingCardsOfThisTypeInHand--;}
- if (!WeCastASecondSpell && NrRemainingCardsOfThisTypeInHand>0 && GreenCost(CardType2)<=AvailableGreenMana && BlueCost(CardType2)<=AvailableBlueMana && TotalCost(CardType2)<=AvailableTotalMana) {
- //Start of the auto-tapping mana logic for the second card. It's a copy-paste of the same logic as before except now all referring to CardType2
- GreenManaToPay=GreenCost(CardType2);
- BlueManaToPay=BlueCost(CardType2);
- ColorlessManaToPay=TotalCost(CardType2)-GreenCost(CardType2)-BlueCost(CardType2);
- GreenManaFromForest=Math.min(GreenManaToPay,ForestInPlay-TappedForest);
- TappedForest=TappedForest+GreenManaFromForest;
- GreenManaToPay=GreenManaToPay-GreenManaFromForest;
- TappedDual=TappedDual+Math.min(GreenManaToPay,DualInPlay-TappedDual);
- BlueManaFromIsland=Math.min(BlueManaToPay,IslandInPlay-TappedIsland);
- TappedIsland=TappedIsland+BlueManaFromIsland;
- BlueManaToPay=BlueManaToPay-BlueManaFromIsland;
- TappedDual=TappedDual+Math.min(BlueManaToPay,DualInPlay-TappedDual);
- do {
- if ( ( (ForestInPlay-TappedForest)==(IslandInPlay-TappedIsland) )&& ColorlessManaToPay>=2 && (ForestInPlay-TappedForest)>0 && (IslandInPlay-TappedIsland)>0) {
- TappedForest++; TappedIsland++;
- ColorlessManaToPay--; ColorlessManaToPay--;
- }
- if ( ( (ForestInPlay-TappedForest)>(IslandInPlay-TappedIsland))&& ColorlessManaToPay>=1 ) {
- TappedForest++;
- ColorlessManaToPay--;
- }
- if ( ( (IslandInPlay-TappedIsland)>(ForestInPlay-TappedForest))&& ColorlessManaToPay>=1 ) {
- TappedIsland++;
- ColorlessManaToPay--;
- }
- if ( ( (ForestInPlay-TappedForest)==(IslandInPlay-TappedIsland) )&& ColorlessManaToPay==1 && (ForestInPlay-TappedForest)>0 && (IslandInPlay-TappedIsland)>0) {
- boolean TapForest=false;
- if (CardsInHand[12]>0) {TapForest=true;}
- if (TapForest) {
- TappedForest++; ColorlessManaToPay--;
- }
- else {
- TappedIsland++; ColorlessManaToPay--;
- }
- }
- if ( ForestInPlay==TappedForest && IslandInPlay==TappedIsland && ColorlessManaToPay>0 ) {
- TappedDual++;
- ColorlessManaToPay--;
- }
- } while (ColorlessManaToPay>0);
- //We have now cast the second card
- WeCastASecondSpell=true;
- if (TotalCost(CardType1)+TotalCost(CardType2)>BestTotalManaSpent){
- BestTotalManaSpent=TotalCost(CardType1)+TotalCost(CardType2);
- BestCardType1=CardType1;
- BestCardType2=CardType2;
- }
- for (int CardType3=1; CardType3<=12; CardType3++){
- AvailableTotalMana=ForestInPlay-TappedForest+IslandInPlay-TappedIsland+DualInPlay-TappedDual;
- AvailableGreenMana=ForestInPlay-TappedForest+DualInPlay-TappedDual;
- AvailableBlueMana=IslandInPlay-TappedIsland+DualInPlay-TappedDual;
- boolean WeCastAThirdSpell=false;
- int NrRemainingCardsOfThisFinalTypeInHand=CardsInHand[CardType3];
- if (CardType3==CardType1) {NrRemainingCardsOfThisFinalTypeInHand--;}
- if (CardType3==CardType2) {NrRemainingCardsOfThisFinalTypeInHand--;}
- if (!WeCastAThirdSpell && NrRemainingCardsOfThisFinalTypeInHand>0 && GreenCost(CardType3)<=AvailableGreenMana && BlueCost(CardType3)<=AvailableBlueMana && TotalCost(CardType3)<=AvailableTotalMana) {
- //Start of the auto-tapping mana logic for the third card. It's a copy-paste of the same logic as before except now all referring to CardType3
- GreenManaToPay=GreenCost(CardType3);
- BlueManaToPay=BlueCost(CardType3);
- ColorlessManaToPay=TotalCost(CardType3)-GreenCost(CardType3)-BlueCost(CardType3);
- GreenManaFromForest=Math.min(GreenManaToPay,ForestInPlay-TappedForest);
- TappedForest=TappedForest+GreenManaFromForest;
- GreenManaToPay=GreenManaToPay-GreenManaFromForest;
- TappedDual=TappedDual+Math.min(GreenManaToPay,DualInPlay-TappedDual);
- BlueManaFromIsland=Math.min(BlueManaToPay,IslandInPlay-TappedIsland);
- TappedIsland=TappedIsland+BlueManaFromIsland;
- BlueManaToPay=BlueManaToPay-BlueManaFromIsland;
- TappedDual=TappedDual+Math.min(BlueManaToPay,DualInPlay-TappedDual);
- do {
- if ( ( (ForestInPlay-TappedForest)==(IslandInPlay-TappedIsland) )&& ColorlessManaToPay>=2 && (ForestInPlay-TappedForest)>0 && (IslandInPlay-TappedIsland)>0) {
- TappedForest++; TappedIsland++;
- ColorlessManaToPay--; ColorlessManaToPay--;
- }
- if ( ( (ForestInPlay-TappedForest)>(IslandInPlay-TappedIsland))&& ColorlessManaToPay>=1 ) {
- TappedForest++;
- ColorlessManaToPay--;
- }
- if ( ( (IslandInPlay-TappedIsland)>(ForestInPlay-TappedForest))&& ColorlessManaToPay>=1 ) {
- TappedIsland++;
- ColorlessManaToPay--;
- }
- if ( ( (ForestInPlay-TappedForest)==(IslandInPlay-TappedIsland) )&& ColorlessManaToPay==1 && (ForestInPlay-TappedForest)>0 && (IslandInPlay-TappedIsland)>0) {
- boolean TapForest=false;
- if (CardsInHand[12]>0) {TapForest=true;}
- if (TapForest) {
- TappedForest++; ColorlessManaToPay--;
- }
- else {
- TappedIsland++; ColorlessManaToPay--;
- }
- }
- if ( ForestInPlay==TappedForest && IslandInPlay==TappedIsland && ColorlessManaToPay>0 ) {
- TappedDual++;
- ColorlessManaToPay--;
- }
- } while (ColorlessManaToPay>0);
- //We have now cast the third card
- WeCastAThirdSpell=true;
- if (TotalCost(CardType1)+TotalCost(CardType2)+TotalCost(CardType3)>BestTotalManaSpent){
- BestTotalManaSpent=TotalCost(CardType1)+TotalCost(CardType2)+TotalCost(CardType3);
- BestCardType1=CardType1;
- BestCardType2=CardType2;
- BestCardType3=CardType3;
- }
- }
- }
- }
- }
- }
- }
- //We have now determined the combination of at most 3 cards that maximize our mana usage.
- if (BestCardType1>0) {Outcome.NumberToPlayOfThisCardType[BestCardType1]++;}
- if (BestCardType2>0) {Outcome.NumberToPlayOfThisCardType[BestCardType2]++;}
- if (BestCardType3>0) {Outcome.NumberToPlayOfThisCardType[BestCardType3]++;}
- Outcome.TotalManaSpentThisTurn=BestTotalManaSpent;
- return Outcome;
- }
- }
- class PlayRecommendation {
- int[] NumberToPlayOfThisCardType;
- int TotalManaSpentThisTurn;
- }
- class LandDropAndPlayRecommendation {
- int[] NumberToPlayOfThisCardType;
- int LandTypeDrop;
- }
- class OpeningHand {
- int NumberOfCardType1;
- int NumberOfCardType2;
- int NumberOfCardType3;
- int NumberOfCardType4;
- int NumberOfCardType5;
- int NumberOfCardType6;
- int NumberOfCardType7;
- int NumberOfCardType8;
- int NumberOfCardType9;
- int NumberOfCardType10;
- int NumberOfCardType11;
- int NumberOfCardType12;
- int NumberOfForest;
- int NumberOfIsland;
- int NumberOfDuals;
- //I really should've used arrays here, lol
- int NrOfCards(){
- return NumberOfCardType1+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfCardType5+NumberOfCardType6+NumberOfCardType7+NumberOfCardType8+NumberOfCardType9+NumberOfCardType10+NumberOfCardType11+NumberOfCardType12+NumberOfForest+NumberOfIsland+NumberOfDuals;
- }
- 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, int NrForest, int NrIsland, int NrDuals) {
- NumberOfCardType1=Nr1;
- NumberOfCardType2=Nr2;
- NumberOfCardType3=Nr3;
- NumberOfCardType4=Nr4;
- NumberOfCardType5=Nr5;
- NumberOfCardType6=Nr6;
- NumberOfCardType7=Nr7;
- NumberOfCardType8=Nr8;
- NumberOfCardType9=Nr9;
- NumberOfCardType10=Nr10;
- NumberOfCardType11=Nr11;
- NumberOfCardType11=Nr12;
- NumberOfForest=NrForest;
- NumberOfIsland=NrIsland;
- NumberOfDuals=NrDuals;
- }
- }//end of OpeningHand
- class Deck {
- int NumberOfCardType1;
- int NumberOfCardType2;
- int NumberOfCardType3;
- int NumberOfCardType4;
- int NumberOfCardType5;
- int NumberOfCardType6;
- int NumberOfCardType7;
- int NumberOfCardType8;
- int NumberOfCardType9;
- int NumberOfCardType10;
- int NumberOfCardType11;
- int NumberOfCardType12;
- int NumberOfForest;
- int NumberOfIsland;
- int NumberOfDuals;
- //I really should've used arrays here, lol
- 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, int NrForest, int NrIsland, int NrDuals) {
- NumberOfCardType1=Nr1;
- NumberOfCardType2=Nr2;
- NumberOfCardType3=Nr3;
- NumberOfCardType4=Nr4;
- NumberOfCardType5=Nr5;
- NumberOfCardType6=Nr6;
- NumberOfCardType7=Nr7;
- NumberOfCardType8=Nr8;
- NumberOfCardType9=Nr9;
- NumberOfCardType10=Nr10;
- NumberOfCardType11=Nr11;
- NumberOfCardType12=Nr12;
- NumberOfForest=NrForest;
- NumberOfIsland=NrIsland;
- NumberOfDuals=NrDuals;
- }
- int NrOfCards(){
- return NumberOfCardType1+NumberOfCardType2+NumberOfCardType3+NumberOfCardType4+NumberOfCardType5+NumberOfCardType6+NumberOfCardType7+NumberOfCardType8+NumberOfCardType9+NumberOfCardType10+NumberOfCardType11+NumberOfCardType12+NumberOfForest+NumberOfIsland+NumberOfDuals;
- }
- int DrawCard (){
- Random generator = new Random();
- int CardType=0;
- int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NrOfCards() )+1;
- int OneCutoff=NumberOfCardType1;
- int TwoCutoff=OneCutoff+NumberOfCardType2;
- int ThreeCutoff=TwoCutoff+NumberOfCardType3;
- int FourCutoff=ThreeCutoff+NumberOfCardType4;
- int FiveCutoff=FourCutoff+NumberOfCardType5;
- int SixCutoff=FiveCutoff+NumberOfCardType6;
- int SevenCutoff=SixCutoff+NumberOfCardType7;
- int EightCutoff=SevenCutoff+NumberOfCardType8;
- int NineCutoff=EightCutoff+NumberOfCardType9;
- int TenCutoff=NineCutoff+NumberOfCardType10;
- int ElevenCutoff=TenCutoff+NumberOfCardType11;
- int TwelveCutoff=ElevenCutoff+NumberOfCardType12;
- int ForestCutoff=TwelveCutoff+NumberOfForest;
- int IslandCutoff=ForestCutoff+NumberOfIsland;
- int DualCutoff=IslandCutoff+NumberOfDuals;
- if (RandomIntegerBetweenOneAndDeckSize>0 && RandomIntegerBetweenOneAndDeckSize<=OneCutoff) {CardType=1; this.NumberOfCardType1--;}
- if (RandomIntegerBetweenOneAndDeckSize>OneCutoff && RandomIntegerBetweenOneAndDeckSize<=TwoCutoff) {CardType=2; this.NumberOfCardType2--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwoCutoff && RandomIntegerBetweenOneAndDeckSize<=ThreeCutoff) {CardType=3; this.NumberOfCardType3--;}
- if (RandomIntegerBetweenOneAndDeckSize>ThreeCutoff && RandomIntegerBetweenOneAndDeckSize<=FourCutoff) {CardType=4; this.NumberOfCardType4--;}
- if (RandomIntegerBetweenOneAndDeckSize>FourCutoff && RandomIntegerBetweenOneAndDeckSize<=FiveCutoff) {CardType=5; this.NumberOfCardType5--;}
- if (RandomIntegerBetweenOneAndDeckSize>FiveCutoff && RandomIntegerBetweenOneAndDeckSize<=SixCutoff) {CardType=6; this.NumberOfCardType6--;}
- if (RandomIntegerBetweenOneAndDeckSize>SixCutoff && RandomIntegerBetweenOneAndDeckSize<=SevenCutoff) {CardType=7; this.NumberOfCardType7--;}
- if (RandomIntegerBetweenOneAndDeckSize>SevenCutoff && RandomIntegerBetweenOneAndDeckSize<=EightCutoff) {CardType=8; this.NumberOfCardType8--;}
- if (RandomIntegerBetweenOneAndDeckSize>EightCutoff && RandomIntegerBetweenOneAndDeckSize<=NineCutoff) {CardType=9; this.NumberOfCardType9--;}
- if (RandomIntegerBetweenOneAndDeckSize>NineCutoff && RandomIntegerBetweenOneAndDeckSize<=TenCutoff) {CardType=10; this.NumberOfCardType10--;}
- if (RandomIntegerBetweenOneAndDeckSize>TenCutoff && RandomIntegerBetweenOneAndDeckSize<=ElevenCutoff) {CardType=11; this.NumberOfCardType11--;}
- if (RandomIntegerBetweenOneAndDeckSize>ElevenCutoff && RandomIntegerBetweenOneAndDeckSize<=TwelveCutoff) {CardType=12; this.NumberOfCardType12--;}
- if (RandomIntegerBetweenOneAndDeckSize>TwelveCutoff && RandomIntegerBetweenOneAndDeckSize<=ForestCutoff) {CardType=20; this.NumberOfForest--;}
- if (RandomIntegerBetweenOneAndDeckSize>ForestCutoff && RandomIntegerBetweenOneAndDeckSize<=IslandCutoff) {CardType=21; this.NumberOfIsland--;}
- if (RandomIntegerBetweenOneAndDeckSize>IslandCutoff && RandomIntegerBetweenOneAndDeckSize<=DualCutoff) {CardType=22; this.NumberOfDuals--;}
- return CardType;
- }
- }//end of Deck
Add Comment
Please, Sign In to add comment