Mihai's page

How not to lose money in Silksong

I am not doing Advent of Code this year. Instead, I will follow the other trend of launching a new “Advent of X” (see Advent of Small ML, Advent of Cyber, and Advent of Sysadmin, as just some examples). Since I have published less than what I set up as a personal expectation back in January, I will post one new blog post every day of this month until Christmas. The posts will be of different length and will touch different topics such as math, modelling stuff with Math, computing, AI, science, and so on.

Today, I will do a math post, solving a simple decision problem involving one of the games released this year (after waiting for it for 7 years).

The game is Silksong and the decision problem we want to solve is to determine the best strategy so that we don’t lose too much currency (called rosaries in the game). When the player character dies, the player loses all of their currency, unless they go back to the place where they died and retrieve them by striking a cocoon. If the player dies before recovering the cocoon, then all the currency is lost. However, the player does not lose any other part of their inventory. And, there are methods to convert currency intro items in the inventory: at certain places in the game, the player can spend 80 rosaries to get a string of rosaries that could be later broken to obtain 60 rosaries on demand. Similarly, there is one seller that would give you a rosary necklace worth 120 rosaries, for 140 rosaries.

Given these, the question we want to solve is Given that the player has \(R\) rosaries now, should they convert these to strings/necklaces before fighting a boss or not?.

For today’s post, we assume that the player has a probability \(p\) of dying on the path to the cocoon. Assume that the cost of conversion is \(c\) (i.e., 80, or 140) and that the value of the item is \(v\) (i.e., 60, or 120).

Given a total amount of \(R\), the player can convert \(k \in \left\{0, 1, \ldots, \left[\frac{R}{c}\right]\right\}\) rosaries and carry the rest in the inventory.

If the player dies before retrieving the cocoon, then they are left with \(vk\) rosaries, in the strings/necklaces. This event occurs with probability \(p\).

If the player recovers the cocoon, then they are left with \(R - ck\) rosaries in the inventory, and the \(k\) strings/necklaces worth \(vk\). Thus, they are left with \(vk + R - ck\), with a probability \(1-p\).

Thus, the expected value of converting to \(k\) strings/necklaces, is

\[\mathbb{E}(k) = pvk + (1 - p)(R - ck + vk)\]

Grouping by \(k\) we have:

\[\mathbb{E}(k) = k(v - c + pc) + (1-p)R\]

This is a degree 1 function. Depending on the sign of \(v - c + pc\), the player should either not convert anything (since each conversion would result in actually losing money on average), or convert as much as possible (if \(v - c + pc\) is positive).

So, if \(p \ge 1 - \frac{v}{c}\), then the player should convert everything into strings/necklaces. That is, if using the machine, the player should convert if they expect to survive in at most 3/4th of the runbacks. Or, if using the vendor in the city, they player should convert if they expect to survive in at most 6/7th of the attempts to collect their money.

This is a simple analysis, and misses some of the complications that can appear when actually playing the game. For example, there is an upper limit of 20 strings/necklaces in the inventory, so \(k\) can be at most 20. Furthermore, if the player dies to a boss, it is expected that they would die a few more times again before being able to continue. This means that even if they recover the rosaries, they could still lose them in the next runback. For the interest of time, we will study these complications in a future article.


Comments:

There are 0 comments (add more):