arithmetic – Tips on how to compute XP thresholds when scaling adjustments for every stage vary?

arithmetic – Tips on how to compute XP thresholds when scaling adjustments for every stage vary?

[ad_1]

I’m growing cellular recreation and I’m caught on a difficulty concerning correct participant stats scaling based mostly on stage.

As a parameters for the computation we now have:

  • base XP worth
  • a number of increment values (for instance one increment for ranges 1-5, one other one for 6-10 and so forth…)

We’re utilizing this formulation:
present stage XP = earlier Stage XP + (earlier stage XP ^ increment).

Let’s break it down on an instance:
We need to get the XP threshold to graduate from stage 3. The bottom XP worth is 100, increment for ranges 1-5 is 0.5.

To get the wanted XP, we first have to get the worth for stage 2:

level2Value = 100 + 100^0.5

Now we now have stat worth for stage 2 and we’re capable of get level3Value like this:

level3Value = level2Value + level2Value^0.5.

If we needed to calculate values for some excessive ranges, this looks as if a reasonably inefficient solution to do issues, as values for all earlier ranges have to be computed prior, and as well as we’re altering the increment worth based mostly on stage – we can’t easy have one line of formulation which will get us the quantity that we wan; all relies on earlier values.

In fact we are able to compute all earlier values, cache it on the server after which do the lookup to the information, however we want to keep away from it if potential – nonetheless I’ve a sense that there have to be higher solution to cope with this downside.

My query is the next:

Are you able to recommend another (related) formulation or methods to compute this? Ideally only one line of code ought to do the trick (one thing like `stage X XP = X * baseXp * increment|, however extra advanced which permits utilization of various increment values)

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply