Advertisement
frankkarsten

MTG Optimal Deck for Big format

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