Author Topic: Experience, some math //WIP, part 1//  (Read 2573 times)

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Experience, some math //WIP, part 1//
« on: May 06, 2007, 01:58:01 PM »
After reading Brodas post about programming books, I took a look at his favourite, MUD Game Programming (I would recommend it as well), and I stumbled across the author's formula to calculate the amount of required experience (EXP for short) for a level-gain.

Now this got me thinking how I usually manage level gains, experience forumlas and so on.

Some of you might have come across this problem as well: balancing the level/experience curve. I always have a hard time not only to get a nice formula going, but also how to award EXP.

The book suggested the following formula:
Code: [Select]
experience = 100 * (pow(1.4,level-1)-1)

This is a usable formula for the the first...20 levels or so, after that the required gaps become huge. You could make a different formula for every 20 levels, but this would become quite confusing with time and you'd always have to write new formulas as the game goes on. Of course, every formula will be quite unbalancing at a certain level, but one should try to keep this unbalancing level out of reach.
This can be achieved by a level cap, or declare whoever gets to this level first as the winner of this round.

But let's get back to this formula. Where is the miscalculation in it? Right here: pow(1.4,level-1). And why is that, you might ask? Simple: If you make a nice table with all possible values from level 1-100 for this formula, you will get huge results. Go check it out, or if you really need proof, ask me and I'll make you a nice table with all the data.

Now, how to avoid this problem, or at least slow it down:
try something like this (for the amoung of xp needed to reach the next level, not the total level):
Code: [Select]
pow(pow(1.03,level)+1.3,2)*100

What does this do, you might ask: This splits up the level requirements into smaller parts, giving the player overall a better "achievement-feeling" (possible to gain one level in 1-2 days, which keeps the playerbase happy).

Ugh, now I forgot my other stuff I wanted to write. I'll continue later on this. But feel free to comment anyways

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: Experience, some math //WIP, part 1//
« Reply #1 on: May 06, 2007, 07:37:28 PM »
First, I'm glad someone else liked the book too. :)

Second, initially in my game I was just going to increase the requirement by 25% of what it took to get to the current level and balance it from there. So if it took 1000 xp to get to level 2, it would take 1250 xp to get to level 3 and so on. I figured this would give me some nice round numbers and I could always tweak the amount of xp you gain for each quest/kill as you go up.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #2 on: May 07, 2007, 02:03:49 AM »
So do you have a formula for the amount of XP you gain for a monster kill?

I remember D2 doing something like that but on a curve. So if the difference between your and the monsters level is <= 5 then you get 100%, elseif <= 10 -> 80% exp and so on. Ending with only 5% or so of the experience you originally gained.

I recently thought about that as well:
Make for each skill a fixed amount of exp you gain. The amoung of exp you gain is determined by the skill level. But it's inverse. Maybe an example helps:
You have 4 skills:
Code: [Select]
* Attack -> Lvl 5
* Defend -> Lvl 3
* Mine   -> Lvl 7
* Smith  -> Lvl 1

Now, each of these skills gain a level when you reach 10'000 EXP.

Now, each time you attack, you gain a bit of EXP for the attack skill. Each time you defend, you gain a bit for the defend skill and so on.
You get more EXP when you fail (say 1.5 the usual EXP).
And here's a quick formula (Just from the top of my head, not eveb remotely tried):
Code: [Select]
Exp gained = (1 + (10 - Skill lvl))^2*2
This means that it takes 50 succesfull tries the first time to get to lvl 1 of a skill, 62 succesfull tries to get to the 2nd level, 5000 to get to level 10. It takes 7790 tries to go from lvl 0 to lvl 10. (10 being the max, obviously)

This formula could be adjusted by increasing the needed experience with each level.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #3 on: May 07, 2007, 02:57:47 AM »
I thought this deserved a new post:

Okay, I've been playing around with Mathematica and found some nice additions to the above formulas:

First off:
I made 3 tables:
1) one that determines the number of successfull tries needed to reach the next level
2) The amount of experience gained per try on this level
3) the total amount of experience required to reach the next level (not the total amount of experience)

