frankkarsten

MTG Optimal Deck for combo format

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