Reading time: 9 minutes.

# Turn-based Battle Systems - Chapter 2 - Analytical Analysis

Hello everybody! It is time to continue with our series on Pokemon-like battle systems. In this chapter I will be more general: now we have our beautiful damage formula and a draft of our characters sheet, it is time to quickly check if the game the formula is balanced. There are a lot of questions that we want to answer as quick as possible. How much HP the enemy must have? What is a good value for the attack power? Is the damage formula fair enough? The critical strike is too much? The randomness is too much? *Is it fun?*

Except for the last question, we can try to answer them just looking at the damage formula. Obviously we can not answer all the questions now, but if there is some evident mistake, we will be able to catch it as soon as possible. There are several ways to analyse the tuning and balancing problem for a damage formula (and thus for a large part of the combat system): **analytically**, with **Google Sheet/Excel**, and with a quick **software prototype**.

In this article we will start from the first step: the analytical analysis.

## Analytical Analysis: The Basics

The simplest thing we can do is to look at the formula and understand how it changes with respect to the various parameters. How can we do that? Borrowing tools from the study of a function we used to do in high school (or equivalent). In this way we can quickly identify some critical conditions we want to avoid in your game but, most important, we can understand it. We can understand the effect of each attribute to the damage output and balance the game accordingly.

### Identify the Singularities

The first things is **to identify singularities**. Let’s look at our damage function. Just looking at it we can clearly see that there is one point in which the damage can be infinite (and infinite damage is not good). If `EnemyDefense`

is 0 we can have infinite damage. So, for instance, this is a point you have to keep in mind when you will implement the *Tail Whip* move (reduce defense) because you have to guarantee that it is impossible to bring the enemy defense to zero. This is a trivial example but I hope you got the point. Other formulas can be much more complex and identifying singularities could be much more trickier.

Other singularities you should identify could be: **negative damage**, **inconsistent damage** (when the increase of a “positive” stats such `attack power`

can reduce the damage) or *“imaginary” damage* (yep… this happened to me once…).

### Understanding the flow

Second, we need to understand how the damage output changes with the parameters. You have to ask yourself questions such as: if I have an enemy with 10 defense, how much the damage changes when the player attack increases (or decreases)? If attack and defense are fixed, how the damage change when the base damage of the Pokemon’s attack change? You have to find out this by yourselves! If you don’t, your players will and they will start exploiting every loophole they can find.

Moreover the “shape” of the damage function with respect to the variation of some character’s attributes can tell you **a lot** on how much important that parameters is and, for instance, guide you when you will start designing equipment, weapons, buffs and so on. There are a limited amount of shapes you can usually find out in this step.

But before we move on, there are two important concept that you have to grasp: the **absolute increment** or **absolute effect** (**AE**) and the **marginal effect** (**ME**). The absolute effect is how much the damage increase (or decrease) if I increase (or decrease) the target attribute by one. For instance, if I am looking at the attribute `p`

the AE value is just:

$$ AE = Damage(p+1) - Damage(p)$$

The marginal effect, instead, represents how “effective” is the damage increase (or reduction) respect to the previous value. For instance, a ME value of 0.3 means that increasing the attribute by one point you obtain a 30% increased damage. Mathematically:

$$ ME = \frac{Damage(p+1) - Damage(p)}{Damage(p)} = \frac{AE}{Damage(p)}$$

For the **law of diminishing returns** the absolute value of ME **must** decrease when the attribute increase. If not, there is a problem in your formula! Diminishing returns is important in this kind of games because, in short, is the reason why your sword with + 10 is so good when you are Level 1 and so shitty when you are level 90. Diminishing returns is your only weapon to control players preogression. We will talk a lot of the diminishing returns law in the next chapters.

#### Linear Attributes

When you increase the attribute, the damage changes in a straight line. This means that the effect of the attribute you are exploring is proportional to the attribute itself. Mathematically you can rewrite your function in this form

$$ Damage(x) = k x + q$$

In this formula *k* means: how much more damage I get if I increase the attribute (e.g., the strength) by one point? At the same time *q* is the **residual**, that is the damage when the attribute is zero. Usually this value is small and we can forgot about that.

In the Pokemon formula, the `PlayerAttack`

attribute is a linear attribute. In fact we can rewrite the formula in this way:

$$ Damage = PlayerAttack \left( \frac{\alpha + Base}{EnemyDefense} Multiplier \right) + (2 \times Multiplier) $$

Where the constant *alpha* is that strange value who depends on the player’s level.

Assuming `q`

small enough, the ME value of a linear attribute is always:

$$ ME = \frac{1}{x}$$

Note that the marginal effect does not depends on the *k*! So, for example, moving from 2 attack to 3 attack will always increase your damage by 50% (because 1/2 = 0.5). Moving from 10 to 11 will always increase the output damage by 10% (because 1/10 = 0.1) and so on.

Linear attributes are very standard stuff in this kind of games. If your positive attributes are linear, you are in a good spot.

#### Hyperbolic

This is the analogous of a linear attribute for **negative attributes**, the one that reduce the total damage such as `EnemyDefense`

. Mathematically you can explicitly highlight an hyperbolic attributes rewriting the damage formula in this way:

$$ Damage(x) = \frac{k}{x} + c$$

In this case, you need *k* points in the attribute in order to neutralize the damage and get `c + 1`

point of damage. `c`

is the amount of unavoidable damage: you can not do less than `c`

even if your enemy has infinite defense.

In the Pokemon damage formula `EnemyDefense`

is an hyperbolic attribute. In fact:

$$ Damage = \frac{ (\alpha + Base) \times PlayerAttack \times Multiplier}{EnemyDefense} + (2 \times Multiplier) $$

For hyperbolic attributes diminish returns is different:

$$ ME = \frac{k}{x(x+1)}$$

Note that marginal effect for an hyperbolic negative attribute depends on `k`

and, moreover, it decreases much faster than the marginal effect for a linear attribute (ME decrease quadratically). This means that, assuming that `PlayerAttack`

and `EnemyDefense`

grow at the same rate, the amount of damage will increase. This is a common and good effect! You don’t want your player to do 10 damage until the end of the game, you want that your player feels more and more powerful during the game, you want that at higher level your player does ten million damage! So powerful! However, how to balance this? Usually you absorb the extra damage increasing the HP of the enemies and the player. Plus: if you are a math geek you can compute how much more HP is needed in order to compensate the increased diminishing return. That’s why analytic analysis is so interesting!

### Advanced Shapes

These are just the two basic shapes we can usually find in damage formulas and, in particular, in the Pokemon formula. This is because we chose to 1) use only the four basic operations 2) we use every character attribute only once in the formula. This is the simplest and safest way to build a damage formula, you can not screw up too much in this way. However, there could be more complex cases who needs a more funny use of the attributes. Sometime we would like to use more “extreme” shapes for our damage-attributes functions. Let’s look a some fancy case.

#### Exponential Attributes

This is an ugly beast. This could be useful in some cases but you do not want exponential attributes in your damage formula. Exponential attributes can easily go out of control. When you have an exponential attribute you can rewrite the damage formula in this way:

$$ Damage(x) = k(base)^x + q$$

This is dangerous. To understand how much this is dangerous, let’s look at the marginal effect.

$$ ME = base - 1$$

There is no diminishing returns, at all! Every time you increase your attribute by 1 you increase the damage by a fixed percentage. An example will make this clear. Suppose the output damage depends exponentially from the `attack`

attribute and that `base = 1.5`

. If we increase the `attack`

value from 1 to 2, the damage will increase by 50%. Ok, cool. However, if we increase the `attack`

from 100 to 101, we still get a 50% damage increase! We could use a level 1 equip item in order to boost our damage by 50%!

Constant marginal effect is usually dangerous but, for instance, **IDLE games** use this kind of shape **A LOT** to handle the game progression and guarantee that you can play the game indefinitely.

#### Nth-Root or Logarithmic Attributes

In both cases this is the shape of the attributes that make the damage increase fast at the beginning and slow as the they increase **without** reaching a fixed value. Damage will just go slower and slower up to infinity. This is a good way to control and “debuff” attributes that could too easily becomes a problem. A logarithmic attribute can be find rewriting the damage formula in this form:

$$ Damage(x) = k Log(x)$$

Marginal effect go **really really quickly to zero** so at higher level you will need tons of that attribute bonus in order to change the damage in a meaningful way.

## Conclusion

There a lot more functions and shapes we can use in our damage formula. They are just like colors in a painting, they can spice up your game or completely destroy it. However, I spent already too many words on this topic. It is time to start computing something and look at how a spreadsheet application can really help us in understanding and balancing our damage function.