Code: [Select]
function NumTries($x)
{
   $x = pow((2+(pow(1.005,$x)*($x+2)),2);
   return $x;
}

function ExpPerTry($x)
{
   $x = 30 / (30+$x) * 20;
   return $x;
}

function ExpNeededToLevel($x)
{
   $x = NumTries($x) * ExpPerTry($x);
   return $x;
}

yeah, this pretty much sums it up what I did and what can be easily adjusted.

Maybe some explanations about the first function (NumTries):
(a+ (b^x * (x + c)))^2
a, c : determines the starting number
b : determines how fast the increases grow
x : this is the current level (You start out at level 1)

I'm looking to any improvements on this formula or additions / balance tweaks :)

[?∂??]
The ExpPerTrie-function slowly decreases and converges to zero.
This formula is only usefull to a certain level (above 400, tho) at which point the two functions trade places, meaning that there are more tries required to get a level than there is experience.
« Last Edit: May 07, 2007, 03:25:30 AM by Sinzygy »

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #4 on: July 27, 2007, 09:35:26 AM »
Back to this topic with a small addition.

I made a small graphic which shows the curves for 3 different typed of exeperince-formulas

The red one uses the formula 10 * pow(1.25,level-1), also known as "25% increase with each level"
The blue one uses the formula 100 * (pow(1.4,level-1)-1), the formula I mentioned in my first post
The green one uses the formula pow((2+(pow(1.005,level)*(level+2)),2), the formula from the post above this one.

 



This demonstrates that the formula I developed has a mild exponential increase which allows for a, in my view, more balanced game experience. The other two formulas take off too fast too soon to be of any real use.
Of course this only applies if the experience gains are approprietly chosen. Every formula can be balanced by chosing the appropriate exp gains.

[€∂¡†] I took 200k exp points as the highest boundry to make the graph readable. You can imagine how the red and blue curves shoot through the roof.
« Last Edit: July 27, 2007, 09:36:58 AM by Sinzygy »

Offline Sunchaser

  • Game Owner
  • Level 22
  • *
  • Posts: 274
  • Reputation: +2/-0
  • Game Owner
    • View Profile
    • Medieval Europe
Re: Experience, some math //WIP, part 1//
« Reply #5 on: December 15, 2008, 08:47:56 AM »
Very interesting discussion, btw I will order that book (MUD Game Programming).

As I am trying to create a game, I have some newbie questions on the skill system and on the experience points

1) I looked a bit at the d20 system, and i saw the %/level thing you described. But i could not find a table that
details the base experience points that a monster gives when killed. Is there a resource somewhere
that gives some guidelines on this?

2) I thought initially to let the user the choice to spend his experience points on advancing level or learning skills,
but i like your idea that for improving skills one has to try them. In your system, this is the only way to improve your skills
or you can improve them even by using experience points?

3) It's better that the skills are available at level 1 or that some skills are available only at certain levels?
For the beginning i want to create few and basic skills.

Bye



Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,128
  • Reputation: +26/-1
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #6 on: December 15, 2008, 11:58:23 AM »
The best info on experience formulas can be found at rec.games.roguelike.development, IIRC the nicest curve can be done by using exp() or log(). But I do not remember what the exact formula was :D

Do not forget that this coin has 3 sides.
- experience per level required
- experience per kill given
- monsters difficulty
I have forgotten about the third one and my whole system fallen down because players started to kill much higher level monster that they supposed to :)
Personally, I think it is imposible to make such system on paper without real live testing. Too many factors.

As for me I use "exp_required = (level*level*level*10)", too early to say how it works, but for now seems OK.

I also plan to take advantage of BBG nature. The experience given per kill will increase if player has lower level that is recommended for a certain day of the round (for example, in day 30 all players below level 40 will be getting +50% experience).

Offline Scion

  • Level 27
  • **
  • Posts: 402
  • Reputation: +11/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #7 on: December 16, 2008, 02:46:54 AM »
yes, on paper it can be quite difficult to see the exact effect of a small change to one variable or factor in a serries of functions.

