I am making a text-based RPG. I have an algorithm that determines the damage dealt by the player to the enemy which is based off the values of two variables. I am not sure how the first part of the algorithm will work quite yet, but that isn't important.
(AttackStrength
is an attribute of the player that represents generally how strong his attacks are. WeaponStrength
is an attribute of swords the player wields and represents generally how strong attacks are with the weapon.)
Here is how the algorithm will go:
import random
Damage = AttackStrength (Do some math operation to WeaponStrength) WeaponStrength
DamageDealt = randrange(DamageDealt - 4, DamageDealt + 1) #Bad pseudocode, sorry
What I am trying to do with the last line is get a random integer inside a range of integers with the minimum bound as 4 less than Damage, and the maximum bound as 1 more than Damage. But, that's not all. I want to assign probabilities that:
- X% of the time DamageDealt will equal Damage
- Y% of the time DamageDealt will equal one less than Damage
- Z% of the time DamageDealt will equal two less than Damage
- A% of the time DamageDealt will equal three less than Damage
- B% of the time DamageDealt will equal three less than Damage
- C% of the time DamageDealt will equal one more than Damage
I hope I haven't over-complicated all of this thank you!