Advertisement
gaz_lloyd

Untitled

Feb 25th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.16 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Iterator;
  3.  
  4. /**
  5.  * Created by Gareth Lloyd on 24/02/15.
  6.  *
  7.  * based on work by Cook Me Plox
  8.  *
  9.  * uses PermIterator from http://stackoverflow.com/questions/2000048/stepping-through-all-permutations-one-swap-at-a-time/11916946#11916946
  10.  */
  11. public class RevolutionOpt {
  12.  
  13.     //all abilities to be considered for the bar
  14.     public static Ability[] abilities;
  15.  
  16.     //maximum number of iterations - permuations is O(n!), so this stops it going for far too long if considering larger n
  17.     //  if n! > MAX_ITER, you can run a few times, reordering the abilities array each time
  18.     public static int MAX_ITER = 500000;
  19.  
  20.     //number of ticks to run the simulated revobar for
  21.     //  100 ticks per minute
  22.     public static int TICKS = 6000;
  23.  
  24.     public static void main(String[] args) {
  25.         double max = 0;
  26.  
  27.         //define all abilities to be considered
  28.         Ability[] l = {
  29.                 //attack
  30.                 new Ability("Slice",5,3,0.7),//1.10*0.6),
  31.                 //new Ability("Havoc",17,3,1.25*0.6), //dw
  32.                 new Ability("Backhand",25,3,1*0.6), //no kick included
  33.                 //new Ability("Smash",17,3,1.25*0.6), //2h
  34.                 //new Ability("Barge",34,3,1.25*0.6), //doesn't work in instances
  35.                 new Ability("Sever",25,3,1.88*0.6),
  36.  
  37.                 //strength
  38.                 new Ability("Punish",5,3,0.94*0.6),
  39.                 new Ability("Dismember",25,3,1.22),
  40.                 new Ability("Fury",9,6,(0.75+0.82+0.89)*0.6),
  41.                 //new Ability("Cleave",17,3,1.88*0.6), //2h
  42.                 //new Ability("Decimate",12,3,1.88*0.6), //dw
  43.         };
  44.  
  45.         //since you cannot use array initialiser for abilities directly here
  46.         abilities = l;
  47.  
  48.         //iterate over every permutation, with a cap of MAX_ITER times
  49.         int i = 0;
  50.         for(Iterator<int[]> it = new PermIterator(abilities.length); it.hasNext() && i < MAX_ITER; i++) {
  51.             max = Math.max(calcrevo(reorder(it.next()), max), max);
  52.         }
  53.  
  54.         //test a specific layout - watch for arrayoutofboundsexceptions
  55.         //int[] a = {7,5,3,1,0,6,2,4};
  56.         //calcrevo(reorder(a),0);
  57.     }
  58.  
  59.     //turn int[] into corresponding Ability[]
  60.     public static Ability[] reorder(int[] order) {
  61.         //make sure to create a new array, don't reorder the base array
  62.         Ability[] out = new Ability[order.length];
  63.         for (int i = 0; i < order.length; i++)
  64.             out[i] = abilities[order[i]];
  65.  
  66.         return out;
  67.     }
  68.  
  69.     //calculate the damage per tick of the revolution bar given, and only print it if it a new best
  70.     public static double calcrevo(Ability[] bar, double max) {
  71.         int time = 0, incr = 0;
  72.         double damage = 0;
  73.         Ability next;
  74.  
  75.         //reset all ability cooldowns and used status
  76.         for (Ability a : abilities)
  77.             a.reset();
  78.  
  79.         //test for TICKS
  80.         while (time <= TICKS) {
  81.             next = null;
  82.  
  83.             //reduce cooldown of all abilities by duration of previous ability
  84.             for (Ability a : abilities)
  85.                 a.reducecooldown(incr);
  86.  
  87.             //determine next ability to be used
  88.             for (Ability a :  bar) {
  89.                 if (a.cd == 0) {
  90.                     next = a;
  91.                     a.used = true;
  92.                     break;
  93.                 }
  94.             }
  95.  
  96.             //if there is no next ability, we have a broken revobar
  97.             if (next == null) {
  98.                 System.out.println("not enough abilities provided for a continuous revobar");
  99.                 return 0;
  100.             }
  101.  
  102.             //activate the ability
  103.             next.putoncooldown(); //put it on cooldown
  104.             incr = next.duration; //set advancement (ticks)
  105.             time += incr; //advance time by duration
  106.             damage += next.damage; //increment damage
  107.         }
  108.  
  109.         double dps = damage/time;
  110.         //System.out.println("Bar "+Arrays.toString(bar)+" damage: "+damage+" ticks "+time+"  DPS: "+dps+"  max:"+max);
  111.  
  112.         if (dps > max) {
  113.             System.out.println("Bar "+Arrays.toString(bar)+" damage: "+damage+" ticks "+time+"  DPS: "+dps+"\nUsed abilities:");
  114.             //System.out.println(dps);
  115.             for (Ability a : bar)
  116.                 if (a.used)
  117.                     System.out.println(a);
  118.  
  119.             return dps;
  120.         }
  121.         return 0;
  122.     }
  123. }
  124.  
  125. //ability class
  126. class Ability {
  127.     public String name;
  128.     public int cooldown; //in ticks
  129.     public int duration; //in ticks
  130.     public double damage; //average - usually (max+0.2*max)/2==0.6*max
  131.     public int cd = 0;
  132.     boolean used = false;
  133.  
  134.     public Ability(String name, int cooldown, int duration, double damage) {
  135.         this.name = name;
  136.         this.cooldown = cooldown;
  137.         this.duration = duration;
  138.         this.damage = damage;
  139.     }
  140.  
  141.     public void putoncooldown() {
  142.         cd = cooldown;
  143.     }
  144.  
  145.     public void reducecooldown(int c) {
  146.         cd = Math.max(0,cd-c);
  147.     }
  148.  
  149.     public void reset() {
  150.         cd = 0;
  151.         used = false;
  152.     }
  153.  
  154.     @Override
  155.     public String toString() {
  156.         return name;
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement