# Math formula for: the higher the stress, the higher the difficulty

My game has a stat called Stress, and the player has some missions to do. Each mission has a computed stat called Difficulty with its own base value. So, let's say:

• Mission 1, Difficulty 1

However, I want to sum to this difficulty an X amount, where X is a % of the player's stress. Turns out I don't want this % to be static, but instead, the higher is the amount of the player's Stress, the higher is the percentage. To illustrate:

• Stress = 10
• Mission 1, Difficulty 2
• Stress = 20
• Mission 1, Difficulty 2
• Stress = 30
• Mission 1, Difficulty 3
• Stress = 40
• Mission 1, Difficulty 5
• Stress = 50
• Mission 1, Difficulty 8
• Stress = 100
• Mission 1, Difficulty 50

The numbers are merely illustrative and don't represent the exact numbers I'd expect.

As you can see, the difficulty doesn't scale linearly.

I don't know the proper keywords to browse for this, so that's why I'm here with this poor vocabulary. Also, I apologize in anticipation if this is duplicated.

• Your current example literally scales linearly. 2 goes into 10 5x. 10 goes into 50 5x. So the linear formula is difficulty = stress / 5. If you are instead referring to the relationship between mission number and difficulty, we cannot tell if it is linear or not, without more samples in series for differentiation. Nov 25 at 0:03
• You are right, @Engineer. My bad. I posted more samples. Nov 25 at 0:11
• What are your edge cases (i.e. minimum and maximum stress and difficulty)? In particular I wonder if there is a maximum difficulty that you want to make sure the formula never goes over. I'm assuming from the example you want the curve ramp up slowly. If there is a maximum difficulty, look for a logistic curve. Otherwise an exponential will do (like the one on DMGregory answer). Nov 25 at 1:03

We can throw your example numbers into a spreadsheet and chart them, say using Google Sheets, and get a look at what the progression looks like:

We can add a trend line to the graph to try to fit a formula to the data. In Google Sheets, this can be found under:

Chart editor > Customise > Series (Difficulty) > Trend Line

I used these settings, and got a pretty decent fit with a polynomial of degree two (a quadratic):

We could use exactly the equation that the trend line found for us, but it has a dip in the middle which isn't ideal. So let's see if we can make our own version using that as inspiration.

Here I tried squaring the stress value, and dividing by 10000 (bringing a maximum of 100 * 100 stress down to an output value of 1). Then I multiplied the result by 49 and added 1, to get an output between 1 and 50.

That gets pretty close to your numbers, but it over-estimates a little in the middle. Let's try cubing stress instead. Here I'll normalize stress between 0 and 1 by dividing by 100, then cube this normalized value, multiply by 49 and add 1 as before. And then let's take the ceiling (next integer higher than the number we get out). That reproduces your example values perfectly.

Moreso than any particular formula though, I hope this demonstrates for you a method that you can use to explore and find formulas on your own.

• Geez, that's a good trick! I wonder - is it possible to create a formula from a graph? Asking because our game has lots of formulas and for non-mathematicians, it's quite a nightmare lol. 2 days ago
• That's effectively what the trendline technique I showed above does. 2 days ago
• Wait. I guess I missed that part. I see you have =ROUND((B3*B3)*49/10000+1), however I don't know how that formula showed up there - I guess you wrote it manually, right? 2 days ago
• I did. I explained my thinking in the answer - the trendline showed that a quadratic could be a good fit for the data, so I tried squaring the stress, then scaling and shifting it into the range 1-50, and rounding the result. 2 days ago
• Oh, I see. Yes, I mean, I guess my question was more like if there was a way to automatically extract the formula for the quadratic graph somehow - not exactly by designing the formula and the numbers myself. But anyways, your approach enlightened my day. Thank you so much! 2 days ago