I’m back from vacation, freshly recovered and therefore able to continue working on my hobby projects.
Today I’m devoting myself to what I think is the most difficult topic in wargame development. It is certainly not the graphics. It is common knowledge that wargames are ugly as night. But it’s not the pathfinding either. In fact, pathfinding is the second most difficult issue, as possible paths are constantly changing and zones such as the “zone of control” or the ownership status of a tile are constantly changing. There are also paths for supplies, airplanes, waterways, etc..
But this article is about the AI. There are games, such as Tower Defense, where enemy AIs don’t have to do much. The principle is clear: spawn enemies, let them run, done. In a wargame, there are a lot of decisions that have to be made. Basically, you can differentiate between the following points in my game (no guarantee of completeness):
Or to put it another way:
For a wargame to actually be played by an AI, these 3 levels must be covered.
First of all: I am not an AI programmer. My solution is therefore not a generally valid solution. It could even be that an experienced game developer reads this and face-palms. Nonetheless, I’ve been a programmer for over 15 years now and have already developed one or two pieces of software. One thing that has stuck with me is the use of design patterns. Design patterns help to decide how code should be organized.
This already expresses an essential core of my AI: I separate the respective decisions of the AI into different levels. At the same time, I follow a paradigm of object-oriented programming: I try to represent reality using classes. Accordingly, I have concentrated on building the AI into three independent parts:
So much for the theory. In practice, it currently works as follows, whereby the operational AI only rolls the dice as to whether there should be an offensive or not.

The strategic AI, i.e. the HQ unit, proceeds as follows:

The unit that is now on the move looks for the easiest route to the objective. There are now various options. In the unlikely event that the objective can be reached directly, the order to march is given immediately. As soon as the unit has reached the objective, the region is considered captured.
More often, however, the AI will encounter resistance. For this purpose, two paths are superimposed. The optimal waypoint route without resistance and the actual route with resistance. All units that are now on this route are saved in a pool. The system now compares which unit has the shortest distance to the unit. If there are several units in the immediate vicinity, the unit that is the weakest – according to the current reconnaissance status – is selected. The unit receives the command status “MOVE_AND_ATTACK”. The enemy unit is saved and the unit follows the path to this unit. As soon as it is in the immediate vicinity (one tile away), the order to fire is given.

At first, the task of programming a wargame AI seemed impossible to me. However, breaking it down to the individual command levels has not only created a logical progression, but also defined small targets that are easy to approach and, in case of doubt, easy to replace.
The AI is far from finished. For example, soft and hard factors such as morale, fatigue, supplies, ammunition and movement points still need to be included in order to make better decisions. However, I’m already quite happy with this simple variant, as it actually allows initial gameplay and makes the game “playable” in terms of gameplay effects for the first time ever.