Elitist Jerks Lagrangian Analysis of the Cataclysm Eclipse System

# Lagrangian Analysis of the Cataclysm Eclipse System

Posted 04/13/10 at 5:33 PM by Hamlet
Updated 04/13/10 at 5:58 PM by Hamlet
Introduction:

I often find it fun and useful to mathematically analyze various parts of WoW. Whenever I find something interesting, I generally wind up posting it on some forum, but this blog feature on EJ might a convenient place to put things that don't fit into any particular topic, or are slightly too esoteric to just drop into a substantive thread about WoW. The goal is both to entertain people who know enough math to follow the discussion, as well as provide an interesting result to anyone who cares about the WoW topic. I'll try to have the assumptions and conclusion stated clearly at the end so people who can't follow the mathematical argument can still understand the main point.

Here I use some variational calculus to examine the new Eclipse system described in the Druid Cataclysm class preview.

This is all we know so far:
Quote:
We are moving Eclipse from a talent into a core mechanic of the class and making it less random. Balance druids will have a new UI element that shows a sun and a moon. Whenever they cast an Arcane spell, it will move the UI closer to the sun, and buff their Nature damage. Whenever they cast a Nature spell, it will move the UI closer to the moon, and buff their Arcane damage. The gameplay intention is to alternate Arcane and Nature spells (largely Starfire and Wrath) to maintain the balance.
The basic question I think of upon reading is, of course, to determine what sort of behavior will be optimal under this new system. Now there are certainly going to be a variety of talents that interact with the Eclipse meter somehow, and at least one new spell, Nature's Torrent, but we don't know how any of these things work yet. It will still be interesting to explore what kind of behavior emerges from the core mechanic they have unveiled, and it will improve our understanding of the system in preparation for the Cataclysm beta when we find out the full details.

Analysis:

Let the eclipse variable E represent the state of the Eclipse meter (0 is the center). The more negative it is, the more "Solar" (Nature-buffed) you are, and the more positive it is, the more "Lunar" (Arcane-buffed). f(E) is a multiplicative modifier to Arcane damage, and f(-E) is a multiplicative modifier to Nature damage.
Unmodified, casting the nature nuke does N damage per unit time, and casting the arcane nuke does A damage per unit time. Casting the nature nuke, on average, increases the Eclipse variable by $\phi_N$ per unit time, and casting the arcane nuke reduces it by $\phi_A$ per unit time.

In order to make the system continuous, imagine that we can perform any linear combination of the nature nuke and the arcane nuke. This is not too far from reality, since we can mix the spells together in whatever ratio we like. Let $\lambda$ be the ratio of nature nukes that we're casting, and $(1-\lambda)$ the ratio of arcane nukes. So at any point in time,

$DPS= \lambda N f(E) + (1-\lambda) A f(-E)$
$\dot{E}= \frac{dE}{dt} = \lambda\phi_N - (1-\lambda)\phi_A$

Solve the latter equation for $\lambda$:
$\lambda= (\phi_A + \dot{E})/(\phi_A + \phi_N).$

Paramaterize in terms of t and let E be the independent variable (reason for this will be evident soon). The goal is to maximize the total damage done, which is the integral of DPS over time. Therefore we can take the DPS function to be our Lagrangian and use Euler-Lagrange mechanics (see appendix) to find an equation describing optimal behavior.

Substituting for $\lambda$, we can write our Langrangian, the DPS function, entirely in terms of E and $\dot{E}$:
$L(E(t), \dot{E}(t), t)= DPS = \frac{\phi_A + \dot{E}}{\phi_A + \phi_N}N f(E) + \frac{\phi_N - \dot{E}}{\phi_A + \phi_N}A f(-E)$

We are now in a position to apply the Euler-Lagrange equation:
$\frac{\partial L}{\partial E} - \frac{d}{dt}(\frac{\partial L}{\partial \dot{E}})= 0$
(ignoring $\phi_A+\phi_N$ denominator):

$(\phi_A + \dot{E})N f'(E) - (\phi_N - \dot{E})A f'(-E) - \frac{d}{dt}(N f(E) - A f(-E))= 0$

$(\phi_A + \dot{E})N f'(E) - (\phi_N - \dot{E})A f'(-E) - N f'(E)\dot{E} - A f'(-E)\dot{E}= 0$

Importantly, all of the $\dot{E}$ terms cancel. This is why we chose E as the independent coordinate above instead of the more intuitive $\lambda$--it makes the result fall out very cleanly.

$\phi_A N f'(E) - \phi_N A f'(-E) = 0$

The resulting equation fixes a value of E. Thus, maximum DPS under this regime is always maintained by holding as closely as possible to one particular optimal value of E. This value can be easily computed from the above equation once all of the constants and the function f are known.

Summary and Conclusion:

The core Eclipse mechanic described in the Druid preview results in a static rotation in which the player holds the Eclipse meter at a constant value, casting whatever ratio of Nature and Arcane spells necessary to prevent the meter from moving. Essentially, some point on the Eclipse meter will give the maximum combination of Nature and Arcane damage, and there will be no reason to stray from there. Note that this result was derived very broadly--the only assumption required was:
1) You can choose to do either Nature or Arcane damage, each doing a certain amount of long-term average DPS and moving the Eclipse meter at some average rate.
2) Eclipse gives some multiplicative bonus based on your position on the meter. (We made no assumptions about what the bonus curve would look like).

So now we have a deeper understanding of what we want to see from the new Eclipse. In order to make the mechanic more interesting than the completely static behavior described here, Blizzard has to introduce some mechanics that break assumption #1 (or #2, but that's less likely). This may not prove to be easy however, since the assumption is itself so weak.

Appendix:

The Euler-Lagrange equation is used in variational calculus to find what function (in this case E(t)) will maximize the value of some particular integral. It is similar in concept to the technique in ordinary calculus of setting a function's derivative equal to 0 to find its minimum or maximum. But in this case, rather than simply finding a single value that maximizes some function, we are finding an entire function that maximizes a function of that function (the latter is often called a "functional").

Specifically, if you have an independent variable t (say, time), and you can control some function of that variable x(t), the Euler-Lagrange equation allows you find the x(t) that maximizes a functional L (called the Lagrangian), as long as L can be expressed in terms of t, x, and $\dot{x}$ (the derivative of x with respect to t). It states that once L is expressed in this way, the function x(t) optimizing the integral of L over time is given by the differential equation
$\frac{\partial L}{\partial x} - \frac{d}{dt}(\frac{\partial L}{\partial \dot{x}})= 0$

Read more here: Euler–Lagrange equation - Wikipedia, the free encyclopedia
Posted in Math , Druids

 That's fascinating work. This assumes that there is a linear relationship between damage dealt and how far you move on the meter (or if you like, a linear relationship between where you are on the meter and the damage bonus). That's not been set in stone to my knowledge, and many have suggested a momentum like system where you actually have a consistent velocity and a quadratic increase based on input of damage. Have you done any modeling around this? Because if it's simply balancing around some optimal point, this seems not particularly interesting; at some point a simple rotation will fall out of this. Posted 04/13/10 at 6:20 PM by kalbear
 I would tend to agree about the non-linear damage bonus, but my gut tells me Blizzard will be using Arcane Blast as a template of sorts for this new mechanic. If so, the bonus might indeed be linear, or at least close to it. Then again, that would imply a more static rotation than they're trying to achieve. (i.e. - Wrath x 5 for max. Arcane bonus -> Starfire/Wrath alternating to keep max. Arcane damage buff.) Posted 04/13/10 at 6:39 PM by Makael
 Would the addition of an incentive to push the eclipsometer to the edge of one side or the other be enough to prevent the situation mentioned in your conclusion? Similar to what is planned for warriors that gain a temporary damage buff when capping rage, provide x seconds of y% increased arcane damage when bumping the edge of the lunar side. Adding a cooldown to the buff, and mirroring the buff on the solar side allows for eclipse to behave somewhat similar to how it is now, but lets the druid control when the buff occurs. Posted 04/13/10 at 6:43 PM by Twid
 Let's be careful--this does not assume that Eclipse gives a linear damage bonus. That's why the magntitude of the Eclipse bonus is kept in arbitrary form f(E). I think we can expect that the bonus will not be linear (I'll show why in a moment). What it does assume is that DPS in either the Nature or Arcane mode of casting is roughly constant and that rate at which the Eclipse meter moves is also roughly constant. They're not perfectly constant of course, since damage is dealt in finite, discrete chunks, but constant enough that the DPS and the rate of Eclipse movement remain reasonably close to the long-term average. Small oscillations in the rate which damage is dealt or the rate at which the Eclipse meter moves are unlikely to upset the result. For example, even if crits affect the meter (like they obviously affect the damage), you can still easily compute an average over time for all of the variables. In order to change the outcome, you need to introduce a qualitatively new mechanic that prevents this sort of linearization. ------- As mentioned above, note what happens if f(E) is actually linear. Now the f' values in the final equation are constants and E has dropped out completely. i.e. there is no solution, because the optimal E value is infinitely far out in one direction. In practice, this means that maximum DPS will come from sitting at one end of the meter. (Alternatively, the equation could happen to balance out perfectly for any value of E, in which case DPS will be constant at all values of E and it doesn't matter what you do). Posted 04/13/10 at 6:56 PM by Hamlet
 I'd consider your latter scenario above to be an adequate way of implementing the Eclipse meter. If, relying solely on nukes, there's no actual difference where you are on the meter, then it simultaneously both makes balancing easy, and allows for DoT refreshes and cooldowns to provide the incentive to oscillate across the entire meter. It would be nice if there was an actual encouragement to this oscillation for the nukes, since that's what Eclipse has traditionally been about, but I'm not sure it's absolutely necessary. Posted 04/14/10 at 2:19 AM by Adoriele
 Edit 2: I see now that I was guessing that dE would be based on damage. After rereading the blizz quote, it could very well be constant (based on the number of spells of a school cast and not the damage done by those spells). This is especially convincing when reading the Nature's Torrent will move the meter 'more' than other spells. Quote: Casting the nature nuke, on average, increases the Eclipse variable by $\phi_N$ per unit time, and casting the arcane nuke reduces it by $\phi_A$ per unit time. $\dot{E}= \frac{dE}{dt} = \lambda\phi_N - (1-\lambda)\phi_A$ Does it matter if the change in E is affected by the damage modifier f(E)? If the modifier affects the "amount moved", it seems wierd to me to say the average increase in E caused by a nuke. On one side of E that nuke will do constant dE, and on the other side it will do dE based on f(E). Edit: Sorry, I should have read the comments. You say: Quote: rate at which the Eclipse meter moves is also roughly constant in your comment, but I'm wondering if it may not be constant since it may also be modified by the Eclipse bonus. If you are doing a constant amount of N over time (the base damage of a series of Nature nukes before the modifier), then if the dE is dependent on the overall damage N * f(E), the the dE will be changing per each nuke. Posted 04/14/10 at 10:30 AM by thefool808 Updated 04/14/10 at 4:12 PM by thefool808
 This still seems to assume a completely linear behavior of movement of the meter dependant respect to either time casting or damage done by the spells doesn't it? If there is some memory associated with moving the meter (i.e. phi A and phi N are not fixed, but can vary significantly depending on the casting behavior you use) then it wouldn't seem obvious to me that there would be an optimal point. Visualizing it, if the meter moves slowly while you are taking advantage of the bonus damage and quickly while charging up if you swing from side to side, but moves slowly while taking advantage and slowly while charging up if you try and stay in the same place, there would be some options for f(E) where you wouldn't want to hover around a single optimal point. Posted 04/14/10 at 5:18 PM by Videl
 I don't think you can assume independent phi A and phi N; what if they're dependent on lambda and E? While phi A and phi N will certainly exist for any given pattern of casting, it's not clear that there is a unique phi A and phi N for a given lambda (or vice versa). Even if you do assume that, aren't you effectively proving that E = 0 (or some fixed E) is a DPS -minimum- for any 'reasonable'* choice of f(E)? (i.e. f(x<=0) = 1, f(x>0) > 1, f'(x>0) > 0) Qualitatively it seems like for any 'reasonable' f(E) the maximum point will always be one of the endpoints (assuming there is a cap to E, otherwise there would be no maximum). * Reasonable in this case is assuming that 0) the multipliers for arcane and nature are symmetric and can actually be represented as a single function (this is actually not obvious nor necessary, and is assumed in the original post), 1) your nukes are never penalized from base (i.e. f(x<0) = 1), 2) f(E) is not decreasing (otherwise the result should be obvious). Actually, unless I'm missing something, this is just optimizing the linear combination of f(E) and its reflection with a 'mixing' variable represented by lambda. It might be more interesting to consider this another way. Suppose at any given E there was an optimal spell to cast (optimal in this case means the best spell in the long run, i.e. including movement of E, not just the best damage for the next cast), and that you only have NatureSpell and ArcaneSpell that both work as described in the original post (i.e. NatureSpell increases E, and ArcaneSpell decreases E). Furthermore, assume the optimal cast choice is only dependent on current E. We also assume that the movement due to NatureSpell and ArcaneSpell are 'small' relative to the granularity of optimal spell selection function (i.e. one cast doesn't 'jump over' a region switch). Finally, we assume that at the beginning of the fight, you are at E = 0 or 'very close'. Suppose then there exists a value of E > 0 such that ArcaneSpell becomes optimal. Then there must be a minimum such value, ASE. This implies that any value of 0 < E < ASE must have NatureSpell as the optimal spell. This means that either ArcaneSpell must move E enough that E < 0 after ArcaneSpell OR the optimal casting rotation once E > 0 must be ArcaneSpell until ASE, then NatureSpell. If there is no value of E > 0 such that ArcaneSpell becomes optimal, then the rotation is trivial. We can apply the same argument in reverse for E < 0. Posted 04/14/10 at 6:43 PM by Noules
 What you describe with ASE is what is described in the OP. You cast NatureSpell until you get to ASE, then you cast ArcaneSpell, which puts you back into 0 < E < ASE, so you cast NatureSpell again, which puts you E > ASE, so you cast ArcaneSpell again, and so it continues indefinitely. Phi dependent on lambda and E is really interesting. I'd initially rejected it, but for the wrong reason. When I try and visualize how it would work I don't think it would encourage the right kind of casting behavior though. Dependence on E alone encourages hovering. Dependence on lambda alone has no effect on it. Together, they only encourage switching when the effect of E encouraging hovering has pushed lambda way out of whack, then hover again until it gets out of whack in the other direction. The amount of time you spend hovering at the ends would grow as the fight went on too. Also, I think you'd need an addon to keep track of lambda for you in game so you knew when it was optimal to switch. Making phi dependent on a short term value of lambda, whether it be in terms of time or number of casts (~10 seconds or 8 casts, for example)is the only thing I can think of that encourages going to one end, then immediately switching and going all the way to the other end for sustained dps, which I think is the desired casting behavior. I can't imagine a shape for f(E) that doesn't have maximums at infinity and negative infinity that would be reasonable. Posted 04/15/10 at 6:24 PM by Videl
 The exact rotation around the optimal DPS point would still depend on the relative values of the delta-E-per-cast of the spells (unlikely scenario, but if one moved it 1/10th as much as the other, for example) and not necessarily cast one, cast other. That's mostly a moot point, admittedly. ASE isn't (in general) being calculated in the OP because the ASE for 'reasonable' functions with 'reasonable' values for the spells would probably be at the cap of the eclipse meter (that is, you would want to stay as close to one side of the bar as possible). The OP's result would not give you that if the 'reasonable' functions are nondecreasing and phi-N/phi-A constant. It will tell you that 0 is a minimum (and it is indeed a stationary point for 'reasonable' functions) but it will not necessarily find the optimal point without outside intervention (which is typical; standard practice being ALWAYS check endpoints and other discontinuities). Regarding 'reasonable' functions: 0.0 <= f(E < 0) <= 1.0 has to be true. By definition f(0) = 1.0 (since there's no modifier either way) and presumably being in the wrong domain does not IMPROVE your spells (which is what f(E < 0) > 1.0 implies). Note that f(E < 0) isn't 'being in the nature phase' by your definition, f(E < 0) is 'being in the wrong phase'. There are actually two functions which are (I assume[d]) implicitly presumed to be identical in the OP: f-sub-nature(E) and f-sub-arcane(E), being the damage multiplier for nature spells and for arcane spells at a given value of E. The assumption is that f-sub-nature(E) = f-sub-arcane(-E) = f(E), but f(E) itself is not (for any 'reasonable' function) symmetric about E=0. Hence why I suggested that a 'reasonable' f(E) must follow f(E<=0) = 1 and nondecreasing. (actually, upon reflection, there's no reason why f(E) must be nondecreasing throughout; nondecreasing doesn't have to be a requirement, though there must be at least some point E > 0 s.t. f(E) > 1.0 or the function would be pointless; this doesn't change the conclusion, though) Most of this is pretty much semantics, though (not to deride precision, however). The bottom line seems to be that in order for the rotation to be more interesting than 'revolve around E = whatever', there has to be more state involved than just E. Simply introducing new spells wouldn't do it (the same arguments would still hold, I believe), though I believe there are some fairly simple ways to encourage people to go back and forth - one easy (if not the most interesting) way would be simply to give you a buff when you hit one end of the eclipse meter that a) buffed the other set of nukes and b) prevents you from moving the eclipse meter back, lasting until you are in the other phase (and no passive buffing of nukes otherwise, based on E). The phi-based-on-lambda idea could work too - one potential system would be where the movement doubled as you chained a given nuke, and started over when you switched. It's conceptually pretty simple, too, and for 'reasonable' values and functions it can be demonstrated to work: Assume f(E) linear for E > 0, f(max E) = 1 + 7*B. Also assume phi-A = phi-N = 1/7 * max E (chosen for simplicity). Then the hovering rotation gives you (wlog assume A > N, where A and N are respectively arcane and nature damage from each cast). Hovering damage per cast = ((1 + 7B) * A + N)/2 while moving back and forth gives you Full rotation damage per cast = ((1 + 7B) + (1 + 6B) + (1 + 4B) + (1 + 0B)) * (A + N)/8 Assuming A = N, Hovering damage per two casts = (2 + 7B) * A and Full rotation damage per two casts = (4 + 17B) * A/2 = (2 + 8.5B) * A for a difference of 0.75*B*A per cast. If the maximum multiplier was 135%, it would imply a very modest ~3.2% gain. The value is certainly tunable, though, as B can be almost arbitrarily high (if presumably Blizzard is not extremely concerned about resto DPS). This sort of model has a lot of potential advantages from Blizzard's perspective (beyond being simple, a significant benefit on its own right), since the 'alternate' rotation is very easy, and doesn't lose a huge amount of DPS from the optimal rotation; also the relative gain scales as B increases. The preview implies the multiplier provided by the Eclipse effect will increase with gear/mastery - so doing the rotation correctly is less important early and more important later. Apologies for the extremely long 'comment'; got a bit carried away! Posted 04/16/10 at 7:41 AM by Noules