Field of Glory 2 Developers Diary - A.I.
![](http://www.slitherine.com/forum/styles/slitherine/imageset/icon_post_target.gif)
by
Daniele » Tue Jul 18, 2017 10:20 am
The AI for
FOG2 has been developed by building on the knowledge gained from developing the generally praised AI for Pike and Shot and Sengoku Jidai.
Deployment
For non-preset scenarios, it is important that the AI can deploy its army in a sensible formation, taking account of the prevailing terrain.
Generally speaking, most ancient armies would deploy with an infantry centre in one or more lines. (Usually three for Romans, usually only one for Hellenistic armies). They would then have cavalry on both wings and perhaps in reserve, plus light troops both in the centre and on the wings.
Except for cavalry armies, the “autodeploy” routine therefore starts with the infantry centre, in one or more solid lines. If the army has a mixture of heavy and medium foot, it will deploy the heavy foot where the terrain is most open, and the medium foot where it is most uneven. This takes into account not just the deployment line but also the map in front of where the line will advance.
If it is possible to rest one flank of the infantry on a river or a coastline, it will do so.
Cavalry are then assigned to each wing depending on the amount of adverse terrain on each wing. More cavalry will be deployed on an open wing than on one with lots of rough or difficult terrain or a river. Some cavalry may be assigned to a reserve behind the infantry.
Light troops are then assigned in a similar way to the cavalry, but more light foot will be deployed on the wing with more terrain, and more light horse on the more open wing.
For cavalry armies, the cavalry is divided into centre and two wings, and the usually weak infantry deployed at the back in reserve.
High Level AI
This level of AI governs the actions of the main divisions of the army – the centre, the wings, the reserve, and the various groups of light troops. For pre-set scenarios, it is usually scripted specifically to fit the scenario, but for custom and campaign battles a generic but highly-detailed AI script is used to make a sensible initial plan and then react appropriately to subsequent enemy actions.
This “AI_Masterplan” script refreshes its plans every turn. It takes into account not only the initial divisions into which the enemy army is divided, but any changes to those divisions. Thus, if most of the enemy left wing cavalry rides across to reinforce its right wing, the AI will reassign those units to the enemy right wing before making its plans for the turn.
The first decision the AI makes is whether to advance from the outset. A primarily infantry army will not do so, for example, if its infantry are outmatched, taking into account any high ground the enemy army may occupy.
If the infantry are not advancing, the cavalry wings will also usually hang back, so that they cannot be defeated piecemeal by the enemy before the infantry engage. Even if the infantry are advancing, the cavalry will not forge ahead unless they outmatch the enemy cavalry on that wing and are not facing enemy non-light infantry.
Likewise the light troops will not advance too far ahead, unless they overmatch their counterparts on the enemy side.
Low Level AI
This is what governs the behaviour of the troops once they approach the enemy. Numerous things are taken into account. For example:
• Heavy troops will try to avoid terrain that would disorder them.
• Units won’t advance into situations where they could be charged in flank or rear. (Although non-lights will ignore lights for this purpose.) If they can’t avoid being flanked they will form square if pikes, otherwise will turn to leave their flank threatened by the least dangerous enemy unit.
• Units will actively seek out enemy flanks to attack.
• Units pick their chosen target enemy unit for the turn based on their threat to it and its threat to them.
• Units will usually avoid charging enemy who overmatch them in close combat. Such calculations are made using the actual combat resolution mechanisms, taking into account the actual situation (terrain etc.) in which the units will fight.
• Light troops and non-lancer cavalry will evade charges by troops that outmatch them in close combat, unless the enemy is so close that they are likely to be caught and charged in the rear.
• Units with longer range shooting will stop outside the range of enemy shooters.
• Light troops that are close to breaking will retreat out of range of the enemy.
AI development philosophy
From a development point of view, we believe that the AI is the most important part of a wargame, and development of the AI needs to start at the very beginning of the game development process. It also needs, where possible, to work off the actual combat mechanisms rather than using approximate pre-calculated estimates. This greatly improves the quality of its decisions.
Most importantly, the AI needs to be designed by someone who is a skilled wargamer themselves. It is hard enough to make the AI follow an effective plan even if you know what an effective plan is. If the writer of the AI is hazy about this, there is little chance that the AI will play very well.
We also don’t believe that easier difficulty levels should be achieved by nobbling the AI, nor harder ones by giving the AI unfair advantages in the combat or morale mechanisms. Our AI behaves the same at all difficulty levels, and both sides play to exactly the same rules at all difficulty levels without any hidden bonuses and random number tweaks to help the AI.
Instead, we achieve the different difficulty levels by adjusting the balance of the opposing forces – few if any historical battles were fought between exactly equal strength armies.
With six difficulty levels, we are confident that the AI in
FOG2 will give players of all abilities an enjoyable challenge.