Sunday, June 23, 2019

Sometimes, Not Too Random

Randomness of any sort in electronic games is determined by what's called a Random Number Generator, because machines cannot make a decision randomly, they can only approximate randomness.  In a few cases the machine will use an external source to generate an actual random number, such as atmospheric noise or even a lava lamp.  Most of the time they use algorithms to approximate randomness, and that is called a Pseudo-Random Number Generator.

For the most part, they're good.  Sometimes implementations of PRNG can leave vulnerabilities, allowing the user to manipulate the system in ways that are not intended.  PRNG in slot machines for criminal gain, PRNG in cryptography to bypass encryption on computer data, but also PRNG in video games.  In many speedruns, players will take specific number of steps, press buttons in only specific patterns, and listen for sound cues in order to make critical strikes appear on demand, avoid every attack, or have a specific rare item drop, guaranteed.

Most players won't find them, or even particularly care about them, so from a developer standpoint those sort of PRNG vulnerabilities are pointless at best to worry about, to a negative experience if it were fixed.  The vast majority of the time those vulnerabilities exist only in closed systems in a one-player environment, at which point however they enjoy playing the game is entirely up to them.

A more interesting potential of PRNG when it comes to video games, is having the randomness be not too random.

Valve implemented a system on top of their PRNG in Dota 2, in order to make their competitive game less vulnerable to overly large lucky or unlucky streaks.

On melee heroes, Skull Basher icon.png Skull Basher's Bash has a 25% chance to stun the target. On the first attack, however, it only has an ~8.5% probability to bash. Each subsequent attack without a bash increases the probability by ~8.5%. So on the second attack, the chance is ~17%, on the third it is ~25.5%, etc. After a bash occurs, the probability resets to ~8.5% for the next attack. These probabilities average out so that, over a moderate period of time, Bash effect procs nearly 25% of the time.
What this meant was that no longer could there be games where you'd get a bash four times in a row, get a crucial kill, and win the game.  On the other hand, neither would you have a game where your basher never activated, leaving you to wonder if the stupid thing is actually bugged.

Likewise, Grinding Gear Games and Path of Exile has the same sort of system with Evasion, but in that they implement an entropy system.  Everytime you evade an attack, your evasion is lowered until you're hit.  If your evasion comes out to be 90%, that means on average you will have evaded 90% of the attacks.  Evasion as a stat felt far more useful and, importantly, reliable.

There are some key things to take away from these anecdotes of pseudo-pseudo-RNG.  When you're playing a video game and something that happens on a very low percentage chance, fails to occur for a very long time, it is a real possibility that there is a bug in the game.  In real life, you don't have to worry about programming glitches keeping you from rolling well in a board game, but in video games you do.

Another thing to keep in mind is that randomness averages out to certain numbers over the span of many iterations.  Depending on what you're implementing and how often it's likely going to actually occur during the game, those iterations may not occur anywhere needed enough for the randomness to actually average out.  A 25% chance for something to drop, and the player hasn't gotten it in 20 tries?  That's needlessly frustrating if it takes about half an hour for each attempt, but it's something that absolutely can happen with randomness.  There's no particular reason why that player would be overjoyed when the item finally drops since the expectation was for the drop to have happened a long time ago.  A key point here is managing the expectations of your players.

In addition, having core mechanics in a game feel reliable is also very attractive to a player.  If it's something core, you want to rely on it.  Button presses need to always do what you expect them to do, movement in an action game should not be an unsure experience.  The same extends to anything that is core to your game.  So if there's something core in your gameplay that has an element of randomness, consider stacking the deck a bit and not truly leaving it up to chance.

All in all, you don't need to implement these systems for every aspect of your game, and there certainly are times and places where being ridiculously lucky or unlucky has a certain appeal and makes for a great story.  That said, there are places in your game where you don't want to gamble big.  So gamble small, constrict your variances in RNG, or just flat out shape the data the way you want, so that you get the effect you want.

Fiddling with numbers can change a lot, after all.

No comments:

Post a Comment