Archive for January, 2010

Difficulty Curves in an AS3 Defence Game

Saturday, January 30th, 2010
Slice: Fortress Defence

Slice: Fortress Defence

How hard is a wave of enemies? If the enemies get twice as strong as the player gets twice as strong there is no change in difficulty. The difficulty of a defence game is related to the ratio of power between the enemies and the player. Over time the player buys upgrades and gets stronger, and the strength of the enemies must match that closely to make the game challenging, fun and progressively more difficult.

My original plan for Slice: Fortress Defence was to tie the important variables to math equations like so:

Enemy Power: Linear Growth

Gold per Wave: Linear Growth

Unfortunately the linear gold drops resulted in polynomial player buying power, as each wave added to all previous gold spending (and so power increases).

Player Strength = Gold per Wave + Gold for all previous Waves = Area under Gold per Wave graph, approximately (G^2)/2

Player Strength: Polynomial Growth

Polynomials always grow faster than Linear in the long run – so this would leave the game hard at the beginning but getting easier and easier as the player upgraded. That’s no fun!

So I moved to an exponential model. Exponentials have an interesting property whereby the sum of an exponential is also an exponential – this makes balancing the ratios much easier!

Enemy Power: Exponential Growth

Gold per Wave: Exponential Growth

Player Strength: Sum of Gold for all Waves => Exponential Growth

By making the Enemy Power exponent slightly larger than the Gold Exponent the ratio of Enemy to Player power would also follow an exponential curve – and thus the difficulty would rise slowly then start ramping up fast at the end of the game.

Now all I had to do was ensure my units Purchase and Level Up costs gave a good ratio of Power to Gold. Three factors effect unit power: Damage, Range, Rate of Fire. All three must be combined to give a single Power rating to match to balance against Gold – I just multiplied them together, so a 10% rise in all three would give a unit 33% more powerful, and consequently it should be 33% more expensive.

With a little tweaking this system could now produce defence games of any length by changing the Enemy Power and Gold exponents.

In actual fact – once I had a Power to Gold ratio I could calculate the Players total expected Power from the Sum of all Gold Spent – so I uses this expected power to generate my Enemy wave power. This keeps the enemy and player in close step without getting bogged down in maths.