Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Iterator;
- /**
- * Created by Gareth Lloyd on 24/02/15.
- *
- * based on work by Cook Me Plox
- *
- * uses PermIterator from http://stackoverflow.com/questions/2000048/stepping-through-all-permutations-one-swap-at-a-time/11916946#11916946
- */
- public class RevolutionOpt {
- //all abilities to be considered for the bar
- public static Ability[] abilities;
- //maximum number of iterations - permuations is O(n!), so this stops it going for far too long if considering larger n
- // if n! > MAX_ITER, you can run a few times, reordering the abilities array each time
- public static int MAX_ITER = 500000;
- //number of ticks to run the simulated revobar for
- // 100 ticks per minute
- public static int TICKS = 6000;
- public static void main(String[] args) {
- double max = 0;
- //define all abilities to be considered
- Ability[] l = {
- //attack
- new Ability("Slice",5,3,0.7),//1.10*0.6),
- //new Ability("Havoc",17,3,1.25*0.6), //dw
- new Ability("Backhand",25,3,1*0.6), //no kick included
- //new Ability("Smash",17,3,1.25*0.6), //2h
- //new Ability("Barge",34,3,1.25*0.6), //doesn't work in instances
- new Ability("Sever",25,3,1.88*0.6),
- //strength
- new Ability("Punish",5,3,0.94*0.6),
- new Ability("Dismember",25,3,1.22),
- new Ability("Fury",9,6,(0.75+0.82+0.89)*0.6),
- //new Ability("Cleave",17,3,1.88*0.6), //2h
- //new Ability("Decimate",12,3,1.88*0.6), //dw
- };
- //since you cannot use array initialiser for abilities directly here
- abilities = l;
- //iterate over every permutation, with a cap of MAX_ITER times
- int i = 0;
- for(Iterator<int[]> it = new PermIterator(abilities.length); it.hasNext() && i < MAX_ITER; i++) {
- max = Math.max(calcrevo(reorder(it.next()), max), max);
- }
- //test a specific layout - watch for arrayoutofboundsexceptions
- //int[] a = {7,5,3,1,0,6,2,4};
- //calcrevo(reorder(a),0);
- }
- //turn int[] into corresponding Ability[]
- public static Ability[] reorder(int[] order) {
- //make sure to create a new array, don't reorder the base array
- Ability[] out = new Ability[order.length];
- for (int i = 0; i < order.length; i++)
- out[i] = abilities[order[i]];
- return out;
- }
- //calculate the damage per tick of the revolution bar given, and only print it if it a new best
- public static double calcrevo(Ability[] bar, double max) {
- int time = 0, incr = 0;
- double damage = 0;
- Ability next;
- //reset all ability cooldowns and used status
- for (Ability a : abilities)
- a.reset();
- //test for TICKS
- while (time <= TICKS) {
- next = null;
- //reduce cooldown of all abilities by duration of previous ability
- for (Ability a : abilities)
- a.reducecooldown(incr);
- //determine next ability to be used
- for (Ability a : bar) {
- if (a.cd == 0) {
- next = a;
- a.used = true;
- break;
- }
- }
- //if there is no next ability, we have a broken revobar
- if (next == null) {
- System.out.println("not enough abilities provided for a continuous revobar");
- return 0;
- }
- //activate the ability
- next.putoncooldown(); //put it on cooldown
- incr = next.duration; //set advancement (ticks)
- time += incr; //advance time by duration
- damage += next.damage; //increment damage
- }
- double dps = damage/time;
- //System.out.println("Bar "+Arrays.toString(bar)+" damage: "+damage+" ticks "+time+" DPS: "+dps+" max:"+max);
- if (dps > max) {
- System.out.println("Bar "+Arrays.toString(bar)+" damage: "+damage+" ticks "+time+" DPS: "+dps+"\nUsed abilities:");
- //System.out.println(dps);
- for (Ability a : bar)
- if (a.used)
- System.out.println(a);
- return dps;
- }
- return 0;
- }
- }
- //ability class
- class Ability {
- public String name;
- public int cooldown; //in ticks
- public int duration; //in ticks
- public double damage; //average - usually (max+0.2*max)/2==0.6*max
- public int cd = 0;
- boolean used = false;
- public Ability(String name, int cooldown, int duration, double damage) {
- this.name = name;
- this.cooldown = cooldown;
- this.duration = duration;
- this.damage = damage;
- }
- public void putoncooldown() {
- cd = cooldown;
- }
- public void reducecooldown(int c) {
- cd = Math.max(0,cd-c);
- }
- public void reset() {
- cd = 0;
- used = false;
- }
- @Override
- public String toString() {
- return name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement