d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Programming Javascript Experience Algorithm > For My Html5 / Js Rpg
Add Reply New Topic New Poll
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Jun 1 2013 02:44pm
Hi guys,
I haven't been very actively lately. I'm sure most of you have no idea who I am.
I've been lurking in the forums for several years, playing titles such as D2, D3, PoE, LoL, and WoW.
Now, I'm back, but instead of trading and playing games, I'm am mostly going to be in the sub-forums working on my current project (~3-4 weeks old at this point)

My first dilemma comes from my desire to learn more about the memory & processing requirements of web languages.

I have worked out an algorithm, however I feel that using the algorithm I've come up with might be "working hard, rather than working smarter".
The point of the algorithm is to determine how much experience the "player" needs to achieve their next level up.
The amounts (assuming I didn't fudge up my math anywhere in the table) are the exact amounts that I want!
The algorithm will generate the correct amount, however in order for it to do so there are several variables it needs to remember.

What I'm wondering is if any of you math savvy folk here at JSP could help me come up with an algorithm that generates the same experience chart posted below, but doesn't require the game to store/call as much data.
If you need a more thorough explanation of what I'm trying to do, please just ask.

Thanks for looking!

PseudoCode + Table
Code

Experience per Level Algorithm

Current Level: lvl
Exp Needed to achieve next level:    nExp
Exp cost of Current Level: cExp

Level 1: 0
Level 2: 10
Level 3: 30
Level 4: 60
Level 5: 100

nExp = cExp + lvl(10)

Level 0-1: 0 + 0 = 0 (Instant Level 1)
Level 1-2: 0 + 10 = 10
Level 2-3: 10 + 20 = 30
Level 3-4: 30 + 30 = 60
Level 4-5: 60 + 40 = 100
Level 5-6: 100 + 50 = 150
Level 6-7: 150 + 60 = 210
Level 7-8: 210 + 70 = 280
Level 8-9: 280 + 80 = 360
Level 9-10: 360 + 90 = 450
Level 10-11: 450 + 100 = 550
Level 11-12: 550 + 110 = 660
Level 12-13: 660 + 120 = 780
Level 13-14: 780 + 130 = 810
Level 14-15: 810 + 140 = 1050
Level 15-16: 1050 + 150 = 1200
Level 16-17: 1200 + 160 = 1360
Level 17-18: 1360 + 170 = 1530
Level 18-19: 1530 + 180 = 1710
Level 19-20: 1710 + 190 = 1900
Level 20-21: 1900 + 200 = 2100
Level 21-22: 2100 + 210 = 2310
Level 22-23: 2310 + 220 = 2530
Level 23-24: 2530 + 230 = 2860
Level 24-25: 2860 + 240 = 3100
Level 25-26: 3100 + 250 = 3350
Level 26-27: 3350 + 260 = 3610
Level 27-28: 3610 + 270 = 3880
Level 28-29: 3880 + 280 = 4160
Level 29-30: 4160 + 290 = 4450
Level 30-31: 4450 + 300 = 4750
Level 31-32: 4750 + 310 = 5060
Level 32-33: 5060 + 320 = 5380
Level 33-34: 5380 + 330 = 5710
Level 34-35: 5710 + 340 = 6050
Level 35-36: 6050 + 350 = 6400
Level 36-37: 6400 + 360 = 6760
Level 37-38: 6760 + 370 = 7130
Level 38-39: 7130 + 380 = 7510
Level 39-40: 7510 + 390 = 7900

Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 1 2013 02:50pm
of all the things that can slow down your game, this isn't going to be one of em.

and since you're just adding the previous value, you're basically using n(n+1)/2. play around with it and adjust it (eg: multiply by 10, offset if necessary, etc)
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Jun 1 2013 02:56pm
Quote (carteblanche @ Jun 1 2013 02:50pm)
of all the things that can slow down your game, this isn't going to be one of em.

and since you're just adding the previous value, you're basically using n(n+1)/2. play around with it and adjust it (eg: multiply by 10, offset if necessary, etc)


Yes, that's essentially my reason for making this post.
I knew this was going to slow down my game, so I was looking for an alternative route that wouldn't require a database to store an Exp per Level chart.
Been working on several different algorithms this morning and my brain just farted out when I got to this one.

You're right though. It is practically n(n+1)/2. I think I know an offset I can use to get the values I want.

The point is to keep the numbers low, while having cost / level increase at an exponential rate.

This post was edited by grievance on Jun 1 2013 02:57pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 1 2013 03:00pm
Quote (grievance @ Jun 1 2013 04:56pm)
Yes, that's essentially my reason for making this post.
I knew this was going to slow down my game, so I was looking for an alternative route that wouldn't require a database to store an Exp per Level chart.
Been working on several different algorithms this morning and my brain just farted out when I got to this one.


No, it wasn't going to slow down your game. your "table" is just a small array, unless you plan on having really high levels (eg: excess of 2^32 - 1) in which case you cannot create an array that big.

This post was edited by carteblanche on Jun 1 2013 03:01pm
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Jun 1 2013 03:12pm
Quote (carteblanche @ Jun 1 2013 03:00pm)
No, it wasn't going to slow down your game. your "table" is just a small array, unless you plan on having really high levels (eg: excess of 2^32 - 1) in which case you cannot  create an array that big.


ahh okay.
I miss read your original post.
Hmm, okay. I guess I'm trying to micromanage just a little too much :P
Thanks for clearing things up for me.

There is no level cap, however i'm very doubtful that any lifetime amount of gameplay could cause a stack overflow.

This post was edited by grievance on Jun 1 2013 03:22pm
Member
Posts: 7,026
Joined: Apr 3 2008
Gold: 1.00
Jun 3 2013 11:51am
do a for loop with javascript, with n being your char level and x the amount of XP needed to get to the next level m=n+1.

Code
var x=0;
var a=0;
var m=n+1;
function myExpNeededToNextLevel(){
   for (var i=2;i<=m;i++){
       a=10*i-10+x;
       x=a;
       if (i==m){
           document.write("Amount of XP needed to get to level" + m + ": is" + x);
       }
   }
}


Then you just want to substract the XP that you already have acquired from x. You get the amount of XP needed to the next level.

That way you don't have to have a table. If I understand well, you are making an online RPG. Just call the function every time the user gets experience points.

Edit: code indent

This post was edited by bail6002 on Jun 3 2013 11:58am
Member
Posts: 4,152
Joined: Oct 2 2006
Gold: 2,117.00
Jun 11 2013 02:41pm
Quote (grievance @ Jun 1 2013 09:12pm)
ahh okay.
I miss read your original post.
Hmm, okay. I guess I'm trying to micromanage just a little too much :P
Thanks for clearing things up for me.

There is no level cap, however i'm very doubtful that any lifetime amount of gameplay could cause a stack overflow.



we could just use a debugger and input our level, because javascript is run clientside :P
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll