Wednesday, 23 February 2022

ARTICLE: Stochastic fantasy combat!

Optimal strategies in the Fighting Fantasy gaming system: influencing stochastic dynamics by gambling with limited resource
Iain G Johnston
European Journal of Operational Research DOI 10.1016/j.ejor.2022.01.039 (2022)

Here's a more unusual one. Fighting Fantasy gamebooks, hugely popular in the 80s and resurgent now, are "games in a book". The reader/player chooses their path through the book's many sections, overcoming challenges, fighting monsters, and hopefully succeeding in their quest.

The combat system is quite interesting. The player and their opponent both have "stamina" -- like the health bar in a video game. The player rolls dice to determine the strength of one of their attacks, and rolls again for the opponent. Whoever has the higher strength inflicts some stamina loss on the other. The combat proceeds through rounds like this until someone's stamina reaches zero.

Phrased like this, the player has no agency and the system is quite easy to solve (ie, work out the probability of winning a given fight). But there's another factor. The player (not the opponent) also has some "luck", describing how lucky they are. Testing luck involves rolling two dice: if the sum is less than or equal to the player's luck score, they are luck, otherwise they're unlucky. If they win an attack round, they can choose to test their luck, and if luck they deal more damage to their opponent. If they lose an attack round, they can also test their luck, and will take less damage if lucky. If they're unlucky, the outcome is negative: they do less, and take more, damage than if they'd not tested.

A bit more complicated, but still possible to solve. But here's the rub. Every time you test your luck, your luck score decreases -- whether you're lucky or unlucky. So as you test your luck more and more, you are less and less likely to get a positive outcome. The question is -- when is it a good idea to use a luck test in combat?

To answer this we used an approach called dynamic programming. We first considered all the ways combat can end -- with someone having no stamina left. We next considered every state of the combat that could lead to one of these end states, and calculated the probability of each possible outcome in the case where the player chose to test their luck and the case where they didn't. We then considered all states of combat that led to these states, and so on, multiplying probabilities as we went to calculate the overall probability of victory from any state given any luck strategy.

We found that judicious use of luck can dramatically increase victory probability in some cases, particularly when player and opponent statistics are unbalanced. There are some general rules -- for example, no matter how low your luck, you should always test if you are otherwise about to die. We used some tools from statistics to distil the complex set of detailed optimal strategies into more general principles to follow. We also connect to more real-world questions, like cheating and espionage, where a "lucky" outcome can be beneficial -- but an unlucky one can be disastrous, and the more you test your luck the more likely you are to be unlucky!

No comments:

Post a Comment