score calculation

Started by
7 comments, last by ToohrVyk 16 years ago
okay i have a game where i want to calculate a score for each player. How ever i i have some stats that I want to drag the score down. so i have: number of hits (more is good) number of shots fired (more is bad) number of deaths (more is bad) number of pickups (more is good) number of waves before running out of lives (this is most important score factor, higher is better) i want to avoid the player getting a negative score as well. So how can i calculate a score value from this with this constraints? so far i've got something like this: score = float(hits) / float(shotsFired) * 100.f + pickups * 10.f + 100.f / float(deaths);
Advertisement
Usually I hate money, but at times, I feel that money is important :D
Almost all the important things in our life has got some weight in terms of money.

Health 100,000/- per annum Food 20,000/- per annum
////////////////////////////


assign some weights to each thing..

for one hit, score += 100; // 100 is the weight for hit
for one shot, score -= 50; // 50 is the weight for shot. u can change it.
since, more is bad, it is -=, instead of +=. The more shots u get, the lesser your score will be
for a death, score -= 1000; // same as shot
for a pickup, score += 500; // same as hit.


The summary...

1) assign weights for each thing
2) if more is good, use += and if more is bad, use -=

[Edited by - Saughmraat on March 20, 2008 5:50:49 AM]
Gents nandu Intelligents veyrayaa
using simply + and - you can get negative scores :-/

i've now got something like this:

// factor modifier to score for each wave	// up to 100 points for high accuracy	// up to 100 points for no deaths	// up to 100 points for pickups	int accuracyScore = float(hits) / float(shotsFired) * 100.f;	int pickupScore = ((1.f - (1.f / Math::Max(1.f, pickups * 0.3f))) * 100.f);	int deathsScore = 100.f / float(deaths);	int score = (accuracyScore + pickupScore + deathsScore) * waveReached;
i want to avoid the player getting a negative score as well


:( I didn't notice that :( :(
Gents nandu Intelligents veyrayaa
Quote:Original post by supagu
so far i've got something like this:

score = float(hits) / float(shotsFired) * 100.f + pickups * 10.f + 100.f / float(deaths);


You could have 0 shots fired and 0 deaths. Either of these will result in a division by zero error.

Are you awarding the score during a level or just at the end? If you are awarding during play, then you can just add or subtract values, ensuring that you total never falls below zero. e.g.
if ( score > penalty ) score -= penalty;

I would also break down your calculation into smaller steps. This will help you to avoid errors, and balance it a little more.

e.g.

if ( shotsFired > 0 )
{
hitRatio = hits / shotsFired;
}

pickupBonusScore = PICKUP_BONUS * pickupsCollected;

killedPenalty = KILL_PENALTY * numTimesKilled;

totalScore = hitRatio * HITS_BONUS;
totalScore += pickupBonusScore;
totalScore -= killedPenalty;

if ( totalScore < 0 ) totalScore = 0;
you could use percentages for the subtraction

for each action that has a penalty just subtract x percent of score

so lets say each penalty is 10% off of score
and the total score from all the positives = 500;

500 - 10% = 450
450 - 10% = 405
405 - 10% = 364.5 or round it off
and so on

then you should never hit 0
and just to be safe you could clamp the score to 1.0 if it falls below 1.0 or clamp it to 0.0 if it falls below 1.0

just and idea
Is it conceivable to determine a maximum value for the short fired and death counts ? Then you could calculate an always positive score with something like (maxDeathCount - deathCount).
And if the player exceeds the max count, he's not eligible for appearing in the hall of fame! "You were sooo bad."
Quote:Original post by OldProgie2
Quote:Original post by supagu
so far i've got something like this:

score = float(hits) / float(shotsFired) * 100.f + pickups * 10.f + 100.f / float(deaths);


You could have 0 shots fired and 0 deaths. Either of these will result in a division by zero error.
A simple +1 would fix this issue (assuming it's impossible to have a negative shot fired and death count):
score = float(hits) / float(shotsFired+1) * 100.f + pickups * 10.f + 100.f / float(deaths+1);
Or whatever small value over 0.
score = float(hits) / float(shotsFired+1) * 100.f + pickups * 10.f + 100.f / float(deaths+1) + waves*1000;

Just to add divide-by-zero protection. Something along those lines is what I would do if there is a mjor issue with negative numbers.
I could propose:

exp(A * shots + B * hits + C * deaths + D * pickups + E * waves);


Select your A, B, C, D and E factors carefully to obtain the correct proportions you wish to get. In practice, firing a shot multiplies your score by exp(A), hitting with a short multiplies it by exp(B), dying multiplies it by exp(C), picking up something multiplies it by exp(D), and passing a wave multiplies it by exp(E).

This topic is closed to new replies.

Advertisement