frankkarsten

MTG Optimal Deck for Lotus Petal format

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