In the last weeks I have been spending a lot of time on the artificial intelligence (AI) system for the ships in BossConstructor. While the main part of the game is about building and flying your own ship, AI controlled ships will play an important role in some of the game modes like for example the survival mode.
How the artificial intelligence works in BossConstructor
The approach for artificial intelligence I have been working on consists of two parts. The first part is about defining simple general rules according to which the ships behave. These rules include, for example:
- Don’t crash into allied ships.
- Avoid incoming shots.
- Don’t crash into enemy ships.
- Try to stay away from the walls.
- Approach enemy ships until they are in weapon range.
- Avoid facing enemy ship’s weapons.
While most these rules apply for all ships, the importance of them is not so clear. For a heavily armoured ship, for example, avoiding shots and collisions is not as important as for a lighter ship. In fact, some ships may even be designed to ram enemy ships in order to do maximum damage.
In total, there are about 25 parameters which describe how the above rules work for each ship. Tweaking these parameters to fit a specific ship is a very tedious and difficult task. It is also a task which needs to be done again whenever a new ship is designed and whenever the game’s balance has changed.
In order to automate this process I have implemented an evolutionary optimisation algorithm. This algorithm works by randomly changing (‘mutating’) a ship’s AI behaviour and evaluating how it affects the ship’s ‘score’. This score is calculated based on a predefined series of skirmishes against different enemy ships. After each round, the AI behaviours which have done well are preserved for future use while the ones which performed poorly are discarded.
The nice thing about this approach is that it works automatically once implemented. However, it does require a lot of processing power. The video below shows how the AI behaves after about 200 iterations including some AI derpness. 🙂
If you are interested in BossConstructor, please follow and like it on Facebook at http://www.facebook.com/Bossconstructor.