Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- const int max_xp = 29000;
- const int xp_levels [] = {0, 500, 1100, 1800, 2600, 3500, 4500, 5600, 6800, 8100, 9500,
- 11000, 12600, 14300, 16100, 18000, 20000, 22100, 24300, 26600, 29000};
- // xp(lvl) = 500*lvl + 100 * (lvl * (lvl -1)) / 2
- // const int lev_size = sizeof(xp_levels) / sizeof(int); // 21 , unused
- int get_level_from_xp(int xp) // Uses busection method. Assumes xp >= 0.
- { if (xp >= max_xp)
- return 20;
- int min = 0;
- int max = 19;
- int current = 10;
- while (1)
- { if (xp < xp_levels[current])
- { max = current;
- current = (min + max)/2;
- } else if (xp > xp_levels[current+1])
- { min = current;
- current = (min + max)/2;
- } else
- return current;
- }
- }
- /* Simulation method for judging a dwarf's skill level and rate.
- Simple version of the while loop, without the interpolation.
- Inputs: dwarf's current xp and learning rate for a skill.
- Output: rating based on simulating gaining experience in that skill. In <0, 1>
- */
- double simulate_skill_gain(int xp, int rate)
- { if (xp >= max_xp)
- return 20.0 / 20.0;
- if (rate == 0)
- return get_level_from_xp(xp) / 20.0; // Obviously stays the same.
- int sim_xp = max_xp; // 29k seems like a good value to me.
- sim_xp = (sim_xp / 100.0) * rate; // This is how much XP will go towards skill learning.
- int total_xp = sim_xp;
- double ret = 0.0;
- int curr_level = get_level_from_xp(xp);
- int curr_xp = xp;
- while ((sim_xp > 0) && (curr_level < 20))
- { int xp_gap = xp_levels[curr_level+1] - curr_xp; // How much XP till mext level?
- if (xp_gap > sim_xp)
- xp_gap = sim_xp;
- ret += xp_gap * curr_level;
- curr_level++;
- curr_xp = xp_levels[curr_level];
- sim_xp -= xp_gap;
- }
- if (sim_xp > 0)
- ret += 20 * sim_xp;
- ret /= total_xp;
- ret /= 20.0;
- return ret;
- }
- /* Simulation method for judging a dwarf's skill level and rate.
- This version of the while loop is interpolating the level. It may be smoother.
- Inputs: dwarf's current xp and learning rate for a skill.
- Output: rating based on simulating gaining experience in that skill. in <0, 1>
- */
- double simulate_skill_gain_slopes(int xp, int rate)
- { if (xp >= max_xp)
- return 20.0 / 20.0;
- if (rate == 0)
- return get_level_from_xp(xp) / 20.0; // Obviously stays the same.
- int sim_xp = max_xp; // 29k seems like a good value to me.
- sim_xp = (sim_xp / 100.0) * rate; // This is how much XP will go towards skill learning.
- int total_xp = sim_xp;
- double ret = 0.0;
- int curr_level = get_level_from_xp(xp);
- int curr_xp = xp;
- while ((sim_xp > 0) && (curr_level < 20))
- { int xp_gap = xp_levels[curr_level+1] - curr_xp; // How much XP till mext level?
- if (xp_gap > sim_xp)
- xp_gap = sim_xp;
- double low = (0.0 +curr_xp -xp_levels[curr_level]) / (xp_levels[curr_level+1] -xp_levels[curr_level]);
- double high = (0.0 +curr_xp + xp_gap -xp_levels[curr_level]) / (xp_levels[curr_level+1] -xp_levels[curr_level]);
- double avg_level = curr_level + (low + high) / 2.0; // Average scaled level for this iteration.
- ret += xp_gap * avg_level;
- curr_level++;
- curr_xp = xp_levels[curr_level];
- sim_xp -= xp_gap;
- }
- if (sim_xp > 0)
- ret += 20 * sim_xp;
- ret /= total_xp;
- ret /= 20.0;
- return ret;
- }
- /* An approximate formula to judge how close a dwarf is to legendary +5
- Inputs: dwarf's current xp and learning rate for a skill.
- Output: rating in <0, 1>
- */
- double skill_rate_eval(int xp, int rate)
- { if (xp >= max_xp)
- return 1.0;
- rate = (rate < 1)? 1 : rate; // 0 or 1 doesn't really matter.
- double jobs_left = (29000.0 - xp) / rate; // Ignore division by 60.
- double normalised_XP = 0.5 * (1.0 - jobs_left/290.0); // Scaled to <-49.5, 0.5>
- if (normalised_XP >= 0)
- normalised_XP += 0.5; // Values <0, 0.5> reserved for those suitable for a task.
- else
- normalised_XP = -0.5 / (normalised_XP - 1.0);
- return normalised_XP;
- }
- /* I could add fancy options to use this from command line or reading from a file,
- but that's not really necessary. Just use $ rates <file_in.txt >file_out.txt */
- int main(void)
- { int xp, rate;
- int ret = 2;
- printf("xp, rate, slill_level, sim1, sim2, interp1\n");
- while ((ret = scanf("%d %d", &xp, &rate)) == 2)
- printf("%d, %d, %d, %f, %f, %f\n", xp, rate, get_level_from_xp(xp), simulate_skill_gain(xp, rate), simulate_skill_gain_slopes(xp, rate), skill_rate_eval(xp, rate));
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement