Home > Modeling RPG-style combat
Modeling RPG-style combat
Following on to yesterday's post about economics, I'd like to present this brief note about how to model role-playing game (RPG) style combat easily with math.
Anyone familiar with Dungeons and Dragons will recall the very tortured set of combat tables broken out by class and level. A simpler method for resolving combat is found in Freeciv.
Assuming a two party combat, you create two attributes for each member: an attack stat and a defense stat. In this system, the bigger the number, the better.
To determine the chance of an attacker hitting the defender, use the following formula:
P(hit) = Attacker->att/(Attacker->att + Defender->def)
This is to say, the chance of an attacker hitting a defender is the proportion of the attacker's 'attack' stat over the sum of the attacker's attack stat plus the defender's defense stat.
If the attack succeeds, some amount of damage is subtracted from the defender's health stat.
I like this formula because it is simple and scales well to opponents of wildly differing strengths.
Attack and defense stats must be greater than 0.
Hope this helps.