Advanced math in game design: random walks and Markov chains in action

Sept. 14, 2023
None
,

Hello everyone, my name is Lev Kobelev, I am a Game Designer at MY.GAMES. Advanced knowledge of mathematics is rarely considered strictly necessary for game designers — or, if it is required, school level is enough. And that’s true in most cases. But sometimes, knowing certain concepts and methods from advanced mathematics can make life easier and help you look at some problems from a different angle.

In this article, we’ll analyze two mathematical concepts: Markov chains and random walks. I’ll note upfront that this article is more «popular» than «scientific», so, some things about how the formulas are derived will be omitted.

After the theory, we’ll discuss example cases where these tools might come in handy, for example:

  1. The number of chests the player will open if more chests can come out of the chests

  2. The amount of gold to be spent pumping up a sword, if the sword can break

  3. The probability of winning a cash match

Alchemist’s problem

First up, let’s imagine a game where we play as an Alchemist. Our task is collecting ingredients for a new potion:

Ingredient

Location

Grassweed

Chess Field

River Meteorites

Space River

Seirreb

Troll’s Loo

The unique thing about this: roads between our locations can lead us to multiple, randomly selected, destinations.

We’ll denote the roads as follows: (location A → location B: the probability of moving from location A to location B):

  1. House → Chess Field: 0.8

  2. House → Troll's Loo: 0.2

  3. Chess field → House: 0.5

  4. Chess Field → Troll's Loo: 0.3

  5. Chess Field → Space River: 0.2

  6. Troll's Loo → House: 0.5

  7. Troll Loo → Chess Field: 0.2

  8. Troll Loo → Space River: 0.3

  9. Space River → Chess Field: 0.5

  10. Space River → Space River: 0.5

Please note: the sum of all destination probabilities from each location equals 1. If the sum is less than 1, then the difference is the probability of transition from A to A. And if it’s more, something definitely went wrong.

The Alchemist goes to get the ingredients. The question: what is the probability that, after two moves, he’ll be at Space River?

There are two possible paths to the river, consisting of two moves:

  1. House → Chess Field → Space River: 0.8 ⋅ 0.2 = 0.16

  2. House → Troll’s Loo → Space River: 0.2 ⋅ 0.3 = 0.06

So, the probability the alchemist will be at the River is 0.22.

Okay, what if we want to know the probability he’ll be at his house after 10 moves? After 100? This takes a lot of calculation, and that’s where Markov chains come to the rescue!

Markov chains

Let’s introduce the following symbols:

  • S is a finite multitude of states. In our case, this is a multitude of locations: {House, Chess Field, Troll's Loo, Space River}.

  • Xi is the state after the i-th transition, Xi ∈ S.

  • Move is a change of state Xi to Xi+1 with a given probability.

  • Stochastic process is a set of states {X0 , X1 , X

JikGuard.com, a high-tech security service provider focusing on game protection and anti-cheat, is committed to helping game companies solve the problem of cheats and hacks, and providing deeply integrated encryption protection solutions for games.

Read More>>