How do I calculate the amount of XP for a level where the first level is 110, and each level after is 10% more than the last. Preferably to do without a loop because the levels will have to be infinite and will need to be quickly calculated.
in js using a loop:
var xptest=110;
var lastLevel = 110;
for (var level = 2; xptest <= Number.MAX_SAFE_INTEGER || level < 100; level++) {
lastLevel*=1.1;
lastLevel = Math.round(lastLevel *1.1)
xptest+= lastLevel;
console.log('LEVEL',level,'('+lastLevel+' / '+xptest+')');
}
Answer
Let's work through some cases, given $baseXP = 110$ and $increase = 1.1$:
targetXP(1)=baseXPtargetXP(2)=baseXP+baseXP⋅increasetargetXP(3)=baseXP+baseXP⋅increase+baseXP⋅increase2...targetXP(n)=baseXP+baseXP⋅increase+...+baseXP⋅increasen−1
If we multiply $targetXP(n)$ by $increase$, we find that all it does is shift the terms down one:
targetXP(n)⋅increase=baseXP⋅increase+baseXP⋅increase2+...+baseXP⋅increasen
So if we subtract the original from this shifted version, all the terms except the first and last will cancel out, and we get...
targetXP(n)⋅increase−targetXP(n)=baseXP⋅increasen−baseXPtargetXP(n)⋅(increase−1)=baseXP⋅(increasen−1)targetXP(n)=baseXP⋅1−increasen1−increase
This is what's called a Geometric Series - you can read more about the math behind this here.
No comments:
Post a Comment