I have been playing around with combat systems and have decided to setlle on a system that includes a random factor.....which is great cause if brings a bit of variety....but i guess weve all seen players that complain that some 'Noob' who was one level lower than them beat them in combat 'and OMG the fight here is so umbalanced it SUX'  So i wanted to see just what chances a lower level had of beating a higher level.....

So i wrote a small program that would run the combat code a large number of times for every single player combination there was...

i found that my random factor meant that in a batlle of 5 rounds the lowest level would beat the highest roughly 0.1% or once every thousand fights.
with 7 rounds to a battle....it was 0.03% or once evey 3000 fights...

But i guess the point im making is that the choice of the number of rounds could have been made arbitarily, but without first actually running some testing your not going to know the affect of your choice. The same goes for all of the other variables in my combat system.

The same can be done with experience gains and leveling requirements..which is what im going to be looking at next, I want to come up with a leveling scheme that is bassed on chance....in otherwords you have a chance to increase in level but its not guaranteed. Ill need to be carefull to ensure that the chance that someone can level too quickly is insignificant or zero same with the chance that they level too slowly...Ive been thinking of using a leveling window aproach....with mins and max's to counter that effect....



Offline luvva

  • Level 10
  • *
  • Posts: 60
  • Reputation: +0/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #8 on: December 16, 2008, 06:05:55 AM »
you could try using a modified and re-normalised gaussian for the max/min window :P

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,128
  • Reputation: +26/-1
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #9 on: December 16, 2008, 06:33:54 AM »
you could try using a modified and re-normalised gaussian for the max/min window :P
Yes! Gaussian, it was the one that was claimed to be the best formula, I always forget the name :D
I will post the link for myself so I can find it later :D http://en.wikipedia.org/wiki/Gaussian_function

What would be the fastest (by this I mean low execution time) way of implementening this formula in PHP?

Offline luvva

  • Level 10
  • *
  • Posts: 60
  • Reputation: +0/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #10 on: December 16, 2008, 10:44:13 AM »
i'd imagine there's a normal distribution function in there somewhere- its essentially the same thing. The problem comes when you want to normalise it so that it's confined between the min and the max.

The best way to figure it out is by using the integral of the normal distribution:

http://en.wikipedia.org/wiki/Error_function

Using that function, you'd need to adjust your value for your input so that you have 0 at xmin, and 1 at xmax. (you'll need to stretch it vertically and displace it by +0.5 to get a usable non-skewed function)

that all depends on how much you want it to slope really- the functions where almost everyone will lie in the middle will have a stretch factor of just over a half, whereas ones which are more of a linear distribution (everything is equal) will be where the stretch factor is very large.

If i get a moment where i feel like figuring it out a little more, i'll post here ;)

That function will give you the probability that you've levelled up, given your experience. [go to **]

(as far as i know, it's not in PHP)

The binomial function operates similarly, but you'd need a rather large number of values to do it properly (you'd need to take a value for each experience point- i'm not sure how long that'd take to run).

for that, you'd need to set your number of values to max-min, and set the distribution to begin at min.(you'll be looking at the (x-min)th value) [go to **]

[**]once you get one of those particular functions, you need to make sure you define a static random number between 0 and 1 for each level up, for each player- otherwise it'll bias when a player levels up quite a lot. Once the value you're reading is greater than the random number, the player levels up, and then you use the next level's distribution (assigning a new random number for this new level), until the player doesnt level up.

if i have any more thoughts on it, i'll post again, but i hate probability because of things like that xD

(yes, i know that was fairly confusing- hopefully someone can put it into better words for me if anyone realises what i'm on about ;) )

Offline Scion

  • Level 27
  • **
  • Posts: 402
  • Reputation: +11/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #11 on: December 17, 2008, 04:30:45 AM »
Yep believe it or not that did make sense....

I was planing on using a simplification of the gausian error fuction...(divide the x axis between my min and max into 3 sections and aproximate each with a straight line.)

....ok if im honest i couldnt have told you the name of the function....heck its been .... erm, quite some time since uni. But i did have that graph shape in mind with what i wanted to achieve.


Offline luvva

  • Level 10
  • *
  • Posts: 60
  • Reputation: +0/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #12 on: December 20, 2008, 05:42:32 PM »
lol- it's one of those things that sticks in your head i guess xD

have you tried using some function of arctan? that might work too.

Offline Scion

  • Level 27
  • **
  • Posts: 402
  • Reputation: +11/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #13 on: December 21, 2008, 08:26:54 AM »
in all my functions i do try to reduce complexity by using approximations that are good enough....

and also identify ways to keep the actual calculations required as simple as possible....ok for leveling checks they dont get run all that often...but combat calculations sure do...

for instance if i was to simplify my combat system just a little what i could do is simply store a chance that a particular attacker wins against a particular defender in the db ....then its a simple selct statement and a call to the random number generator....

the chances to win would be pre-calculated by runnign the combat system a large number of times....

ok yes its not that flexible and wouldnt allow for individual player effects...but its a possibility for keeping things simple.

Offline k1ng

  • Level 4
  • *
  • Posts: 11
  • Reputation: +0/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #14 on: February 08, 2009, 08:33:59 PM »
Code: [Select]
experience = 100 * (pow(1.4,level-1)-1)

Code: [Select]
pow(pow(1.03,level)+1.3,2)*100

Im new to this coding buissenss. could you explain what all of that is calculating please. the 'pow' , 1.03,level , *100.
it would really help me out

Offline ranting

  • Level 4
  • *
  • Posts: 14
  • Reputation: +0/-0
    • View Profile
Re: Experience, some math //WIP, part 1//
« Reply #15 on: February 11, 2009, 06:56:51 AM »
could you explain what all of that is calculating please. the 'pow' , 1.03,level , *100.

'pow' is a function that is used to calculation exponential expressions.
For example "pow(1.4,level-1)" : if the level is 5, the expression would be 1.4^4 which is the same as 1.4*1.4*1.4*1.4 = 3.8416
So it's a way to make your experience curve grow exponential based on yor level, i.e. it becomes harder and harder to gain new levels.


Another approach could be to first decide how quickly/easily you want the players to gain a new level. (I havn't used this appoach myself, but have considered it.)
This probably should be divided into two parts, since you may want new players to quickly gain new levels in the beginning in order to get excited about things. So maybe up to level 5-10 you could treat it specially, before hitting of a more generic formula.

For example, lets say I want a new player to gain next level after 10 successful attacks. At level 2 maybe still only 10 attacks. Then slowly increase it, at level 3 it will take 12 attacks. Level 4 will need 20 attacks, and at level 5 it'll take 50 attacks.
Once at level 6 I will start using my generic formula. In this case I will use a simple linear function, so that the number of attacks needed slowly increase from 70 at level 6 to about 80 at level 55:
nrAttacks = 0,2*level + 68,8

Then I decide that the experience gained is based on the (enemy) level: 10*level.
That gives me as level 1 I need 100 exp, at level two 200 exp, level three 360 exp, level four 800 exp, level 5 2500 exp. Then at level 6 and forward I can use the formula:
Exp needed = 10 * level * (0,2 * level + 68,8)
Exp needed = "Exp gained at the current level" * "wins needed at the current level"
(If you want to simplify the formula you could ofc also write it as: Exp needed = 2 * level^2 + 688 * level )
Then to tweak the curve you simply tweak the part-formula that decides how many attacks it needs at a certain level. Since you are in control over the curve that decides number of attacks needed, the resulting curve for exp needed shouldn't become too steep.


On a sidenote, having the experience gained based on the enemy level will include a simple reward system for attacking more difficult targets, assuming that a player on a higher level is a more difficult target than a player at your own level. If you attack someone one level above yourself, you will in the example above be rewarded with 10 extra exp compared to attacking someone at the same level. Consequently if you choose a more simple target, and attack someone a level below you, you will be punished by earning 10 less exp.
« Last Edit: February 11, 2009, 07:30:17 AM by ranting »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal