0

In our game, we have a boss (NPC), who's life is being checked on a time interval, say 1 minute. I need to find a way to extrapolate known points (life,time), and approximately predict life after one minute (after 1 minute life will be checked again, and will be put in data set) Also, extrapolation needs to consider mostly recent change (for instance, if we have 10 points, and last two have changed rapidly, it should be able to predict even more rapid change at next point). I found multiple example this one and this one, but seems like I'm not able to translate all this in as3 code. Basically what I was looking for was 2D Extrapolation.

P.S. The point is that any calculated value should not get above any previous values, that is because the boss' hit points cannot increase, and also cannot stay the same; they can only decrease. I guess that means extrapolation wouldn't do. So I'm looking for another algorithm that will do.

Martin Asenov
  • 1,288
  • 2
  • 20
  • 38

1 Answers1

1

Consider a calculus-inspired approach. If we have a list d[i] of the damage at a past time iand the current time is n, then we can estimate d[n+1] using the previous values in the list. d[n] - d[n-1] provides an estimate of the change from d[n] to d[n+1] based on recent values, (d[n] - d[n-1]) - (d[n-1] - d[n-2]) provides an estimate of the change of that change, and so forth. The idea is to use differencing to estimate change. If you have a time-series data list d[i] = [a,b,c,...], and another list d2[i] = d[i] - d[i-1], then d2[] is the change in d[] for all times i > 1. Since d2[] is also a time series, you can use it to create a d3[], chaining the terms to provide an estimate:

d[n+1] ~ d[n]    +    ( (d[n] - d[n-1]) )  +  ( (d[n] - d[n-1]) - (d[n-1] - d[n-2]) )  +  ...
         ^last value    ^ est. change           ^est. change of change
         d[n]           d2[n]                   d3[n]

Granted that this makes a lot of assumptions about incoming data. The two most important problems I can think of:

  • This assumes that most recent change(s) are completely representative of future values- in cases where change terms are non-linear, this causes the estimation to lag behind the actual data
  • The "lag" becomes stronger as more terms are added - a better estimate (more terms) must be balanced with better agility (less terms)
  • Outliers in incoming data figure directly into the equation, and thus directly affect the resulting estimate
Conduit
  • 2,675
  • 1
  • 26
  • 39
  • This looks good. Is it possible to summarize this for unknown number of data points, with some kind of recursive function? Thank you! – Martin Asenov Dec 07 '14 at 20:29
  • The idea is to use differencing to estimate change. If you have a time-series data list `d[i]`, and another list `d2[i] = d[i] - d[i-1]`, then `d2[]` is the change in `d[]` for all times `i > 1`. Since `d2[]` is *also* a time series, you can just keep doing this and chaining the terms. I'd guess that after a point the terms stop being relevant... personally I'd keep a backlog of a certain number of terms, adding new ones at the same time I remove the oldest. – Conduit Dec 07 '14 at 21:08
  • So basically if you decide that 3 terms are "good enough", then keep a list of the three last damage values and apply the function above. Start with the values initialized to 0 (no damage) and then cycle - if the first three damage measurements are 1, 5, 10, 20 the list goes [0,0,0] -> [1,0,0] -> [5,1,0] -> [10,5,1] -> [20,10,5]. Recalculate the estimation after each push/pop. – Conduit Dec 07 '14 at 21:12
  • I will warn you that this formula will be super sensitive to outliers in incoming values, though - your mileage may vary :) – Conduit Dec 07 '14 at 21:13
  • Editing my answer to illustrate my first comment – Conduit Dec 07 '14 at 21:14
  • I tried that, but unfortunately it doesn't seem to work, because it allows positive changes, while the boss cannot increase health, but I guess this is just how this statistic you supplied work. Unfortunately, it wouldn't work if it allows positive values – Martin Asenov Dec 10 '14 at 14:29
  • @MartinAsenov Yeah, that can happen... You could try disallowing positive changes by checking the summed `d(i)[n]` terms (if change > 0 -> set to 0), but I have no conceptual grasp on what that would look like. Your best bet might be to collect actual data from your application and see if you can find a regression model that works for it. Once the model is set, you can use it to do short-term extrapolation. – Conduit Dec 11 '14 at 16:41
  • I get you, but it just seems to me that such kind of extrapolation is not suitable for this case... (since it must always go down), I edited the question. Thank you for the effort though! – Martin Asenov Dec 11 '14 at 20:11