Advertisement

Filtering experience points by an intelligence state

Started by July 11, 2015 03:36 AM
7 comments, last by wintertime 9 years, 6 months ago

Hey everyone,

I'm attempting to write a seemingly simple routine that filters character experience by an intelligence-like character state. The state value will be a scaler ranging from 0 to 1. When experience is earned, the scaler represents how much of that experience is granted to the character, and the remaining experience goes toward repairing the state (scaled by a hardcoded value). Here's some quick code to demonstrate:


// some defines
real REPAIR_SCALER = xxxx;

// some known values
real input_experience = ?;
real char_state = 0 to 1;

// the (incorrect) code
real earned_experience = input_experience * char_state;
real repair_experience = input_experience - earned_experience;
char_state = min( 1.0, char_state + repair_experience * REPAIR_SCALER );

AddCharExperience( earned_experience );
SetCharState( char_state );

The problem with this approach is that there will be a significant difference between earning a bunch of small amounts of experience versus earning a single large amount of experience. Since the state that scales the experience is increasing each time its earned, each epsilon(?) of the experience is changing the amount of experience earned. I could mostly mitigate this issue by iterating through a loop and applying small amounts of experience per iteration, but I was hoping there is a more elegant solution. I've been playing around with pow() and exp(), but math isn't my strongest skill, and I'm having trouble coming up with anything.

If anyone has any advice, it will be greatly appreciated. Thank you.

You state your goal is to "filter" with an "inteliigence-like" state, but that phrase could mean very different things to different people. Can you better describe or define what you want to simulate? That may help you determine better how to design your code, as well as helping others help you. If you provide information on the context (what events result in "input_experience," what the benefit of increased "char_state" is, etc.), you'll likely get better responses.

It appears the code you posted will result in character experience increasing faster with a lot of small events than with one large event. That sounds reasonable if you want to simulate learning from repetition. Can you better describe why that doesn't meet your goal? I.e., a more "elegant" solution can only be suggested if what you're trying to "solve" is known! wink.png

EDIT: If you're trying to get into artificial intelligence, there's an entire forum devoted to that. smile.png

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

You state your goal is to "filter" with an "inteliigence-like" state, but that phrase could mean very different things to different people. Can you better describe or define what you want to simulate? That may help you determine better how to design your code, as well as helping others help you. If you provide information on the context (what events result in "input_experience," what the benefit of increased "char_state" is, etc.), you'll likely get better responses.

The character state decreases for certain reasons in the game, and increases when the character earns experience. There's not much else to the concept. It doesn't need to increase linearly with the experience, but I'm wanting something that increases the experience and repair by the same amount for +5 +5 +5 as it does with +15, and so on.

It appears the code you posted will result in character experience increasing faster with a lot of small events than with one large event. That sounds reasonable if you want to simulate learning from repetition. Can you better describe why that doesn't meet your goal? I.e., a more "elegant" solution can only be suggested if what you're trying to "solve" is known! wink.png

If it increases at different rates based on the size of increments, players will catch on to it, and it adds an unwanted gameplay incentive - if the player's state is low, they must engage in small accomplishments before large ones if they want to earn the most experience. This is something I want to avoid, and the reason I'm asking for help. I'm having troubling coming up with something that results in the same outcome with different size increments, since the state changes along with them.

Is it not possible, maybe? I was thinking it would work similar to the math for frame-independent movement friction. But I haven't been able to make anything work.


I'm wanting something that increases the experience and repair by the same amount for +5 +5 +5 as it does with +15

Why not eliminate character_state as an input to your calculations?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


I'm wanting something that increases the experience and repair by the same amount for +5 +5 +5 as it does with +15

Why not eliminate character_state as an input to your calculations?

It represents the character's ability to learn and develop skills. Things like death and head injuries will reduce it in the game. It is the only major consequence of death, which makes it a pretty important aspect of the game. I'm still working on the exact details, but death may cut it in half, or it may subtract some from it. But the only way to improve or repair it is through earning experience. Players that avoid death are rewarded by earning more experience.

So you believe the math itself is impossible? Is that why you're suggesting I remove it?

Thanks


So you believe the math itself is impossible? Is that why you're suggesting I remove it?

I suggested it because that's the simplest solution that meets the criteria you implied.

If you add the condition that the end character state must be based on the start character state, AND the result must be the same when the total input experience is the same for any number of steps, I would suggest iteration.

You can do that by defining your procedure for an input experience of 1. I.e., make the code you posted into a function, but always use input_experience = 1 as a constant in that function.

Then, when an event occurs with an experience of N, just call the function N times. Each time through the function, the repair and state changes result in a new character state. That new character state will be used the next time you call it. Whether you call it 5 times, then 5 times, then 5 times; or you call it 15 times, the end result will be the same.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

You can do that by defining your procedure for an input experience of 1. I.e., make the code you posted into a function, but always use input_experience = 1 as a constant in that function.

Then, when an event occurs with an experience of N, just call the function N times. Each time through the function, the repair and state changes result in a new character state. That new character state will be used the next time you call it. Whether you call it 5 times, then 5 times, then 5 times; or you call it 15 times, the end result will be the same.

Right, that's what I meant by "iterating through a loop and applying small amounts of experience per iteration". I was just hoping there would be something more advanced that wouldn't require iteration. If there is no such thing, then there's not much that can be done.

I'm open to a completely different algorithm if anyone has an idea that would result in a similar outcome.

Thanks again

A simple way to make things better is not having a continuous function but some discrete points.

E.g. while your status is between 0 and 25%, then 100% of experience goes toward fix the status.
From 25% to 50%, 75% goes towards fixing
From 50% to 75%, 50% goes towards fixing
From 75% to 100%, 25% goes towards fixing
When at 100%, 0% goes towards fixing (obviously)

Then you calculate how much experience did the character to earn up to the next point. If more, apply that and recheck.


Another option could be to remember the worse status the character has been since healthy.
e.g. My char gets a hit to the head and has a 25% reduction of the status. Then wins the combat and experience is shared 75% to XP and 25% towards fixing. It ends with a 21% reduction.

Next fight, another blow to the head, status reduced another 25% (46% total).
If he doesn't get more blows to the head, experience will go 46% to fixing the status and 54% will be real experience, until the status is again at 100%. Since then, all experience will be earned normally.

What you have much alike a geometric series and you have its value for current experience, but want to calculate its value for current experience + gained experience.

You should read up on it, for example, on wikipedia: https://en.wikipedia.org/wiki/Geometric_series

Many of these series have a way to simplify the formula, so you dont need iteration.

This topic is closed to new replies.

Advertisement