Coding AI for your tower war game

So as a total beginner, I wanted to create some sort of simple AI to control the computer in the game I am creating, that is a variation of the old WarCraft 3 maps called Tower Wars – it is a bit like Tower defence, but instead of only defending your base, you have to think about economy as well.

So, I though, how hard can it be, all I have to do is to make it take a decision between 3 options.

  1. Buy a new soldier,
  2. Upgrade a tower
  3. Save for next round

Simple right?

However, I quickly found out it was not as simple as first anticipated. First of, how do I decide what to do? When will we choose to spawn a solder, what values should the AI be looking for?

Second, when wanting to upgrade the tower, what part of the tower should be upgraded? And what about saving up.. what makes the AI want to save up?

I started reading around on the internet, and quickly came to the conclusion that what I was looking for was some sort of behaviour tree, and that on a timer, the AI would make a “random” decision, where the probability for some decisions would be higher than others.

Once I got started, it was actually quite simple, I put up a bunch of variables that I marked from 1 to 10 then for each decision that the AI have to make. 10 there is a high probability that this will be the decision, and 1 means that there is a low probability that this will be the decision.

So, if the AI have to choose between 3 options – I simply add the 3 options together, and make a random number between the 3. So taking the first decision that the AI have to take: Buy a new soldier (7), upgrade a tower (5) or save for next round (3) the decisions looks like this.

Create a random number between 1 and 15 (7+5+3)
If the random number is from 1 to 7 AI should spawn a monster, if it was from 8 to 12 we upgrade a tower, and from 12 to 13 we save for next round.

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.