Advertisement
Guest User

Composing Calculator V 1.0.2.1

a guest
Sep 15th, 2013
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.46 KB | None | 0 0
  1. //#include "stdafx.h"
  2. #include <iostream>
  3. #include <cmath>
  4. #include "stdio.h"
  5. #include <vector>
  6. #include <fstream>
  7.  
  8. class FragmentOptimizationParameters {
  9. public:
  10.     int minLevel;
  11.     int levelDifference;
  12.     FragmentOptimizationParameters(){
  13.         minLevel = 0;
  14.         levelDifference = 20;
  15.     }
  16.     FragmentOptimizationParameters(int _minLevel, int _levelDifference){
  17.         minLevel = _minLevel;
  18.         levelDifference = _levelDifference;
  19.     }
  20. };
  21.  
  22. class FragmentCostParameters {
  23. public:
  24.     double multFactor;
  25.     double subtractFactor;
  26.     FragmentCostParameters(double _multFactor, double _subtractFactor){
  27.         multFactor = _multFactor;
  28.         subtractFactor = _subtractFactor;
  29.     }
  30.     FragmentCostParameters(){
  31.         multFactor = .05;
  32.         subtractFactor = 0;
  33.     }
  34.  
  35. };
  36.  
  37. //function prototypes
  38. //various functions given by HCS
  39. long long int experience(long long int skillLevel, long long int duration);
  40. long long int goldcost (long long int skillLevel, long long int duration);
  41. long long int xpToAdvance (int compLevel);
  42. long long int time (double skillLevel, double duration, double composingLevel);
  43. int FragmentCost(double skillLevel, int duration);
  44.  
  45. //summation formulas
  46. long long int goldcost (long long int skillLevel, long long int duration, long long int potions);
  47. long long int totalGoldSpent (long long int skillLevel, long long int duration, long long int potions);
  48. long long int xpTotal (int compLevel);
  49. void totalFragCost(int skillLevel, int numSkills, int duration);
  50. void regularTotalFragCost(int skillLevel, int duration);
  51.  
  52. //analytics functions
  53. int bestXPGoldRatio (int* maxSkillLevels, int* maxNumSkills, int composingLevel);
  54. void xpInGold ();
  55. void xpInGoldwithFrags ();
  56. void xpInGoldwithFragsv2();
  57. void OptimizedFragCost(int skillLevel, int numSkills, int duration, FragmentOptimizationParameters FOP);
  58. void lowestWeightedFragCost(int skillLevel, int numSkills, int duration);
  59. int OptimizedSkillLevels(int skillLevel, int numSkills, int duration, FragmentOptimizationParameters FOP);
  60.  
  61. using namespace std;
  62.  
  63. //global variables
  64. int userMaxSkillLevel = 0;
  65. int userMaxNumSkills = 0;
  66. static int maxSkillLevels[] = {0,300, 405, 655, 705, 855, 1015};
  67. static int maxNumSkills[]= {0,2,3,4,4,5,6};
  68. static int fragmentGoldCosts[] = {3000,2000,10000,15000,30000,35000};
  69. unsigned int maxCompLevel = 0;
  70. unsigned int composingLevel = 0;
  71.  
  72. //fixing my pointer problems
  73. int totalFragmentCost[7] = {0,0,0,0,0,0,0};
  74. int regularTotalFragmentCost[7] = {0,0,0,0,0,0,0};
  75. int optimizedFragmentUsage[7] = {0,0,0,0,0,0,0};
  76. int lowestWeightedFragmentCost[8] = {0,0,0,0,0,0,0,0};
  77.  
  78. vector<FragmentOptimizationParameters> FOPs;
  79. vector<FragmentCostParameters> FCPs;
  80.  
  81. int main(){
  82.  
  83.     cout << "Composing Calculator v 1.0.2.1" << endl;
  84.     cout << "Functional to level 6 (inclusive). Further data is required for higher levels." << endl << endl;
  85.  
  86.     cout << "Made by aa0007." << endl;
  87.     cout << "Additional thanks to Savanc and Undjuvion for providing data and assistance." << endl << endl;
  88.  
  89.     FOPs.push_back(FragmentOptimizationParameters(0,20));
  90.     FOPs.push_back(FragmentOptimizationParameters(50,20));
  91.     FOPs.push_back(FragmentOptimizationParameters(125,20));
  92.     FOPs.push_back(FragmentOptimizationParameters(175,50));
  93.     FOPs.push_back(FragmentOptimizationParameters(250,50));
  94.     FOPs.push_back(FragmentOptimizationParameters(300,50));
  95.  
  96.     FCPs.push_back(FragmentCostParameters(.05, 0));
  97.     FCPs.push_back(FragmentCostParameters(.05, 50));
  98.     FCPs.push_back(FragmentCostParameters(.05, 125));
  99.     FCPs.push_back(FragmentCostParameters(.02, 175));
  100.     FCPs.push_back(FragmentCostParameters(.02, 250));
  101.     FCPs.push_back(FragmentCostParameters(.02, 300));
  102.  
  103.     maxCompLevel = sizeof(maxSkillLevels)/sizeof(int); 
  104.  
  105.     do{
  106.         cout << "Please enter your composing level: "; 
  107.         cin >> composingLevel;
  108.     } while (composingLevel >=  maxCompLevel || composingLevel < 1);
  109.  
  110.     userMaxNumSkills = maxNumSkills[composingLevel];
  111.     userMaxSkillLevel = maxSkillLevels[composingLevel];
  112.  
  113.     cout << endl;
  114.     cout << "Your max skill level is " << userMaxSkillLevel << endl;
  115.     cout << "Your max num skills is " << userMaxNumSkills << endl;
  116.     cout << endl;
  117.  
  118.     cout << "The current fragment values are as follows: " << endl;
  119.     cout << "Common: " << fragmentGoldCosts[0] << endl;
  120.     cout << "Rare: " << fragmentGoldCosts[1] << endl;
  121.     cout << "Unique: " << fragmentGoldCosts[2] << endl;
  122.     cout << "Legendary: " << fragmentGoldCosts[3] << endl;
  123.     cout << "Crystalline: " << fragmentGoldCosts[4] << endl;
  124.     cout << "Super Elite: " << fragmentGoldCosts[5] << endl;
  125.  
  126.     cout << "Press 'y' to move on or 'n' to change [ADVANCED USERS ONLY]: ";
  127.  
  128.     char temp;
  129.     do {       
  130.         cin >> temp;
  131.         cout << endl;
  132.         if (temp == 'n'){
  133.             cout << "Please enter your desired value: " << endl;
  134.             cout << "Common: "; cin >> fragmentGoldCosts[0];
  135.             cout << "Rare: "; cin >> fragmentGoldCosts[1];
  136.             cout << "Unique: "; cin >> fragmentGoldCosts[2];
  137.             cout << "Legendary: "; cin >> fragmentGoldCosts[3];
  138.             cout << "Crystalline: "; cin >> fragmentGoldCosts[4];
  139.             cout << "Super Elite: "; cin >> fragmentGoldCosts[5];
  140.             cout << "Press 'y' to move on or 'n' to change [ADVANCED USERS ONLY]: ";
  141.         }
  142.     } while (temp != 'y');
  143.  
  144.     temp = 'a';
  145.  
  146.     bestXPGoldRatio(maxSkillLevels, maxNumSkills, composingLevel);
  147.    
  148.     do{
  149.         xpInGoldwithFragsv2(); //gives optimized values
  150.         cout << "Press 'y' to repeat or 'n' to quit" << endl;
  151.         cin >> temp;
  152.     } while (temp == 'y');
  153.    
  154.    
  155.  
  156.    
  157.     //both functions have been rendered useless since they give the same results
  158.     //  xpInGold(); //useful when you've gotten free frags or care more for gold than frags
  159.     //  xpInGoldwithFrags(); //useful everywhere else
  160.  
  161.     //system("PAUSE");
  162.     return 0;
  163. }
  164.  
  165. //total skill leve and duration -> experience
  166. long long int experience (long long int skillLevel, long long int duration){
  167.  
  168.     return (long long int)(ceil((double)min(skillLevel,duration)/60 + (double)skillLevel/500)*10);
  169. }
  170.  
  171. //total skill leve and duration -> gold cost
  172. long long int goldcost (long long int skillLevel,long long int duration){
  173.     return (long long int)((skillLevel*duration)<5000?5000:skillLevel*duration);
  174. }
  175.  
  176. //individual gold cost * 2^n for instant
  177. long long int goldcost (long long int skillLevel, long long int duration, long long int potions){
  178.  
  179.     return (long long int)(goldcost(skillLevel, duration) * pow(2,potions));
  180. }
  181.  
  182. //actual gold cost for making n potions instantly
  183. long long int totalGoldSpent (long long int skillLevel, long long int duration, long long int potions){
  184.  
  185.     long long int totalGold = 0;
  186.  
  187.     for (int i = 0; i < potions; i++){
  188.         totalGold += goldcost(skillLevel, duration, i);
  189.     }
  190.  
  191.     return totalGold;
  192. }
  193.  
  194. //total experience at any level
  195. long long int xpTotal (int compLevel){
  196.     long long int xp = 0;
  197.     while (compLevel > 0){
  198.         xp += (250 + (compLevel-1)*500);
  199.         compLevel--;
  200.     }
  201.     return xp;
  202. }
  203.  
  204. //xp needed to progress to next level
  205. long long int xpToAdvance (int compLevel){
  206.     return (250 + (compLevel-1)*500);
  207. }
  208.  
  209. //time it takes to normal brew a potion
  210. long long int time (double skillLevel, double duration, double composingLevel){
  211.     return (( (max( ((ceil(max(skillLevel,150.0)/20.0)*5) + (ceil(duration/30.0)*30)) - ((composingLevel-1)*5.0), 60.0)) ));
  212. }
  213.  
  214. //shows the best xp/time ratio at all composing levels, prioritizing xp/time then gold cost
  215. int bestXPGoldRatio (int* maxSkillLevels, int* maxNumSkills, int currComposingLevel){
  216.  
  217.     int totalPotsMade = 0;
  218.     int totaltime = 0;
  219.     int composingLevel = 1;
  220.  
  221.     while (composingLevel <= currComposingLevel){
  222.         double maximum=0;
  223.         int mx=0;
  224.         int my=0;
  225.  
  226.         long long int cost = 10000000000;
  227.  
  228.         for(double x=1; x<=maxSkillLevels[composingLevel]; x++)
  229.         {
  230.             for(double y=30; y<=300; y++)
  231.             {
  232.  
  233.                 double d=(ceil(min(x,y)/60.0 + x/500.0) * 10)/(( (max( ((ceil(max(x,150.0)/20.0)*5) + (ceil(y/30.0)*30)) - ((composingLevel-1)*5.0), 60.0)) ));
  234.                 if(d>maximum || d== maximum && goldcost(x,y)<cost)
  235.                 {
  236.                     maximum=d;
  237.                     mx=x;
  238.                     my=y;
  239.                     cost = goldcost(x,y);
  240.                 }
  241.             }
  242.         }
  243.         cout << "Composing: " << composingLevel << ", XP/min: " << maximum << ", Skill: " << mx << ", Dur: " << my << ", Gold: " << cost << ", Pots: " << ceil((double)xpToAdvance(composingLevel)/(double)experience(mx,my)) << endl; 
  244.         totaltime+= time(mx,my,composingLevel)*(ceil((double)xpToAdvance(composingLevel)/(double)experience(mx,my)));
  245.         totalPotsMade+= (ceil((double)xpToAdvance(composingLevel)/(double)experience(mx,my)) );
  246.         composingLevel++;
  247.     }
  248.  
  249.     //cout << endl << "Total Time: " << totaltime << ", Total Potions: " << totalPotsMade << endl;
  250.  
  251.     return 0;
  252. }
  253.  
  254. //most xp in how much gold, not including fragment cost
  255. void xpInGold (){
  256.  
  257.     vector<long long int> optimalCosts;
  258.     vector<long long int> skillLevels;
  259.     vector<long long int> durations;
  260.  
  261.     unsigned int currentSize = 0;
  262.  
  263.     cout << endl;
  264.     cout << "Optimal Potions based on Gold Cost Only" << endl;
  265.  
  266.     for (int i = 1; i <= userMaxSkillLevel; i++){
  267.         for (int j = 30; j <= 300; j++){
  268.  
  269.             long long int currexp = experience(i,j)/10;
  270.  
  271.             if (currexp > optimalCosts.size()){
  272.  
  273.                 optimalCosts.resize(currexp);
  274.                 skillLevels.resize(currexp);
  275.                 durations.resize(currexp);
  276.  
  277.                 for (unsigned int a = currentSize; a < currexp; a++){
  278.                     optimalCosts[a] = 12386124718;
  279.                 }
  280.  
  281.                 currentSize = optimalCosts.size();
  282.  
  283.             }
  284.             if (goldcost(i,j) < optimalCosts[currexp-1]){
  285.                 optimalCosts[currexp-1] = goldcost(i,j);
  286.                 skillLevels[currexp-1] = i;
  287.                 durations[currexp-1] = j;
  288.             }
  289.         }
  290.     }
  291.  
  292.     //prints vector
  293.     for (int i = 0; i < optimalCosts.size(); i++){
  294.         cout << (i+1)*10 << " xp, " << optimalCosts[i]<< " gold, " << skillLevels[i] << " skill levels, " << durations[i] << " minutes" <<  endl;
  295.     }
  296.  
  297.  
  298.  
  299.     long long int gold = 0;
  300.     cout << endl;
  301.     cout << "Please enter the amount of gold you wish to spend: ";
  302.     cin >> gold;
  303.     cout << endl;
  304.  
  305.     long long int potions = 0;
  306.     int xp=0;
  307.     long long int goldSpent = 0;
  308.  
  309.     vector<int> potionsToMake;
  310.     vector<int> bestPotionsToMake;
  311.     int currentexp = 0;
  312.  
  313.     while(optimalCosts.size()>0){
  314.  
  315.         long long int tempgold = gold;
  316.         long long int tempgoldspent = 0;
  317.  
  318.         for (int i = optimalCosts.size()-1; i >=0; i--){
  319.             while (tempgold -optimalCosts[i]*pow(2,potions) >=0){
  320.  
  321.                 tempgold -= optimalCosts[i]*pow(2,potions) + goldcost(skillLevels[i],durations[i]);
  322.                 tempgoldspent += optimalCosts[i]*pow(2,potions) + goldcost(skillLevels[i],durations[i]);
  323.                 potions++;
  324.                 currentexp += i*10+10;
  325.                 potionsToMake.push_back(i*10+10);
  326.             }
  327.         }
  328.         optimalCosts.pop_back();
  329.  
  330.         if (currentexp > xp){
  331.             bestPotionsToMake = potionsToMake;
  332.             xp = currentexp;
  333.             goldSpent = tempgoldspent;
  334.         }
  335.  
  336.         else if (xp == currentexp && tempgoldspent < goldSpent){
  337.             bestPotionsToMake = potionsToMake;
  338.             xp = currentexp;
  339.             goldSpent = tempgoldspent;
  340.         }
  341.  
  342.         tempgoldspent = 0;
  343.         potionsToMake.clear();
  344.         currentexp = 0;
  345.         potions = 0;
  346.     }
  347.  
  348.     for (int i = 0; i < bestPotionsToMake.size(); i++){
  349.         cout << "Potion " << i+1 << ": " << bestPotionsToMake[i] << endl;
  350.     }
  351.  
  352.     cout << endl;
  353.     cout << "Number of Potions to Make: " << bestPotionsToMake.size() << endl;
  354.     cout << "Total XP Gained: " << xp << endl;
  355.     cout << "Total Gold Spent " << goldSpent << endl;
  356.     return;
  357. }
  358.  
  359. void xpInGoldwithFragsv2(){
  360.  
  361.     vector<long long int> optimalCosts;
  362.     vector<long long int> skillLevels;
  363.     vector<long long int> durations;
  364.  
  365.     unsigned int currentSize = 0;
  366.  
  367.     cout << endl;
  368.     cout << "Best way to instant compose with best frag usage" << endl;
  369.  
  370.     for (int i = 1; i <= userMaxSkillLevel; i++){
  371.         for (int j = 30; j <= 300; j++){
  372.  
  373.             long long int currexp = experience(i,j)/10;
  374.  
  375.             if (currexp > optimalCosts.size()){
  376.  
  377.                 optimalCosts.resize(currexp);
  378.                 skillLevels.resize(currexp);
  379.                 durations.resize(currexp);
  380.  
  381.                 for (unsigned int a = currentSize; a < currexp; a++){
  382.                     optimalCosts[a] = 12386124718;
  383.                 }
  384.  
  385.                 currentSize = optimalCosts.size();
  386.  
  387.             }
  388.             if (goldcost(i,j) < optimalCosts[currexp-1]){
  389.                 optimalCosts[currexp-1] = goldcost(i,j);
  390.                 skillLevels[currexp-1] = i;
  391.                 durations[currexp-1] = j;
  392.             }
  393.         }
  394.     }
  395.  
  396.     for (int i = 0; i < optimalCosts.size(); i++){
  397.         cout << (i+1)*10 << " xp, Fragments: ";
  398.         for (int j = 0; j < 7; j++){
  399.             lowestWeightedFragCost(skillLevels[i], userMaxNumSkills, durations[i]);
  400.             cout << lowestWeightedFragmentCost[j+1]<< ", ";
  401.         }
  402.         cout << optimalCosts[i]<< " Gold, " << skillLevels[i] << " Level, " << durations[i] << " Min, " <<  endl;
  403.         cout << "       Potion Levels: ";
  404.         lowestWeightedFragCost(skillLevels[i], userMaxNumSkills, durations[i]);
  405.         OptimizedSkillLevels(skillLevels[i], userMaxNumSkills, durations[i], FOPs[lowestWeightedFragmentCost[0]]);
  406.         cout << endl << endl;
  407.     }
  408.  
  409.     long long int gold = 0;
  410.     cout << endl;
  411.     cout << "Please enter the amount of gold you wish to spend: ";
  412.     cin >> gold;
  413.     cout << endl;
  414.  
  415.     long long int potions = 0;
  416.     int xp=0;
  417.     long long int goldSpent = 0;
  418.  
  419.  
  420.     //figure out which are the best potions to make based on the gold cost, don't need to worry about fragments
  421.     vector<int> potionsToMake;
  422.     vector<int> bestPotionsToMake;
  423.     int currentexp = 0;
  424.  
  425.     while(optimalCosts.size()>0){
  426.  
  427.         long long int tempgold = gold;
  428.         long long int tempgoldspent = 0;
  429.  
  430.         for (int i = optimalCosts.size()-1; i >=0; i--){
  431.             while (tempgold -optimalCosts[i]*pow(2,potions) >=0){
  432.  
  433.                 tempgold -= optimalCosts[i]*pow(2,potions) + goldcost(skillLevels[i],durations[i]);
  434.                 tempgoldspent += optimalCosts[i]*pow(2,potions) + goldcost(skillLevels[i],durations[i]);
  435.                 potions++;
  436.                 currentexp += i*10+10;
  437.                 potionsToMake.push_back(i*10+10);
  438.             }
  439.         }
  440.         optimalCosts.pop_back();
  441.  
  442.         if (currentexp > xp){
  443.             bestPotionsToMake = potionsToMake;
  444.             xp = currentexp;
  445.             goldSpent = tempgoldspent;
  446.         }
  447.  
  448.         else if (xp == currentexp && tempgoldspent < goldSpent){
  449.             bestPotionsToMake = potionsToMake;
  450.             xp = currentexp;
  451.             goldSpent = tempgoldspent;
  452.         }
  453.  
  454.         tempgoldspent = 0;
  455.         potionsToMake.clear();
  456.         currentexp = 0;
  457.         potions = 0;
  458.     }
  459.  
  460.     int frags[] = {0,0,0,0,0,0,0};
  461.  
  462.     for (int i = 0; i < bestPotionsToMake.size(); i++){
  463.         for (int j = 0; j < sizeof(frags)/sizeof(int); j++){
  464.             lowestWeightedFragCost(skillLevels[(bestPotionsToMake[i]-10)/10], userMaxNumSkills, durations[(bestPotionsToMake[i]-10)/10]);
  465.             frags[j] += lowestWeightedFragmentCost[j+1];
  466.         }
  467.     }
  468.  
  469.     for (int i = 0; i < bestPotionsToMake.size(); i++){
  470.         cout << "Potion " << i+1 << ": " << bestPotionsToMake[i] << endl;
  471.     }
  472.  
  473.     cout << endl;
  474.     cout << "Number of Potions to Make: " << bestPotionsToMake.size() << endl;
  475.     cout << "Total XP Gained: " << xp << endl;
  476.     cout << "Total Gold Spent: " << goldSpent << endl;
  477.     cout << "Total Fragments Used: " << frags[0] << endl;
  478.     cout << "Total Common Fragments Used: " << frags[1] << endl;
  479.     cout << "Total Rare Fragments Used: " << frags[2] << endl;
  480.     cout << "Total Unique Fragments Used: " << frags[3] << endl;
  481.     cout << "Total Legendary Fragments Used: " << frags[4] << endl;
  482.     cout << "Total Crystalline Fragments Used: " << frags[5] << endl;
  483.     cout << "Total Super Elite Fragments Used: " << frags[6] << endl;
  484.  
  485.     cout << endl;
  486.     return;
  487. }
  488.  
  489. //best XP considering fragments
  490. void xpInGoldwithFrags (){
  491.     unsigned int skillMax = userMaxSkillLevel;
  492.     unsigned int skillNumMax = userMaxNumSkills;
  493.  
  494.     vector<long long int> optimalCosts;
  495.     vector<long long int> optimalFragCosts;
  496.     vector<long long int> skillLevels;
  497.     vector<long long int> durations;
  498.  
  499.     unsigned int currentSize = 0;
  500.  
  501.     cout << endl;
  502.     cout << "Optimal Potions with Best Gold and Fragment Usage" << endl;
  503.     cout << endl;
  504.  
  505.     for (int i = 1; i <= skillMax; i++){
  506.         for (int j = 30; j <= 300; j++){ //through duration
  507.  
  508.             long long int currexp = experience(i,j)/10;
  509.  
  510.             if (currexp > optimalCosts.size()){
  511.  
  512.                 optimalFragCosts.resize(currexp);
  513.                 optimalCosts.resize(currexp);
  514.                 skillLevels.resize(currexp);
  515.                 durations.resize(currexp);
  516.  
  517.                 for (unsigned int a = currentSize; a < currexp; a++){
  518.                     optimalFragCosts[a] = 12386124718;
  519.                 }
  520.  
  521.                 currentSize = optimalFragCosts.size();
  522.             }
  523.             lowestWeightedFragCost(i,skillNumMax, j);
  524.             if (lowestWeightedFragmentCost[0] < optimalFragCosts[currexp-1]){
  525.                 optimalFragCosts[currexp-1] = lowestWeightedFragmentCost[0];
  526.                 optimalCosts[currexp-1] = goldcost(i,j);
  527.                 skillLevels[currexp-1] = i;
  528.                 durations[currexp-1] = j;
  529.             }
  530.         }
  531.     }
  532.  
  533.     //prints vector
  534.     for (int i = 0; i < optimalFragCosts.size(); i++){
  535.         cout << (i+1)*10 << " xp, Fragments: ";
  536.         for (int j = 0; j < 7; j++){
  537.             lowestWeightedFragCost(skillLevels[i], skillNumMax, durations[i]);
  538.             cout << lowestWeightedFragmentCost[j+1]<< ", ";
  539.         }
  540.         cout << optimalCosts[i]<< " gold, " << skillLevels[i] << " levels, " << durations[i] << " min" <<  endl;
  541.     }
  542.  
  543.     long long int gold = 0;
  544.     cout << endl;
  545.     cout << "Please enter the amount of gold you wish to spend: ";
  546.     cin >> gold;
  547.     cout << endl;
  548.  
  549.     long long int potions = 0;
  550.     int xp=0;
  551.     long long int goldSpent = 0;
  552.     int tempfrags[7] = {0,0,0,0,0,0,0};
  553.     int frags[7] = {0,0,0,0,0,0,0};
  554.  
  555.     vector<int> potionsToMake;
  556.     vector<int> bestPotionsToMake;
  557.     int currentexp = 0;
  558.  
  559.     while(optimalCosts.size()>0){
  560.  
  561.         long long int tempgold = gold;
  562.         long long int tempgoldspent = 0;
  563.  
  564.         for (int i = optimalCosts.size()-1; i >=0; i--){
  565.             while (tempgold -(optimalCosts[i]*pow(2,potions) +goldcost(skillLevels[i],durations[i])) >=0){
  566.  
  567.                 tempgold -= (optimalCosts[i]*pow(2,potions) + goldcost(skillLevels[i],durations[i]));
  568.                 tempgoldspent += (optimalCosts[i]*pow(2,potions) + goldcost(skillLevels[i],durations[i]));
  569.                 potions++;
  570.                 currentexp += i*10+10;
  571.                 potionsToMake.push_back(i*10+10);
  572.                 for (int q = 0; q < 7; q++){
  573.                     totalFragCost(skillLevels[i], skillNumMax, durations[i]);
  574.                     tempfrags[q] += totalFragmentCost[q];
  575.                 }
  576.             }
  577.         }
  578.         optimalCosts.pop_back();
  579.  
  580.         if (currentexp > xp){
  581.             bestPotionsToMake = potionsToMake;
  582.             xp = currentexp;
  583.             goldSpent = tempgoldspent;
  584.             for (int q = 0; q < 7; q++){
  585.                 frags[q] = tempfrags[q];
  586.             }
  587.         }
  588.  
  589.         else if (xp == currentexp && tempgoldspent < goldSpent){
  590.             bestPotionsToMake = potionsToMake;
  591.             xp = currentexp;
  592.             goldSpent = tempgoldspent;
  593.             for (int q = 0; q < 7; q++){
  594.                 frags[q] = tempfrags[q];
  595.             }
  596.         }
  597.  
  598.         tempgoldspent = 0;
  599.         potionsToMake.clear();
  600.         currentexp = 0;
  601.         potions = 0;
  602.         for (int q = 0; q < 7; q++){
  603.             tempfrags[q] = 0;
  604.         }
  605.     }
  606.  
  607.     for (int i = 0; i < bestPotionsToMake.size(); i++){
  608.         cout << "Potion " << i << ": " << bestPotionsToMake[i] << endl;
  609.     }
  610.  
  611.     cout << endl;
  612.     cout << "Number of Potions to Make: " << bestPotionsToMake.size() << endl;
  613.     cout << "Total XP Gained: " << xp << endl;
  614.     cout << "Total Gold Spent: " << goldSpent << endl;
  615.     cout << "Total Fragments Used: " << frags[0] << endl;
  616.     cout << "Total Common Fragments Used: " << frags[1] << endl;
  617.     cout << "Total Rare Fragments Used: " << frags[2] << endl;
  618.     cout << "Total Unique Fragments Used: " << frags[3] << endl;
  619.     cout << "Total Legendary Fragments Used: " << frags[4] << endl;
  620.     cout << "Total Crystalline Fragments Used: " << frags[5] << endl;
  621.     cout << "Total Super Elite Fragments Used: " << frags[6] << endl;
  622.  
  623.     cout << endl;
  624.  
  625.     return;
  626. }
  627.  
  628. //fragment cost based on which parameters you use
  629. int FragmentCost(double skillLevel, int duration, FragmentCostParameters FCP){
  630.     return max((int)(ceil(FCP.multFactor*(skillLevel-FCP.subtractFactor))*ceil(duration/30.0)) , 0);
  631. }
  632.  
  633. //total frag cost assuming that each skill is divided evenly. NOT the most efficient skill max.
  634. void totalFragCost(int skillLevel, int numSkills, int duration){
  635.     for (int i = 0; i < 7 ; i++){
  636.         totalFragmentCost[i] = 0;
  637.     }
  638.  
  639.     while (skillLevel > 0 && numSkills > 0){
  640.         int tempSkill = ceil((double)skillLevel/(double)numSkills);
  641.         totalFragmentCost[0]+= FragmentCost(tempSkill,duration, FCPs[0]);
  642.         totalFragmentCost[1]+= FragmentCost(tempSkill,duration, FCPs[0]);
  643.         totalFragmentCost[0]+= FragmentCost(tempSkill,duration, FCPs[1]);
  644.         totalFragmentCost[2]+= FragmentCost(tempSkill,duration, FCPs[1]);
  645.         totalFragmentCost[0]+= FragmentCost(tempSkill,duration, FCPs[2]);
  646.         totalFragmentCost[3]+= FragmentCost(tempSkill,duration, FCPs[2]);
  647.         totalFragmentCost[0]+= FragmentCost(tempSkill,duration, FCPs[3]);
  648.         totalFragmentCost[4]+= FragmentCost(tempSkill,duration, FCPs[3]);
  649.         totalFragmentCost[0]+= FragmentCost(tempSkill,duration, FCPs[4]);
  650.         totalFragmentCost[5]+= FragmentCost(tempSkill,duration, FCPs[4]);
  651.         totalFragmentCost[0]+= FragmentCost(tempSkill,duration, FCPs[5]);  
  652.         totalFragmentCost[6]+= FragmentCost(tempSkill,duration, FCPs[5]);
  653.         skillLevel -= ceil((double)skillLevel/(double)numSkills);
  654.         numSkills--;
  655.     }
  656.     return;
  657. }
  658.  
  659. //given a skill level + duration, will return an array with the fragment usage
  660. void regularTotalFragCost(int skillLevel, int duration){
  661.  
  662.     for (int i = 0; i < 7; i++){
  663.         regularTotalFragmentCost[i] = 0;
  664.     }
  665.     regularTotalFragmentCost[0]+= FragmentCost(skillLevel,duration, FCPs[0]);
  666.     regularTotalFragmentCost[1]+= FragmentCost(skillLevel,duration, FCPs[0]);
  667.     regularTotalFragmentCost[0]+= FragmentCost(skillLevel,duration, FCPs[1]);
  668.     regularTotalFragmentCost[2]+= FragmentCost(skillLevel,duration, FCPs[1]);
  669.     regularTotalFragmentCost[0]+= FragmentCost(skillLevel,duration, FCPs[2]);
  670.     regularTotalFragmentCost[3]+= FragmentCost(skillLevel,duration, FCPs[2]);
  671.     regularTotalFragmentCost[0]+= FragmentCost(skillLevel,duration, FCPs[3]);
  672.     regularTotalFragmentCost[4]+= FragmentCost(skillLevel,duration, FCPs[3]);
  673.     regularTotalFragmentCost[0]+= FragmentCost(skillLevel,duration, FCPs[4]);
  674.     regularTotalFragmentCost[5]+= FragmentCost(skillLevel,duration, FCPs[4]);
  675.     regularTotalFragmentCost[0]+= FragmentCost(skillLevel,duration, FCPs[5]);  
  676.     regularTotalFragmentCost[6]+= FragmentCost(skillLevel,duration, FCPs[5]);
  677.     return;
  678. }
  679.  
  680. //optimizes for a single fragment tier
  681. void OptimizedFragCost(int skillLevel, int numSkills, int duration, FragmentOptimizationParameters FOP){
  682.    
  683.     for (int i = 0; i < 7; i++){
  684.         optimizedFragmentUsage[i] = 0;
  685.     }
  686.  
  687.     vector<int> fragCutoffs;
  688.     int increment = 1;
  689.     int tempSkillLevel = skillLevel;
  690.     while (tempSkillLevel>FOP.minLevel){
  691.         fragCutoffs.push_back(increment*20 + FOP.minLevel);
  692.         increment++;
  693.         tempSkillLevel-= 20;
  694.     }
  695.     if (fragCutoffs.size() > 0)
  696.         fragCutoffs.pop_back();
  697.  
  698.     vector<int> skills(numSkills); //can't have more skills than the max num of skills
  699.     if (fragCutoffs.size() == 0){
  700.         skills.clear();
  701.         skills.push_back(skillLevel);
  702.     }
  703.  
  704.     else {
  705.         int highestSkillLevel = FOP.minLevel;
  706.         double average = (double)skillLevel/(double)numSkills;
  707.         for (int i = fragCutoffs.size()-1; i >= 0; i--){
  708.             if (fragCutoffs[i] <= average){
  709.                 highestSkillLevel = fragCutoffs[i];
  710.                 break;
  711.             }
  712.         }
  713.         int j = 0;
  714.         int skillsdone = 0;
  715.         while (skillLevel > highestSkillLevel&& skillsdone < numSkills){
  716.             if (highestSkillLevel < skillLevel){
  717.                 skills[j] = highestSkillLevel;     
  718.                 skillLevel-= highestSkillLevel;
  719.                 skillsdone++;
  720.             }              
  721.             j++;
  722.         }
  723.  
  724.         //just adds the remainder to the last skill
  725.         int skillIncrement = 0;
  726.         while (skillLevel > FOP.levelDifference){
  727.             skills[skillIncrement%numSkills] += FOP.levelDifference;
  728.             skillLevel-= FOP.levelDifference;
  729.             skillIncrement++;
  730.         }
  731.         skills[skills.size()-1] += skillLevel;
  732.     }
  733.  
  734.     for (int i = 0; i < skills.size(); i++){
  735.         for (int j = 0; j < 7; j++){
  736.             regularTotalFragCost(skills[i], duration);
  737.             optimizedFragmentUsage[j] += regularTotalFragmentCost[j];
  738.         }
  739.     }
  740.  
  741.     return;
  742. }
  743.  
  744. //finally got it working
  745. int OptimizedSkillLevels(int skillLevel, int numSkills, int duration, FragmentOptimizationParameters FOP){
  746.     vector<int> fragCutoffs;
  747.     int increment = 1;
  748.     int tempSkillLevel = skillLevel;
  749.     while (tempSkillLevel>FOP.minLevel){
  750.         fragCutoffs.push_back(increment*20 + FOP.minLevel);
  751.         increment++;
  752.         tempSkillLevel-= 20;
  753.     }
  754.     if (fragCutoffs.size() > 0)
  755.         fragCutoffs.pop_back();
  756.  
  757.     vector<int> skills(numSkills); //can't have more skills than the max num of skills
  758.     if (fragCutoffs.size() == 0){
  759.         skills.clear();
  760.         skills.push_back(skillLevel);
  761.     }
  762.  
  763.     else {
  764.         int highestSkillLevel = FOP.minLevel;
  765.         double average = (double)skillLevel/(double)numSkills;
  766.         for (int i = fragCutoffs.size()-1; i >= 0; i--){
  767.             if (fragCutoffs[i] <= average){
  768.                 highestSkillLevel = fragCutoffs[i];
  769.                 break;
  770.             }
  771.         }
  772.         int j = 0;
  773.         int skillsdone = 0;
  774.         while (skillLevel > highestSkillLevel&& skillsdone < numSkills){
  775.             if (highestSkillLevel < skillLevel){
  776.                 skills[j] = highestSkillLevel;     
  777.                 skillLevel-= highestSkillLevel;
  778.                 skillsdone++;
  779.             }              
  780.             j++;
  781.         }
  782.  
  783.         //just adds the remainder to the last skill
  784.         int skillIncrement = 0;
  785.         while (skillLevel > FOP.levelDifference){
  786.             skills[skillIncrement%numSkills] += FOP.levelDifference;
  787.             skillLevel-= FOP.levelDifference;
  788.             skillIncrement++;
  789.         }
  790.         skills[skills.size()-1] += skillLevel;
  791.     }
  792.  
  793.     for (int i = 0; i < skills.size(); i++){
  794.         cout << skills[i] << ", ";
  795.     }
  796.  
  797.     return 0;
  798. }
  799.  
  800. //finds the lowest gold cost of all of the fragment optimizations
  801. void lowestWeightedFragCost(int skillLevel, int numSkills, int duration){
  802.  
  803.     for (int i = 0; i < 8; i++){
  804.         lowestWeightedFragmentCost[i] = 0;
  805.     }
  806.  
  807.     int tempGoldCost = 0;
  808.     int leastGoldCost = 999999999;
  809.     int leastGoldCostIndex = 10;
  810.  
  811.     for (int i = 0; i < FOPs.size(); i++){
  812.         for (int j = 0; j < 6; j++){
  813.             OptimizedFragCost(skillLevel, numSkills, duration, FOPs[i]);
  814.             tempGoldCost += optimizedFragmentUsage[j+1]*fragmentGoldCosts[j];
  815.         }
  816.  
  817.         if (tempGoldCost < leastGoldCost){
  818.             leastGoldCost = tempGoldCost;
  819.             leastGoldCostIndex = i;
  820.         }
  821.     }
  822.  
  823.     lowestWeightedFragmentCost[0] = leastGoldCostIndex;
  824.     for (int i = 0; i < sizeof(lowestWeightedFragmentCost)/sizeof(int) - 1; i++){
  825.         OptimizedFragCost(skillLevel, numSkills, duration, FOPs[leastGoldCostIndex]);
  826.         lowestWeightedFragmentCost[i+1] = optimizedFragmentUsage[i];
  827.     }
  828.  
  829.     return;
  830. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement