Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

Useful mathematical functions for game systems designers

mihai

Educated
Joined
Jun 28, 2017
Messages
45
Location
germany
I would actually love to see some distributions used more often in games. For example, the Poisson distribution fits perfectly for damage calculation. It has a single, easy-to-compare rate (which is also its expectation value), so no fiddling with different numbers or limited types of dice. With higher rates, the standard deviation increases more slowly, as you would think of a better-quality weapon or increased skill or attribute.

You wouldn‘t calculate that in pen&paper, but when a computer does it for you and graphically shows you the resulting probability distribution, it would be intuitive. For me at least.
 
Unwanted

Savecummer

Latest Doxxer Account
Edgy
Joined
Mar 6, 2021
Messages
330
I would actually love to see some distributions used more often in games. For example, the Poisson distribution fits perfectly for damage calculation. It has a single, easy-to-compare rate (which is also its expectation value), so no fiddling with different numbers or limited types of dice. With higher rates, the standard deviation increases more slowly, as you would think of a better-quality weapon or increased skill or attribute.
Wat, Poisson is just crippled Normal...
Damage calc example with Poisson and 3 different weapons, pl0x - I dont see the advantage at all. Looks to me like massive extra complexity for no reason, also less features (standard deviation tied to rate in poisson) than a Normal... ie 3 dice...
The Rate doesnt seem enough to define a weapon's damage. If you apply the distribution to the damage spread, than you need to apply the PMF somehow too.
Programmatically, you only have rand() to pull random numbers, so you would have to transform the rand() result with some kind of a table representing the PMF with normalized k?

RvqRJHG.png

1vIhi39.png

Eg, rate goes from 50 to 100 and your SD increases from 7 to 10...
7/50 is 0.14 and 10/100 is 0.1 - big deal... while doubling the rate

Another FAIL of complexity for no reason!
 
Unwanted

Savecummer

Latest Doxxer Account
Edgy
Joined
Mar 6, 2021
Messages
330
I am pretty smart, but just like Lyric Suite my age is making me senile... I dont konw what I once didnt even know...
 

mihai

Educated
Joined
Jun 28, 2017
Messages
45
Location
germany
Another FAIL of complexity for no reason!

please don't be rude, there is always the possibility of misunderstanding.

Here, poisson is all about small numbers. I like granularity in games, maybe that's from the pen and paper area, or that first levels of the characters that are always the most fun (for me). It's always fun to decide to distribute 3 points here or there, it makes a difference. 50 Points? I don't care anymore.

Of course poisson converges to normal for anything > 30, that's not the point. But what if you want to have a damage rate of 6, with a wide spread? Or 1.5? It gets problematic if the standard deviation would produce negative values, you need to skew the probability, clip the results, renormalize, think of extreme cases.

For me it's always fun to hope for an unprobable, but possible result. That's the regime of criticals, with extra rules, and difficult to intuitively grasp. But in a poisson distribution? It's just included. Example:

