Public Group

# How To Calculate Exponential Skill Level Using Experience Points ?

This topic is 2072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am running into an issue when it comes to calculating a player's non combat skill level based on the total experience points they have.

Each skill level requires 108% more experience than the level before it.

Example:

Level 5 requires 100 exp

Level 6 requires 108 exp

Level 7 requires 116 exp

Level 8 requires 125 exp

and so on.

In simple terms, how would I calculate the player's skill level by just using the experience points they have ?

Could you provide a code example of how it would work in Java or Python ?

Thank you very much for your time !

##### Share on other sites
Let's assume level 1 requires 100 exp, what we'll call the base exp.
If a level requires 8% more exp than the previous one, we would have the following:
1 - base_exp = 100
2 - lvl1 * 1.08 = 100 * 1.08 = 108 (208 total)
3 - lvl2 * 1.08 = 108 * 1.08 = 116.64 (324.64 total)
4 - lvl3 * 1.08 = 116.64 * 1.08 = 125.9712 (450.6112 total)
and so on.

My Java is a little rusty, but I'll give it a try.
public class level{
public static final double base_exp = 100;
public static final double exp_increase_per_level = 0.08;
public static final int max_level = 99;

public static int level (double exp) {

int i = 0;//Starting from lvl 0, if you want to start from lvl 1, just initialize to 1
double test_exp = base_exp;

while ( i < max_level ) { //Test for max_level, replace with while(true) for no max
if (test_exp > exp) { //Check if enough exp for lvl i
return i; //if so, return the level
}

//The test failed, so the exp is higher than the necessary for level i.
test_exp = test_exp + test_exp * exp_increase_per_level; //Increase it by 8% to test the next level
i++; //Since the test failed, the level is higher
}

return max_level;//Return when it reach max_level
}

public static double level_to_exp (int level) {
if(level == 1)
return base_exp; //return the base_exp when reach the first achievable level
else {
double prev = level_to_exp(level-1); //Computes the previous level exp to calculate this one
return prev + prev * exp_increase_per_level;
}
}

public static double level_to_total_exp (int level) {
if(level == 1)
return base_exp; //return the base_exp when reach the first achievable  level
else {
return level_to_total_exp(level-1) + level_to_exp(level-1) * (1 + exp_increase_per_level);
}
}

public static void main(String []args){
System.out.println("90 exp is level "+level(90));
System.out.println("900 exp is level "+level(900));
System.out.println("9'000 exp is level "+level(9000));
System.out.println("90'000 exp is level "+level(90000));
System.out.println("188'594 exp is level "+level(188594));
System.out.println("188'595 exp is level "+level(188595));
System.out.println("900'000 exp is level "+level(900000));

System.out.println("To level 3, "+level_to_exp(3)+" exp");
System.out.println("To level 30, "+level_to_exp(30)+" exp");
System.out.println("To level 99, "+level_to_exp(99)+" exp");

System.out.println("Total exp to level 4, "+level_to_total_exp(4)+" accumulated");

}
}
This is the output:
90 exp is level 0
900 exp is level 29
9'000 exp is level 59
90'000 exp is level 89
188'594 exp is level 98
188'595 exp is level 99
900'000 exp is level 99
To level 3, 116.64 exp
To level 30, 931.7274897290217 exp
To level 99, 188594.07204572056 exp
Total exp to level 4, 450.6112 accumulated
Edited by dejaime

##### Share on other sites

Your equation for xp needed for a particular level is:

xp = 100*1.08^level  (Same formula as "compound interest")

So turning that around should be:

level = ln(xp/100) / ln(1.08)  (Using algebraic rules for exponents )

Java code:

float level = Math.log(xp/100) / Math.log(1.08);

Edited by Olof Hedman

##### Share on other sites

Your equation for xp needed for a particular level is:

xp = 100*1.08^level

So turning that around should be:

level = ln(xp/100) / ln(1.08)

You can use Math.log for that.

It's actually xp = 100*1.08^(level-1). To go from level 0 to level 1, you only need (say) 100 exp, which is a base, so base*1.08^0 = base. To go from lv1 to lv2, you need 100*1.08 extra, which is 100*1.08^(2-1) = ... = 108.

When you sum those up, you get something like total_xp_for_level = base*(level - 1 + 1.08^(level-1)).

So if you use L as the target level, M as the modifier (1.08 in this case), B as the base exp for level 1 (100 in this case) an T as the total exp for level L, turning that around, i got to:
L + pow(M, L-1) = 1+ T/B

and i was lazy to continue. :)

##### Share on other sites

Ah, thats true. You can just add that after to offset the numbers though:

xp = 100*1.08^(level-1)  =>

xp/100 = 1.08^(level-1) =>

level - 1 = ln(xp/100) / ln(1.08) =>

level = ln(xp/100) / ln(1.08) + 1

Edited by Olof Hedman

##### Share on other sites

Thanks. I'll implement that as soon as I can.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75