Dev Diary #08: Adaptive AI in Scenario Design in Four Easy Steps

The Campaign Series: Middle East 1948-1985 is a new turn-based, tactical wargame that focuses on conflicts in the Middle East.

Moderator: Jason Petho

Post Reply
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

Dev Diary #08: Adaptive AI in Scenario Design in Four Easy Steps

Post by Crossroads »

Time for another Dev Diary!

Dev Diary #08: Adaptive AI in Scenario Design in Four Easy Steps

With CS Middle East, one of the totally new concepts introduced to The Campaign Series was the Adaptive AI mechanism.

Berto wrote an excellent Coder Diary of it at the time, check it out: Coder Diary #30 -- The Adaptive A/I

[*] FYI: All previous Coder and Developer Diaries are listed in the Mods And Their Use post in the Mods and Scenarios folder.

To recap, with added emphasis by me:
ORIGINAL: berto

Coder Diary #30 -- The Adaptive A/I, part 1


[This Coder Diary is an adaptation, an abridgement, of the AdaptiveAI PDF included in the Middle East game's manual folder.]

The Campaign Series A/I -- One size does not fit all!

Arabs did not fight the same way as Israelis. Jordanians outclassed the Egyptians, who outclassed the Syrians. Israel's combat doctrines changed from 1948 to 1956 to 1967 to 1973 and beyond. The cocky Israelis at the beginning of the Yom Kippur War learned to give their revitalized Egyptian foes newfound respect, and learned to change their ways. Adapt or die.

From nation to nation, from war to war, from year to year, even from one battle to the next -- they all differed, so much evolved.


But in the traditional Campaign Series, as in most (all?) war games, there is one and only one A/I. Locked down tight. Mostly inaccessible to the scenario designer, much less to the player.

Until now...

We have devised a new customizable A/I System. Customizable by side, by nation, by scenario. Open to the scenario designer's tweaking. Also the modder's.

We call this new system: "Adaptive A/I." As in: An A/I that adapts to the side, the nation, the era, the individual scenario. (Not as in: Adapts real-time to changing game play circumstances. But that too will be implemented in future updates.)


The purposes of the Adaptive A/I are:

[*]To coach the A/I in ways and things it is too dumb to figure out by itself.
[*]To achieve game play "balance".
[*]Not so much to improve the A/I play as to better simulate actual combatant and scenario conditions. To achieve greater "realism" and "historical fidelity".
[*]To add randomness.
[*]Thereby increasing replayability.

These cross purposes are often at odds with one another. Some Adaptive A/I parameters will make the A/I opponent "better"; others will make it "worse". It all depends. Some players will like the increased uncertainty; others will not. It all depends. That's why the Adaptive A/I is optional. Select it or not as you wish.

Image

AI parameters that can be tweaked per scenario, per side, per nation? In this blog entry, let us seehow it all played out with the hypothetical Crisis in Sirte Libya'85 scenarios.

First, let us revisit what Adaptive AI does. Even for H2H scenarios, AI does a lot of things, as one might guess at looking at the Adaptive AI groupings.

This, from the latest CS:ME 2.0 Beta init.ai file:

[*] 0-29 movement
[*] 30-49 opfire (opportunity fire)
[*] 50-59 IF (indirect fire)
[*] 60-69 combat, direct fire, assault
[*] 70-79 fatigue, morale, disruption, leadership, command
[*] 80-89 visibility, spotting
[*] 90-99 supply, ammo
[*] 100-109 activity
[*] 110-119 misc
[*] 120-129 opfire (opportunity fire)
[*] 130-139 SAMs
[*] 140-149 helos

So for me, pitting Gaddafi's finest versus the British Quick Reaction Force, in general, I wanted to achieve at least these two things.

[*] Adapt AI calculations to this particular set of scenarios. Sirte 1985 is a specific set of battles with all sorts of modern gear, and I want to have some unique features.
[*] Also, I want to beef up Libyan combat behavior a bit, as they are supposed to be the elite formations of Gaddafi's arsenal.

Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Crisis in Sirte Revisited

Before going further, let us revisit the Crisis in Sirte scenarios too, and in particular as why I thought to adapt the Adaptive AI there.

Again, emphasis mine:
ORIGINAL: Crossroads

I have found the 1980s to be very much my sweet spot on these series, so how about some more modern action. Don't take the background story too seriously, it is all just an excuse to field Chieftains and Scimitars into the battle. And tracked Rapiers. And T-72s. Hordes of T-72s, in fact! And they all get to be blown away!

Image

The scenarios come in two versions:

[*] SIDE A; for a chance to blow everything heading your way as the commander of the British Quick Reaction Force
[*] H2H; a first attempt at tournament scenarios.

NOTE: First versions after some vs-AI and Hot Seat testing. Not the complete product yet, please let me know how you find things! In fact, I have struggled a bit to make the play balance: you start as Libyan commander and you have all these men and equipment, and they just fall apart

Yes, the Libyans need to be better equipped to face the Brits.

To start small, I only wanted to change a few things:

[*] Libyan Op Fire probability. At 50% by default, I wanted them to be able to react quicker to threats around them, both in ground and in air.
[*] Their artillery advantage. Admittedly this is about having 105mm batteries vs Brit mortars, but still, let us beef them up a bit.
[*] Finally, the Surface-to-Air missile model. SAMs are to be able to fire at Low airlevel too, from High only, in CS:ME 2.0.

Let us get to it then. I will not repeat everything Berto described in his post and in the AI How-To doc that ships with the game. Have a look at his post again.

Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Using Adaptive AI in Four Easy Steps

Easy, he said? Berto had this to say in his Coder Diary, added emphasis again mine:
ORIGINAL: berto

This system of

[*]tandem .ai files (init.ai & <scenario>.ai)
[*]<scenario>.ai values trumping init.ai values trumping default values
[*]-1 ignores

is designed for the greatest flexibility, and to minimize redundancy and extra work. You drop in to fine tune a parameter exactly where you need to, no more, no less.

This might seem confusing to you now. But as you play around with this, as you tweak and experiment, and as you follow along the inevitable forum discussions about this, it should all become much clearer to you. You'll get the hang of it!

NOTE: All of this applies to modders only, who wish to modify the A/I values. In ordinary play, for ordinary players who don't care to mod, don't worry! We have figured out the A/I parameters in the appropriate ways in the appropriate places for you. Just play!

It does feel a bit complex at first, doesn't it. But, seeing is believing.

Once you have the files open in front of you, it becomes easier to grasp, as basically we're looking to change parameters one at a time.

Here's the required four steps, in short:

[*] 1. Copy one of the existing *.ai files to serve as a template
[*] 2. Copy over the Nation specific lines from Init.ai, if necessary
[*] 3. Change the parameters you want to experiment with
[*] 4. Game on! Test with -X NoEncryption, or have us encrypt the *.ai files, we're happy to help you!

And that's it. Game engine now uses AI parameters per your design

So, finally, let us look at each of these step, one by one

Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Step 1: Copy one of the existing *.ai files to serve as a template

In this step I create my own scenario specific Adaptive AI file using "Init.ai" default file and one of the existing <Scenario>.ai files, namely: Bootcamp_1.ai as that already includes the Brits.

First, a brief recap how the parameters work, and in which order in particular:

[*] Game engine has hard coded parameters which are used, if no Adaptive AI parameters are available.
[*] Most Adaptive AI parameters are defined in init.ai (plain text) and init.aix (encoded for PBEM play) files, in the root directory. These are used, unless there's a ...
[*] Scenario specific <scenario file name>.ai(x) file is available in the \Scenarios subfolder.

In the current set-up, there's 150 Adaptive AI parameters or placeholders to allow access to game behaviour. They are all explained on init.ai file.

To get started with the first tasks in Step 1, I

[*] Open init.ai from the root folder (as it has the parameters explained and default values for all nations), and
[*] Open the Bootcamp_1.ai file from Scenarios folder (to serve as a basis for my Sirte scenario specific ai file)

Here they are, in my Text Editor. As Bootcamp_1 already has the Brits, I just need to change the Generic Pro-East nation to Libya:

Image

To complete Step 1

[*] Save Bootcamp_1.ai I used as a template, as E01_Sirte1985_H2H.ai

to exactly match the file name of the first scenario I want to work with.

And that's Step 1 completed! [:)]

Attachments
aai_1.jpg
aai_1.jpg (412.13 KiB) Viewed 703 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Step 2: Copy over the Nation specific lines from Init.ai, if necessary

And necessary it is, as the template I used had the Brits but not the Libyans.

Step 2 is what it says, I copy Libyan Default Parameters from "Init.ai" to "E01_Sirte1985_H2H.ai". And that's it.

[*] Init.ai has a default line for all the Nations, just look at the Nation ID for the row(s) you want to copy over.

Note: The Side specific defaults are good as they are. I just put a note to the comment section Side B being Libya here.

Here's how it looks at the moment, Sirte AAI file on the bottom, with Libyan rows now available there as well:

Image

Attachments
aai_2.jpg
aai_2.jpg (348.15 KiB) Viewed 703 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Step 3: Adjusting "Artillery vs Hard Targets" Values

In Step 3, we alter the default Adaptive AI values to those that we want to take place in our particular scenario.

Note: this is one of the parameters that need to be adjusted for both Side and Nations parameter rows, as indicated by the # 55[sn] reminder. (Berto's Coder Diary has all the details for Sides and Nations specific parameters, have a look there if necessary)


First thing I want to change is to make the life of the very impressive Chieftain tankers a tad harder.

[*] I will add to the probability a Libyan artillery salvo will have a Disable Combat Result Modifier roll to them.

Here's how I did it. I looked at the available Artillery AAI parameters, and found this:

[font="Courier New"]# 55 [sn] AI_if_hardtarget_kill_prob // Probability of IF fire scoring kill against hard target. [/font]

Probability values present percentages, so here goes:

[*] Libya: 6 % -> 10 %
[*] Brits: 10 % -> 4 %

Why this particular change to Sirte scenarios? Libyans have actual Artillery Batteries, while the Brits only have their light Mortar sections.

I do this to both Sides and Nations row. See the picture below.

Image

The two sets of three lines visible in the E01_Sirte1985_H2H file are

[*] Parameter # helper row
[*] UK
[*] Libya

So far so good.

Attachments
aai_3.jpg
aai_3.jpg (289.56 KiB) Viewed 703 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Step 3 Cont'd: Adjusting Op Fire, SAM Parameter Values

Let us change a bunch of other parameters next:

Note: These all were Nations parameters, as indicated in the sample row # 122 [ n]. Therefore I needed to add these values to one place only.


[font="Courier New"]# 121 [ n] AI_opfire_ground_prob // Probability of per-attempt opfire against ground units.
[*] Libya: 50 -> 70

# 122 [ n] AI_opfire_air_prob // Probability of per-attempt opfire against air units.
[*] Libya: 50 -> 70[/font]

[*] Motivation:Libyan mech units are supposed to be Gaddafi's finest, so made them a bit better in reacting to events facing them. Not overly so, though.

[font="Courier New"]# 130 [ n] AI_dirfire_sam2helolow_prob // Probability of per-attempt SAM direct fire against low-flying helos.
[*] Libya: 25 -> 20
[*] Brits: 25 -> 30

# 131 [ n] AI_dirfire_sam2helohigh_prob // Probability of per-attempt SAM direct fire against high-flying helos.
[*] Libya: 75 -> 70
[*] Brits: 75 -> 70

# 132 [ n] AI_opfire_sam2helolow_prob // Probability of per-attempt SAM opfire against low-flying helos.
[*] Libya: 25 -> 20
[*] Brits: 25 -> 30

# 133 [ n] AI_opfire_sam2helohigh_prob // Probability of per-attempt SAM opfire against high-flying helos.
[*] Libya: 75 -> 70
[*] Brits: 75 -> 70

# 134 [ n] AI_opfire_sam2helo_prob // Probability of per-attempt SAM opfire against helos (tripfire prob).
[*] Libya: 25 -> 80
[*] Brits: 25 -> 90[/font]

[*] Motivation: Low flying targets - Brits with Tracked Rapiers to have a slight advantage here on locking on Low flying targets. High air level they are equal. Diminished the odds a bit, as there's two batteries for each side. For Brits, only for Sirte #4 though.

And here they are.

Image
Attachments
aai_4.jpg
aai_4.jpg (325.78 KiB) Viewed 703 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

About SAM AAI Parameters in CS:ME 2.0

So again, SAMs are to be able to fire at Low air level targets as well, as of CS:ME 2.0.

The current Air Levels are:

[*] Ground: Treated as a ground unit.
[*] Nap of Earth: <25 meters
[*] Low: 25 meters to <250 meters
[*] High: 250+ meters

If you recall the various SAM systems were never 100% effective vs targets, less so when treating with Low flying Helos, so here's how it plays out:

Opportunity Firing

[*] opfire_sam2_helo_prob defines the likelyhood Opportunity Fire kicks on against an aerial targer. Think of this as SAM Radar noticing the target, and giving the firing co-ordinates to SAM batteries
[*] opfire_sam2_helolow/high_prob then defines the likelyhood the individual SAM Battery then is able to lock on to target, and to launch their missiles against the target.

So when playing vs Libyan AI, the likelyhood HAL fires at your Low altitude helo is 0.70 * 0.20 = 14%. He's got two SAM Batteries though, do you want to risk your Lynx gunships against the 14% + 14% odds? Decision is yours [8D]

Direct Firing

With direct firing your units, there's no Op Fire probability, but the probability your SAM Batteries can lock into those Low flying buggers remains. So attempting to fire with SAM against a spotted Helo at Low is what the parameter says

[*] dirfire_sam2_helolow/high_prob

So 20% vs Low and 70% vs High if you're playing the Libyans, or 30% / 70% if you're playing the Brits

Makes sense? Any questions just ask here!

Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Step 4: Adding Encryption

And that's it for now. Let us see how they play.

I could use the -X NoEncryption parameter to launch ME.EXE to have it use the non-encrypted *.ai files. This is available only for playing vs HAL.

Or, I could have them encrypted into *.aix files to have them available for all game play, including PBEM play. To do that, just give us a holler, we'll run the encryption for your modded files.

That's what I did here.

[*] Decided to have these Adaptive AI settings available to all four Sirte H2H and four Sirte SIDEA games, so copied the file I prepared above to match all Sirte scenario file names. Remember, these are scenario specific settings!
[*] Had all the *.ai Encrypted, resulting in *.aix files.

Remember, *.ai file names must exactly match the scenario file names. See here:

Image
Attachments
aai_5.jpg
aai_5.jpg (197.47 KiB) Viewed 703 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

Game On!

Did it work as hoped for? Let us find out by launching one of the Sirte scenarios.

Here's Crisis in Sirte: 1. Prelude (H2H) in action, with Adaptive AI dump dialog as available by pressing Alt-F10.

British values (Nation id 9) in Blue, Libyan values (Nation ID 29) in Red. Also, the Current Side (and it is the British turn) values are available during this opening turn.

Libyans now Op Fire with a better probability, to reflect the quality of Libyan Mech Formation in this scenario. Their artillery is also more of a threat to Chieftains. No tank parking, artillery barrage imminent! Also, SAM behaviour just as I want for this particular set of battles with SAM batteries available in numbers.

Neat!

Image
Attachments
aai_6.jpg
aai_6.jpg (631.23 KiB) Viewed 703 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »


Seeing Is Believing

And that's it for this little Blog entry.
ORIGINAL: berto

This system of

[*]tandem .ai files (init.ai & <scenario>.ai)
[*]<scenario>.ai values trumping init.ai values trumping default values
[*]-1 ignores

is designed for the greatest flexibility, and to minimize redundancy and extra work. You drop in to fine tune a parameter exactly where you need to, no more, no less.

This might seem confusing to you now. But as you play around with this, as you tweak and experiment, and as you follow along the inevitable forum discussions about this, it should all become much clearer to you. You'll get the hang of it!

NOTE: All of this applies to modders only, who wish to modify the A/I values. In ordinary play, for ordinary players who don't care to mod, don't worry! We have figured out the A/I parameters in the appropriate ways in the appropriate places for you. Just play!

I hope this little sample provided a concrete example as how to make the game behave towards a certain manner as you see fit in your scenarios.

Something not quite working out for you, in your particular scenario:
ORIGINAL: Crossroads

This, from the latest CS:ME 2.0 Beta init.ai file:

[*] 0-29 movement
[*] 30-49 opfire (opportunity fire)
[*] 50-59 IF (indirect fire)
[*] 60-69 combat, direct fire, assault
[*] 70-79 fatigue, morale, disruption, leadership, command
[*] 80-89 visibility, spotting
[*] 90-99 supply, ammo
[*] 100-109 activity
[*] 110-119 misc
[*] 120-129 opfire (opportunity fire)
[*] 130-139 SAMs
[*] 140-149 helos
Now you can do something about it!

There's a few steps to achieve it, but what's important imho is that these parameters are now open and available to all scenario designers.

You (and we) can now model a certain era, a certain nation, a certain battle in much more detail, without having to surrender to the game engine ultimately using the hard coded values baked deep into the code:

[*] Copy one of the existing *-ai files to serve as a template
[*] Copy over the Nation specific lines from Init.ai, if necessary
[*] Change the parameters you want to experiment with
[*] Test with -X NoEncryption, or have us encrypt them, we're happy to help you!
[*] And that's it. Game engine now uses AI parameters per your design

This is still early times for Adaptive AI, but the intention is there. At the moment there's space for 150 in-game parameters for tweaking, and it's not likely to end there either, in the long run.

Also, having Editors availble for easier access is in the plans. But given the task list we have, they are not on the top of the queue. For now, editing these text files is the way to go about it.

So, no need to postpone any further tweaking a battle to meet your strict design requirements. Adaptive AI is there to help you.

Any thoughts, comments, questions? Just shoot, we're happy to answer. [:)]

Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
User avatar
KEYSTONE0795
Posts: 90
Joined: Thu Aug 21, 2014 12:01 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by KEYSTONE0795 »

How do you launch the X NoEncryption parameter from the ME.EXE?
User avatar
Crossroads
Posts: 17498
Joined: Sun Jul 05, 2009 8:57 am

RE: Dev Diary 08: Adaptive A/I in Scenario Design

Post by Crossroads »

ORIGINAL: KEYSTONE0795

How do you launch the X NoEncryption parameter from the ME.EXE?

Easiest way to do that is to locate the ME.EXE at the game root folder, and to create a shortcut to your desktop. ie. first "Copy" it, then "Paste Shortcut" it to your desktop.

Then, right click at the shortcut icon, and type -W -X to the parameters, to have game opening in Windowed mode, with X NoEncryption on.

See the first picture behind the link below:

ORIGINAL: Crossroads

Step 4: Adding Encryption

And that's it for now. Let us see how they play.

I could use the -X NoEncryption parameter to launch ME.EXE to have it use the non-encrypted *.ai files. This is available only for playing vs HAL.
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < Available now
CS: Middle East 1948-1985 2.0 < 3.0 In the works
Post Reply

Return to “Campaign Series: Middle East 1948-1985”