https://ibb.co/xD5Hh7W
(sorry, posting the image didn't work)

One function to rule them all, not more difficult at all. And for today's CPU's, come on, the overhead for a couple rolls will be difficult to notice. From a programmer's perspective, just a std::poisson_distribution() away.
 

J1M

Arcane
Joined
May 14, 2008
Messages
14,626
Trying to improve the 'feel' of rolls with a distibution is a smooth-brain move.

To make a real attempt at that you'd want to use something like Pink Noise as a starting point.
 

mihai

Educated
Joined
Jun 28, 2017
Messages
45
Location
germany
Thanks. Another idea: „fair world RNG“.

It has been brought up, but I don‘t know if ever implemented.

In reality, random values are independent of previous history. Flipped a coin 5 times with the same result? Sorry, still 50% next time. Missed three times in a row? RNG from hell. Even if it‘s realistic, it doesn‘t feel fair. Some unlucky rolls can mess up your otherwise sound strategy (example: Battle of Wesnoth).

But we can rig the game, make it feel fair. Keep track of rolls, and to what degree they were good or bad for the player (and each side). Draw from a limited „pool of balance“. Got bad luck? Will be compensated soon. Or even have spells or abilities to manipulate your luck, for this one important moment - you can deal with repercussions later. Basically Karma.

And: savescumming becoming a meta-strategy.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
That would be no random number but only distributing a static set of numbers over time.

And considering that if you had a good run you would then know in advance you get good dice rolls or vice versa, this is not what I consider fun.

Also reality does not work like that at all, and some people have already won millions in the lottery at least twice.
 

Zuurix

Arcane
Developer
Joined
Feb 14, 2021
Messages
42
Just don't make combat that relies on good RNG so much and it'll be fine.
 

lukaszek

the determinator
Patron
Joined
Jan 15, 2015
Messages
12,672
Thanks. Another idea: „fair world RNG“.

It has been brought up, but I don‘t know if ever implemented.

In reality, random values are independent of previous history. Flipped a coin 5 times with the same result? Sorry, still 50% next time. Missed three times in a row? RNG from hell. Even if it‘s realistic, it doesn‘t feel fair. Some unlucky rolls can mess up your otherwise sound strategy (example: Battle of Wesnoth).

But we can rig the game, make it feel fair. Keep track of rolls, and to what degree they were good or bad for the player (and each side). Draw from a limited „pool of balance“. Got bad luck? Will be compensated soon. Or even have spells or abilities to manipulate your luck, for this one important moment - you can deal with repercussions later. Basically Karma.

And: savescumming becoming a meta-strategy.
this is why people do not trust rng
 

Norfleet

Moderator
Joined
Jun 3, 2005
Messages
12,250
I would actually love to see some distributions used more often in games. For example, the Poisson distribution fits perfectly for damage calculation.
Actually, in the real world, damage is more of a Pareto distribution, where the majority of the damage is caused by the minority of the hits, where 80-90% of the damage is actually caused by 10-20% of the hits. This seems to consistently apply whether you're dealing with creatures or vehicles, unarmored or armored: the majority of the hits will inflict superficial damage, with only a minority of the hits that will strike a vital organ or component.

This is just as true in fiction outside of games: Most shots fired will do nothing except shatter some glass or create holes in the car, then one shot suddenly causes the entire thing to blow up. Most shots do nothing except inflict dramatically bleeding injuries, then one shot will suddenly mortally wound the hero's sidekick.

But we can rig the game, make it feel fair. Keep track of rolls, and to what degree they were good or bad for the player (and each side). Draw from a limited „pool of balance“. Got bad luck? Will be compensated soon. Or even have spells or abilities to manipulate your luck, for this one important moment - you can deal with repercussions later. Basically Karma.
The real reason that random rolls tend to "feel" off on an intuitive level is because successive attempts at a task in the real world are not generally random. Thus when a soldier shoots at the same enemy 3 times at a listed chance of 50% and misses all 3 shots, each increasingly more wildly than the last, it feels off because that's not how aiming really is like in the real world: You aim, you shoot, you correct, whereas in the archetypical example, the X-Com Trooper shoots and each shot misses even more outlandishly rather than zeroing in. This intuition that re-attempting a task should result in progress towards it is what interferes with the sense of randomness, because independent randomness is actually the wrong model for the job.

Gamblers, similarly, conflate this idea because they intuitively believe that there is some kind of "skill" involved in what they're doing, when, in fact, it might actually be totally random, meaning each subsequent attempt is not actually making you any better at this and it is therefore pointless to even try because you will do no better the second time than you did the first.
 
Last edited:

Alpan

Arcane
Patron
Joined
Mar 4, 2018
Messages
1,340
Grab the Codex by the pussy Pathfinder: Wrath
The following YouTube playlist is pretty useful for game math (Infinitron feel free to embed to the OP):

 

mihai

Educated
Joined
Jun 28, 2017
Messages
45
Location
germany
I would actually love to see some distributions used more often in games. For example, the Poisson distribution fits perfectly for damage calculation.
Actually, in the real world, damage is more of a Pareto distribution, where the majority of the damage is caused by the minority of the hits, where 80-90% of the damage is actually caused by 10-20% of the hits. This seems to consistently apply whether you're dealing with creatures or vehicles, unarmored or armored: the majority of the hits will inflict superficial damage, with only a minority of the hits that will strike a vital organ or component.

This is just as true in fiction outside of games: Most shots fired will do nothing except shatter some glass or create holes in the car, then one shot suddenly causes the entire thing to blow up. Most shots do nothing except inflict dramatically bleeding injuries, then one shot will suddenly mortally wound the hero's sidekick.

But we can rig the game, make it feel fair. Keep track of rolls, and to what degree they were good or bad for the player (and each side). Draw from a limited „pool of balance“. Got bad luck? Will be compensated soon. Or even have spells or abilities to manipulate your luck, for this one important moment - you can deal with repercussions later. Basically Karma.
The real reason that random rolls tend to "feel" off on an intuitive level is because successive attempts at a task in the real world are not generally random. Thus when a soldier shoots at the same enemy 3 times at a listed chance of 50% and misses all 3 shots, each increasingly more wildly than the last, it feels off because that's not how aiming really is like in the real world: You aim, you shoot, you correct, whereas in the archetypical example, the X-Com Trooper shoots and each shot misses even more outlandishly rather than zeroing in. This intuition that re-attempting a task should result in progress towards it is what interferes with the sense of randomness, because independent randomness is actually the wrong model for the job.

Gamblers, similarly, conflate this idea because they intuitively believe that there is some kind of "skill" involved in what they're doing, when, in fact, it might actually be totally random, meaning each subsequent attempt is not actually making you any better at this and it is therefore pointless to even try because you will do no better the second time than you did the first.

Very good points, thanks! So every repetitive task with the chance of feedback and readjustment should actually improve chances. That is an interesting game dynamic, could be connected to intelligence or specific skills. And produce opportunities to make situational decisions: do I use a high-repetition or high-damage weapon?. But it would need to include to what degree a situation is really repetitive - if a target starts to move or behave differently, that could reset this auto-improving aim.

About the pareto distribution, I don't really know. Remember the early Realms of Arcania games? Really frustrating not to hit or to do no damage most of the time... maybe one should reduce it to interesting events for a game. But maybe one can use low-damage hits in other ways, like reduce stamina for a successful block, or imbalance the opponent for the next strike.
 

Norfleet

Moderator
Joined
Jun 3, 2005
Messages
12,250
But we can rig the game, make it feel fair. Keep track of rolls, and to what degree they were good or bad for the player (and each side). Draw from a limited „pool of balance“. Got bad luck? Will be compensated soon. Or even have spells or abilities to manipulate your luck, for this one important moment - you can deal with repercussions later. Basically Karma.
As an alternative to random numbers at all, you could turn it into a card game, where each player is dealt a hand of cards to play and doesn't get a new set until he uses every card. This essentially turns high and low rolls into a resource to manage, increasing player agency. So if the player attacks another character, the player chooses what value he will play from his deck for his attack roll while the defender does the same for his defense roll...whoever then gets the higher value after modifiers wins, perhaps more or less depending on the degree of success. This leaves it up to the player to decide how much from his resource pool to invest: All in, fold, etc. The results are still kinda random-ish, but now player has a sense of agency. The drawback is that this drags down the pace of play if the number of actions and counter-actions are many, but if you have MANY such actions, the result would have been a spam of random numbers that turns into statistical average anyway, and the point of using randomness at all is largely lost.

About the pareto distribution, I don't really know. Remember the early Realms of Arcania games? Really frustrating not to hit or to do no damage most of the time...
Not hitting isn't damage, though. If you miss, you just don't do any damage at all.

maybe one should reduce it to interesting events for a game. But maybe one can use low-damage hits in other ways, like reduce stamina for a successful block, or imbalance the opponent for the next strike.
The concept I proposed above sort of is like that, I guess. Since rolls become a resource pool, intentionally using low-yield attacks as feints to draw your opponent into burning high-value rolls to counter low-value attacks is now a strategy. If you use a 2 to fail against an opponent's 20, you've traded a low-value roll for a high-value one and thus unbalanced your opponent/depleted his stamina. You've failed your attack, but now instead of being a frustrating miss, it's a just-as-planned.

But it would need to include to what degree a situation is really repetitive - if a target starts to move or behave differently, that could reset this auto-improving aim.
This ties into natural player behavior as well. Just as frequent in X-Com is the way an alien will bullseye you out of nowhere even as you take evasive action. This is because the alien, similarly, is not undergoing this process, and thus you don't get a chance to do exactly that in an attempt to throw your opponent. In fact, nothing you do helps! But what if it did, precisely because it disrupts that process above? This promotes a kind of naturalistic play: When you first come under fire, the enemy is firing cold, without having found the range. You should probably take cover before he does! However, if you cower behind that same place too long, the enemy mortar might find his range. Better move!
 
Last edited:
Unwanted

Savecummer

Latest Doxxer Account
Edgy
Joined
Mar 6, 2021
Messages
330
that's not the point. But what if you want to have a damage rate of 6, with a wide spread? Or 1.5?
You cannot do variable "spread" with poisson, breh... That was my point about limited features vs normal. As far as I see, spread/SD is tied to rate, thats the defining characteristic of poisson.
5bokA3K.png

lfUvVqS.png

If you want to pull numbers from this, you have to fix one variable in place, either lambda (rate) or k. k is preferable of course.

Also, you gave 3 examples of the distribution, but I wanted precise examples of a 3 weapons. Ie I am interested in seeing HOW you want to implement pulling the numbers from the distribution.
I'd like to see the programmatic logic.
 

LannTheStupid

Товарищ
Patron
Joined
Nov 14, 2016
Messages
3,195
Location
Soviet Union
Pathfinder: Wrath
1. Card games are abhorrent. (C)RPG's should use the dice.
2. The problem with XCOM-like hits was solved in Phoenix Point that uses the simulation approach. It automatically enables not only point blank shotgun shots for massive damage, but friendly fire as well, which is awesome.
 

mihai

Educated
Joined
Jun 28, 2017
Messages
45
Location
germany
that's not the point. But what if you want to have a damage rate of 6, with a wide spread? Or 1.5?
You cannot do variable "spread" with poisson, breh... That was my point about limited features vs normal. As far as I see, spread/SD is tied to rate, thats the defining characteristic of poisson.
If you want to pull numbers from this, you have to fix one variable in place, either lambda (rate) or k. k is preferable of course.

Also, you gave 3 examples of the distribution, but I wanted precise examples of a 3 weapons. Ie I am interested in seeing HOW you want to implement pulling the numbers from the distribution.
I'd like to see the programmatic logic.

I think you misunderstood me. The spread is fixed and is fine as it is. The only parameter is lambda (you could maybe add a constant to the result for higher, lower-varying levels).

About your question: you plotted the formula for the probability distribution, to draw actual numbers you have to chose an appropriate algorithm. I'm no expert, but in this case, there are different algorithms optimal for different ranges of lambda. For small (<30) lambda, "Knuth's" algorithm is quite good: transform random numbers to arrival times (via 1/lambda, exponentially distributed), add them up (and count how many) until integration time is reached. For lambda >30, there are better algorithms. This is a solved problem (best algorithms automatically chosen) and I wouldn't reinvent the wheel here. Look at the c++ standard library (std::poisson_distribution) for a good implememtation, it comes with your compiler for free. I just tried it on Matlab, 1 Million numbers were drawn in 0.5s on my old laptop. You will barely need a couple per combat round, so we are talking about some microseconds. Compared to e.g. cache misses when fetching some data from memory, this is trivial.

wiki on poisson generation: https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables

[edit:] example, generating 10000 numbers and showing their histogram: https://en.cppreference.com/w/cpp/numeric/random/poisson_distribution
 
Last edited:

Jamesmorris

Barely Literate
Joined
Jan 26, 2022
Messages
4
I would never have thought that I could use math functions in my work
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom