0
\$\begingroup\$

I'm currently in the process of making a scoreboard for my game. One of things I would like to display is the players accuracy in the amount of hits they had in game. However, I have never done this before and I've no idea how to go about doing this.

Is there a commonly used algorithm out there that can help me calculate this, or has someone found a way to calculate this fairly easily?

Any help with this would be appreciated.

\$\endgroup\$
4
  • \$\begingroup\$ ShotsHit / ShotsFired * 100? Or did I mis-understand the question..? \$\endgroup\$
    – user9790
    Commented Dec 6, 2012 at 9:33
  • \$\begingroup\$ @JaakkoLipsanen Nah I think that's just it, you should post this as answer. \$\endgroup\$ Commented Dec 6, 2012 at 9:43
  • \$\begingroup\$ The 'algorithm' is just the addition of one to the accuracy variable, executed on every hit, i.e. accuracy++;. \$\endgroup\$ Commented Dec 6, 2012 at 12:16
  • \$\begingroup\$ -1 If you have to ask how to calculate a percentage, you've definitely not done enough research. \$\endgroup\$
    – Anko
    Commented Dec 6, 2012 at 21:35

2 Answers 2

2
\$\begingroup\$

As I already mentioned in the comments, it's simply just:

float hitAccuracy = ShotsHit / ShotsFired * 100;

Basically just every time the player fires a shot, increment ShotsFired by one and if the shot hits the target, increment ShotsHit by one.

Of course, there's one problem with this. If Player A fires 100 shots of which 99 hits the target, he would lose to someone who has shot only one shot which hitted the target. This is not necessary a problem, but if it is, could you give us more details about your game?

\$\endgroup\$
3
  • \$\begingroup\$ Depending on the type of ShotsFired and ShotsHit you might want to cast them first to avoid integer division. Also I don't consider the number of shots fired being an issue. Such games usually show both values and only consider values for rankings, if a given minimum number of shots have been fired. One more thing to note, which might be more serious issue: If you're able to hit multiple targets, it's possible to get more than 100% (or back to 100%) rather easy (prominent example: Battlefield 3's shotguns). \$\endgroup\$
    – Mario
    Commented Dec 6, 2012 at 11:07
  • \$\begingroup\$ @Mario: Why? If you hit two targets with one shot, ShotsHit would be incremented by one, or the variable ought to be renamed TargetsHit. \$\endgroup\$ Commented Dec 6, 2012 at 12:11
  • \$\begingroup\$ Ah, you're right. Thought about counting actual hits rather than shots that hit. \$\endgroup\$
    – Mario
    Commented Dec 6, 2012 at 12:40
-1
\$\begingroup\$

it depends on how much of each hit the timing is, if it shows marvelous or perfect on all of the shots, it is 100% accuracy, there is usually 5 or 6 ratings, from most timed to least timed, the least would be a miss, and the more of a certain timing the less the accuracy would be, all greats, would not be the same accuracy as like an all perfect or an all marvelous.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .