AI Editing and Scripting

John Tiller's Battleground Series is a Hall of Fame lineup of games covering the Civil War and Napoleonic Wars. We've compiled these classic games into two new affordable collections, incorporating updated versions of these legendary titles. Incredible historical gameplay and great value!
Post Reply
User avatar
simovitch
Posts: 5906
Joined: Tue Feb 14, 2006 7:01 pm

AI Editing and Scripting

Post by simovitch »

Here's some hints that I have gathered from my experiences with scripting the AI in BG Napoleonic Wars:

Granted, you can develop an elaborate series of clever scripts for the AI but it will still make utterly inane, and often suicidal tactical choices. But sometimes it may actually suprise you, especially noobs and even average players, at the tactical level.

With some practice you can script a fairly tough and responsive Defense. Getting the AI to keep the attack moving along is more difficult but there are still some things you can do to help the AI keep losses down and keep the defender guessing.

First, we look at the Header Dialog.

The Scenario Editor Help files are handy and a must read for implimenting a functional AI, but there are a few things they don't tell you, and a few things that some designers seem to have ignored in many of the NIR project add-on scenarios:

1. Don't forget your AI settings in the Header Dialog!
0=extreme defense
1=ordinary defense
2=do only what the scripts tell you to do.
3=attack
4=extreme attack.

What the help files don't tell you is you can use a setting besides 2 and still influence your scripts. For instance, in the attack, use the scripts combined with 3 or 4 to give your AI a bit more aggression (though too much agression will increase the AI's losses - read cavalry...)

In defense, I find it best to write some scripts and stay with 2. If you choose to only set the AI settings and no scripts you are just being lazy and you may as well forget about it - if you have more than 1 objective the AI will not allocate it's forces effectively.

2. Don't forget your AI flag in the Header Dialog!
0=commit all to A or D.
1=be flexible as the situation develops.
2=French move in column
4=Allied move in column

Setting the Flag really depends on the type of battle you are portraying; attack/defend, meeting engagement, or maneuver/exit.

You can combine these such that 3=French moves in column and stays flexible, or 6=both sides move in column. Putting the French in column will keep them highly maneuverable, but the 1/3 FP penalty will make them rather impotent for direct fire. Know that the AI will never put them in line formation (but will do squares). So, use 2 and 4 only if the side needs to exit off the map (which the AI will do nicely if you script it to the exit hex).

In the next installment we will look at some scripting techniques and tips.

AI Scripting Part 1

To create a really clever AI script for a large, multi-corps scenario can be a mind boggling venture if you don't plan right or have the right tools. Although not neccessary you may want to print out a copy of the small 2D map, or just sketch out a rough picture of the terrain. Use this to sketch out your general attack Plan. Scripting a defense is rather easier and you probably don't need a sketch.

I do recommend that you download the OOB editor and learn how to use it - it has some wonderful features that can help you keep track of things, especially if you are modding someone else's scenario that uses bits and pieces of a larger OOB. There is a tool that will extract only the units that are present in the scenario so you don't have to hunt around for them in a large OOB file. You can also view relative force values for Infantry, Cavalry, and Artillery to aid in Play Balance.

OK here are some basics of Scripts:

1. There is no substitute for extensive alpha-testing. At least run manual vs manual and observe how the whole thing plays out. Several times. Play at least once against your crafted AI.

2. An order from a higher org when triggered will cancel out a previous order given to a lower org in the same chain of command.

This means if at 2PM you order 1st division of III Corps to attack point A, and at 2:30PM you order III Corps to attack point B, then 1st Division will cancel it's order at 2:30PM and join III Corps to attack point B.

The trick is to Give Orders to your Corps first, followed by Division, etc. This way you know that if you forget to script a lower org it will still at least get the Corps order. Also the Corps supply will only move on the Corps order, same with Division supply.

Re-supply on the attack is a problem for the AI - it rarely gets those wagons up close enough. A small consolation is that unsupplied units will tend to rout quicker and that sometimes sends them back near a supply wagon. The best solution is to form up your Corps and Divisions for an hour or 2 prior to surging toward the enemy to let the AI get those wagons up. If enemy units are nearby the AI will tend to hold the wagons farther back.

Perhaps the most versatile tool in the AI arsenal is the "No Order" command. In the next installment I will highlight some tricks for using this order to your (the AI's) advantage.

AI Scripting Part 2

The "No Order" command. Don't forget to always put -1 -1 for the location because the Scenario UI won't do it for you.

This command can serve several useful functions if used properly. Basically it allows the AI some flexibility to make it's own decision based on the situation at hand, and I have found good results using the "1" AI flag (flexible defense/offense) in conjuction with some well timed "No Order" commands (although if the battle is a cut and dry defense offense, stay with the "0" flag). Use this command:

1. If you dont want the AI to move unless provoked. Great for keeping the AI from moving out of a strong initial setup, like adjacent to a river crossing or along a ridge in line formation. If you know about how long it will take the human player to reach your front lines, THEN script in a flanking counterattack at the right time.

Sometimes with defend orders, the AI has a tendency to continually limber artillery in the movement phase, and unlimber in the defensive phase thus never firing a shot. This seems to be prevelant when the opponent is closing up within 2-4 hexes. I found that "No Order" will keep them in place and firing.

2. If you want to hold your cavalry (or other units) in reserve. Moving the AI cavalry forward with "Defend" commands just behing the location where the main battle will take place. Give it a "No Order" -1 -1 and it will stay back and do a fair job reacting to threats. Try to refrain from ever scripting the AI Cavalry with an "Extreme Attack" order and very rarely an "Attack" order. The human player will chew them up and spit them out.

Your best bet with scripting the attacking AI is to keep your cavalry and to a lesser extent artillery safe, and hope that some imaginative scripting catches the human off guard. If you just give an "Extreme Attack" to every unit and let it be you will burn out your troops with not much to show for it, and the human player will likely be wise to your folly.

For defense, stay put if the AI starts in good defensive positions, but send out some well timed flanking maneuvers to keep the human guessing.

And lastly, the best way to make multiple scripts in your scenario is to make one full set (as a template, if you will) in the scenario editor, and then edit the scenario file by copy/pasting the script lines using a text editor. You will find the scripts near the bottom of the .scn file just above the scenario description. the first line to recognize is a "1 0" followed on the next line with an integer representing the number of lines of script commands that follow it. Copy the integer and all the lines of numbers above the scenario description, and paste them just above the scenario description.

Finally, change the "1 0" to "2 0" (meaning a second set of scripts exists). Then open of the scenario and you will see the 2 sets of scripts. Make edits as needed.

It will help to take a look at the pre-made scripts in the stock BGN scenarios. Some of these (especially the BG Waterloo scenarios) I found could use some improvement, and could make for a tougher, more exciting game. Too bad because we all know that the AI needs all the help it can get.
simovitch

User avatar
berto
Posts: 21461
Joined: Wed Mar 13, 2002 1:15 am
Location: metro Chicago, Illinois, USA
Contact:

RE: AI Editing and Scripting

Post by berto »

Fascinating! I'd like to do AI scripting someday.

Since they come from the same designer (John Tiller), would your observations apply equally well to the later HPS lineup of Napoleonic (and ACW and other) games?
Campaign Series Legion https://cslegion.com/
Campaign Series Lead Coder https://www.matrixgames.com/forums/view ... hp?f=10167
Panzer Campaigns, Panzer Battles Lead Coder https://wargameds.com
User avatar
simovitch
Posts: 5906
Joined: Tue Feb 14, 2006 7:01 pm

RE: AI Editing and Scripting

Post by simovitch »

berto, I can't say for certain - I don't own those titles.
simovitch

Post Reply

Return to “John Tiller's Battleground Series”