problem with mechanic design for hits and misses

Started by Sierrus, May 23, 2014, 10:41:41 am

Previous topic - Next topic

Sierrus

Hello everyone,

I'm currently fiddling around with the mechanics behind a turn based battle system.
At the moment I'm clueless about how to handle the mechanic of desciding between hits and misses.


The default is to just compare rand(100) with your hit rate.
I was not too fond of this version, as it felt too "binary", literally hit-or-miss.
Need to roll a 95 or less to hit but get a 96? too bad, you get nothing.

The next step was to have multiple partial attack attempts. Depending on the relevant stats the game would basically iterate over 3 to 20 hit rolls and sum the positive results up; 5 confirmed hits would do 100% damage compared to the normal system, 2 hits 40%, etc.
This falls apart with more hit attempts as it becomes statistics instead of some degree of luck.

The third (and current) version... not nearly as easy explained.
First rand(hit_attempts*100) is called.
The result is then compared to expected_hit_rate * 100 and biased towards the expected hit rate via modelling on a square-root function.

maybe the code helps...
values are multiplied by 10 to increase precision
def number_confirmed_hits(hit_rate = 100, max_hits = 10)
    n = 1.0 * rand(10 * 100 * max_hits+1)
    c = 10.0 * 100 * max_hits
    d = 10.0 * hit_rate
    if n > d
      result = c-(c-d)*(Math.sqrt(1.0*(c - n)/(c-d)))
    else
      result = d*Math.sqrt(1.0*n/d)
    end
    return Integer(result/1000)
end


The problem with this version is the real hit chance; a simple test (100k iterations over the function) with hit_rate = 30 and max_hits = 10 only had 3% misses. Which is a problem if I consider that I added some passive abilities that should be triggered on a miss...


What I want is a way that:
-is not binary hit or miss
-allows for a real rate of misses if the hit rate is bad (some passive abilities are triggered on a miss)

Currently I'm clueless as to how to progress towards that goal.

KK20

I honestly have no idea what you're doing. An attack can only hit or miss--it's a binary constant that you can't change.
What is a "real rate of misses"? You have to explain terms that you make up.
Your third algorithm makes no logical sense: If I attack 10 times and have a 30% chance of hitting, I'm expecting to hit, on average, 3 of my 10 attacks, not 9.7 of them.

Plus, why are you even overthinking this? This is a one-time calculation that takes 0.0001 of a second that the player could care less about.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Sierrus

By the default algorith it's only hit or miss, true, but I don't see why I shouldn't change something when I see a problem with it.
E.g. a dex-based character would probably only have 1 or 2% more chance to hit an enemy than a str-based char; when a player won't notice that difference, why have dex in the first place?
So I tried to allow "partial" hits, a high-dex character would get more of those compared to a str-based character.
Mechanics wise it's multiple (invisible) attacks; in-game it would model e.g. how deep a cut is; just scratched the surface or a deep cut that hit a vital organ.

real rate of misses - real in the sense that it can actually happen; at 30% chance per hit to land a hit over 10 attempts I would have about 2-3% chance to completely miss.
I don't know how to phrase it better; what I want is that, given a "low" hit chance (from low dex, inaccurate weapon/skill and/or evasive enemies) that a miss can actually happen.

Maybe I copied something wrong but at testing (30% chance, 10 hits, 100000 repetitions) I got 3% misses, about 30% 3 hits and the rest spread around.

Why I am overthinking it? ... no real reason, just that at this point hit rate was mostly static; quite a lot of calculations for something that would more often than not end up in the range of 92-95%, with dex having as good as no influence over it.
Changing the hit rate calculation of course resulted in hit rates that would not be tolerable for most player. (<95%)
Multiple partial hits might have helped against that problem, but with increasing number of hits it became basically a certainty instead of a chance, and then you get to fun stuff like status effects where the ability for misses would be a bit more welcome... for poison to always land should be ok but heavier stuff like paralyze on the whole party not so much.

KK20

QuoteBy the default algorith it's only hit or miss

*By the definition of natural physics
Quotein-game it would model e.g. how deep a cut is; just scratched the surface or a deep cut that hit a vital organ.

That's called damage variance. This is probably what you are confusing your question with. Hit rate is a 1 or 0 value: you either hit your target or miss--there is no such thing in-between. Damage variance has range--it's unbound by constant restrictions.

What you're aiming for is not a hit rate calculation but a variance calculation (a chance of 0 out of 10 can be the weakest possible hit you do rather than completely missing). You should write a separate hit rate algorithm instead.

Your alternate solution would be to keep what you have but generate a range of ratios that would be considered a miss (e.g. you have to land 3 of the 10 to even score a weak hit, anything less is a miss). This all still falls back to basic probability which is inevitable. It also means defining each and every skill/weapon to be configured with different ratio levels.

I also notice you keep talking about DEX but it's not being shown at all. Have you tampered with the damage formula yet to make DEX more appealing?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Sierrus

Quote from: KK20 on May 24, 2014, 08:02:59 pm
Quotein-game it would model e.g. how deep a cut is; just scratched the surface or a deep cut that hit a vital organ.

That's called damage variance. This is probably what you are confusing your question with. Hit rate is a 1 or 0 value: you either hit your target or miss--there is no such thing in-between. Damage variance has range--it's unbound by constant restrictions.

What you're aiming for is not a hit rate calculation but a variance calculation (a chance of 0 out of 10 can be the weakest possible hit you do rather than completely missing). You should write a separate hit rate algorithm instead.

I should have expected it to be the wrong term...
well, then I've combined variance and hit rate into one calculation. Or rather not; hit rate is calculated before (alongside a number of possible hits), the problem is what I do with them.

Quote from: KK20 on May 24, 2014, 08:02:59 pmI also notice you keep talking about DEX but it's not being shown at all. Have you tampered with the damage formula yet to make DEX more appealing?

Well, yes, that's where the hit_rate comes from.

I've basically removed the entire original damage and hit rate calculation and replaced them; whatever dex and agi did is now handled by dex alone (turn order, hit/miss, crits, basic hit count, damage for dex-weapons),
agi was remade as stamina (basically defense against str/dex-based damage + determines duration of status effects) as well as added wisdom (defense against int, powers healing, involved in resisting a status effect completely)

As for hit rate itself, I'm changing parts of it from time to time; basically if attacker.dex equals defender.dex he has about 60% chance to hit, at double 95% (cap) at half about 40%; a dex-based character would have about 20-30% more dex than a str-based character which would be about 70-75% hit rate if the str-based one has 60%.
Plus variance for skill-hit-rate, evasion and a reduction if the defender used the defend command last turn.

KK20

It already sounds like you know what you're doing and have it done. Seriously, don't kill yourself over something so menial.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!