Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fearme;
- public final class RuneScape {
- private static void combat(final double[] health, final double oaccuracy, final double obase_damage) {
- for (int i = 1; i < health.length; i++) {
- for (int j = 1; j < obase_damage; j++) {
- if (i - j >= 0) {
- health[i + j] += oaccuracy * health[j] / obase_damage;
- } else {
- health[0] += oaccuracy * health[j] / obase_damage;
- }
- health[j] *= 1 - oaccuracy;
- health[j] += oaccuracy * health[j] / obase_damage;
- }
- }
- }
- private static void statistics(double p, double win, double loss, final double[] health, final double[] ohealth) {
- double temp = 1 - (1 - health[0]) * (1 - ohealth[0]);
- temp -= p;
- if (health[0] > 0 || ohealth[0] > 0) {
- win += temp * (ohealth[0] / (ohealth[0] + health[0]));
- loss += temp * (health[0] / (ohealth[0] + health[0]));
- }
- p += temp;
- }
- private static void create_health(final double[] health, final double constitution) {
- for (int i = 0; i < constitution * 10; i++) {
- health[i] = 0;
- }
- health[health.length - 1] = 1;
- }
- public static void main(final String[] args) {
- // you
- final double attack = 99;
- final double strength = 99;
- final double defence = 99;
- final double constitution = 99;
- // opponent
- final double oattack = 99;
- final double ostrength = 99;
- final double odefence = 99;
- final double oconstitution = 99;
- final double effective_attack = 10 * (attack + 8 + 3); // 5/8 from standard formula, 3 from style bonus
- final double effective_strength = strength + 8;
- final double base_damage = effective_strength + 5;
- final double effective_defence = 10 * (defence + 8);
- final double oeffective_attack = 10 * (oattack + 8 + 3);
- final double oeffective_strength = ostrength + 8;
- final double obase_damage = oeffective_strength + 5;
- final double oeffective_defence = 10 * (odefence + 8);
- double accuracy;
- double oaccuracy;
- if (attack < odefence) {
- accuracy = (effective_attack - 1) / (2 * oeffective_defence);
- } else {
- accuracy = 1 - (oeffective_defence + 1) / (2 * effective_attack);
- }
- if (oattack < defence) {
- oaccuracy = (oeffective_attack - 1) / (2 * effective_defence);
- } else {
- oaccuracy = 1 - (effective_defence + 1) / (2 * oeffective_attack);
- }
- System.out.println("Your accuarcy: " + accuracy);
- System.out.println("Opponnent's accuracy: " + oaccuracy);
- final double[] health = new double[(int) (constitution * 10)];
- final double[] ohealth = new double[(int) (oconstitution * 10)];
- create_health(health, constitution);
- create_health(ohealth, oconstitution);
- final double p = 0;
- final double win = 0;
- final double loss = 0;
- for (int hit = 0; win + loss < 0.99 && hit < 1000; hit++) {
- combat(health, oaccuracy, obase_damage);
- combat(ohealth, accuracy, base_damage);
- statistics(p, win, loss, health, ohealth);
- }
- System.out.println("Your win chance: " + win);
- System.out.println("Opponent's win cahnce: " + loss);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement