Machine Learning and Game Balancing pt. 1
Well, if there is one thing every programmer hates, it’s repeating himself.
And balancing a game like prototype defense is nothing more than that: constantly playing the same level over and over till you find a balance in waves that is as equally matching in toughness as in diversity.
This post series will be a rambling of sorts on some of the ideas I have on how to automate, or ease the aspect of game balancing for Tower Defense.
First we need to look at what aspect we want to look at; balancing could mean two things:
– Either adjusting the strengths or weaknesses of enemies or turrets.
– Creating and balancing waves for a given map.
As its much more fun to define the towers and enemies ourselves, we focus on the second problem.
We immediately see that exhaustive search (brute force) would be out of the question as the search space is just too damn big.
Over 40 types of enemies, over 48 types of turrets, 24 bases, the dimensional aspect of the map, and the temporal aspect of the differing waves. We would just be asking to many questions: “Where should I place a tower?”, “When should I buy a tower”, “When can I upgrade the tower?”, etc…
So we tried to boil the whole problem down to a basic question: “How much much money would be needed to defeat a wave of enemies?”
Our thinking was that if we could just press a button that would calculate this value for us, we could match up the summed income of all the waves before that wave and see if we had enough cash to defeat it!
Our first approach was to give the algorithm a set of enemies which it needed to defeat, along with a path to build towers on.
Essentially the experiment searches for a average cost per unit needed to defeat it. We assume that the density of the wave is irrelevant as it is compensated by the varying degrees of effectiveness of the different towers.
- For each iteration, the algorithm is given:
- An X amount of towers it is allowed to construct, on a (somewhat optimal) preset in-order path.
- A wave consisting of Y units of type Z (which should be extended later on to accommodate different types)
- The algorithm then searches for a convergence of the average cost to stop a unit (ASC), defined as: (Unit Cost * Units) / (Total Tower Cost)
- by first increasing X until a combination is found that stops the Wave with 0 lives lost, and is the minimum cost combination.
- After which Y is increased, and the cycle is run again until the difference in AVC between iterations drops below a magic variable threshold.
In the next part I’ll outline what went wrong, and what went correct.