• 📚 A new project from the admin: Check out PictureBooks.io, an AI storyteller that lets you create personalized picture books for kids in seconds. Give it a try and let me know what you think!

Artificial Intelligence in Test of Time

techumseh

Deity
Joined
Mar 12, 2002
Messages
2,477
Location
BC wine country
As anyone who's tried to make a ToT scenario knows, the built in AI is fairly useless. The AI-controlled unit mostly just wander around until the run into an enemy unit or city. An AI civ might be fighting for its life, and yet it's cities are building recycling centres. And so on.

So here is a naive question for the cyber-savvy: Is it possible to link one of the new AI programs like ChatGPT to Test of Time, so that the AI running the non-human civs actually makes intelligent, perhaps even brilliant, decisions?
 
Not being a programmer the only way I can think of is setting up a multiplayer game and teach the AI to play like a human until it gets good enough that it can make better decisions than the original AI.

But I'm guessing you're thinking more so of somehow getting the modern AI to directly interface with the backend of the game code and replace the in-game AI for single player & scenarios. For that I have no idea as it would probably require some programming genius. Maybe replacing is impossible but if the game's original AI decision making code could somehow be accessed and changed that would open the door to either humans or a modern AI making improvements to the original AI code upgrading instead of replacing. But I'm not a programmer so I guess we'll see what other more knowledgeable people say.
.
 
Wouldn't it make more sense, and be more practical, to use lua events to override the ai?
 
Wouldn't it make more sense, and be more practical, to use lua events to override the ai?
Yes. The large language models aren't a general form of intelligence. If we were trying to design a computer program that could play as the player and understand event text, etc, then an LLM would be a useful part of that program, but there would be a lot more to it. This video talks about how an LLM was given extra tools in order to "understand" and beat Pokemon Blue. In any case, we can't give arbitrary commands to an AI player.

We can use Lua to exercise a lot of influence/control over the AI.

Choosing Production

Using Lua, we can change a city's current production order to whatever we like. Using the canBuild mechanic, we should be able to give the AI only one thing to build at a time, so it won't decide to build something else. The hard part is coming up with a way of deciding exactly what should be produced, especially if you want the code to be portable between scenarios.

City Worker Allocation

Lua lets us choose what tiles a city is working using city.workers and city.specialists, but I don't know if/when the AI will revert back to its defaults. This also seems easiest to compensate for with a relatively small amount of "cheating".

Taxes and Research

We can force a tribe to research the "right" thing by changing tribe.researching, if we can't adequately influence it by changing tech.aiValue and tech.modifier. We can't change a tribe's tax rates, but we can give/take gold and science progress if we want.

Settlers

We can use civ.scen.onCanFoundCity to disallow an AI from founding "bad" cities. If we really want to, we can also use civ.createCity (and delete a settler) to found a city if changing tile.fertility doesn't make the AI "want" to found a city. I presume we can give goto orders to settlers (IIRC, @JPetroski couldn't give Sea Transport role units goto orders, since they immediately try to do something else, but that was fixed by changing their role), as well as giving a settler orders to change terrain. In fact, I believe I could give non-settler units change terrain orders via Lua, and they'd do it. If all else fails, we can spend settler movement allowances and change terrain under them.

Moving Units to Attack

As far as I know, we can't actually force units to attack other units, since the goto order will clear when they're adjacent to an enemy unit. If we want units to attack in groups instead of one by one, we should be able to give them orders to go to a "rally point", and then clear their movement so they can't wander off on their own. Then, when there are "enough" units in the stack, they can proceed.

When working on 1937 with @techumseh I found out that the AI chooses what unit to move by going through their IDs one by one, and moving each unit in turn. IIRC, the AI only goes through the list twice. In any case, we can't make units move/attack in an arbitrary order, which means the AI's attack will be at a disadvantage, since we can't make it go from best to worst attack.

There is also the issue of deciding where to attack, and how many units should be involved.
 
Thank you, that's interesting. I am totally convinced that Lua can do amazing things to make scenarios more realistic and more fun generally. However, it shares the same limitation as macro events, which is that its use in a scenario must be anticipated in advance by the designer. You can control the city build by programming it in advance, but you can't give the AI the intelligence to change it if the situation warrants, other than the limited ability of the existing AI to do so. And, as you say, the capacity to improve the combat tactics of the existing AI is very limited. Anyway, I think it's an interesting question. Given the rate of development of AI, I suspect the answer will continue to evolve.
 
Thank you, that's interesting. I am totally convinced that Lua can do amazing things to make scenarios more realistic and more fun generally. However, it shares the same limitation as macro events, which is that its use in a scenario must be anticipated in advance by the designer. You can control the city build by programming it in advance, but you can't give the AI the intelligence to change it if the situation warrants, other than the limited ability of the existing AI to do so. And, as you say, the capacity to improve the combat tactics of the existing AI is very limited. Anyway, I think it's an interesting question. Given the rate of development of AI, I suspect the answer will continue to evolve.
Skynet_Meme.jpg
 
:lol:

Anyway yeah that's why I didn't suggest LUA as correct me if I'm wrong but it seems like you can give the AI nudges here and there but not quite overhaul all of it's situational behavior in a sandbox game.

Funnily enough a coincidental chat about using LLM AI to develop game AI has just kicked off (picture below) on the Sid Meier's Colonization Fans Discord I run between Civ modding legend and Old World dev @Dale with other game devs. Although they're of course talking about making new games from scratch which we're not. With Civ2 there's no publicly accessible source code to really get into the AI code (& we don't even know if Firaxis have it either as it possibly went down with the ship at Microprose). @axx can confirm but I think the Civ2Clone project guys are recreating Civ2 functions using game observation, config files and wiki info like many other fan projects out there do (OpenRA, Dune 2 Legacy, MoM-IME come to mind) instead of a full disassembly and reassembly project (OpenCiv1, ReCol, ReMoM, and Dune 2 Dynasty come to mind) which if it had been the later it would result in the public having access to Civ2's original AI code leading to all sorts of cool stuff. While I'm aware of several current and old Civ2 re-creation attempts I'm not aware of anyone attempting a full disassembly and reassembly sadly. If that happens it'll really open the door to all sorts of cool stuff, including the AI reprogramming ideas in this thread..

1760675749724.png
 
Last edited:
… However, it shares the same limitation as macro events, which is that its use in a scenario must be anticipated in advance by the designer. You can control the city build by programming it in advance, but you can't give the AI the intelligence to change it if the situation warrants, other than the limited ability of the existing AI to do so. And, as you say, the capacity to improve the combat tactics of the existing AI is very limited…
The Prof.'s lua template has a very easy to use tool that allows you to create polygons within your scenario. When in cheat mode in ToTPP it can be accessed through the crtl-shift-F4 keys and selecting the "Start Polygon Script" box.

1760709940278.png

The advantage of this, from a designer's perspective, is that it allows you, as the name implies, to create or 'designate' any number of zones on your map as special areas. Whenever any number of enemy units enters said defined zone you can use lua to trigger any kind of reaction or event you deem appropriate.

I believe I used this method to very good effect in my Battle of Italy scenario whereby, in my case, I set a whole series of zones throughout the map that would trigger historical German reaction forces whenever Allied units entered them. In particular, as I couldn't foresee ahead of time where the human Allied player would launch their major invasions (there are more than a dozen possible beach areas on the map for them to choose from) I had German reaction forces pop up depending only on where Allied invasion forces actually landed (this was important to accomplish because it allowed me to remain within the historical limits of the German order of battle for the Italian campaign, instead of having tons of German units just pop up everywhere).

Your imagination is really the limit to what you may consider to be either the trigger or the AI reaction to it (it doesn't necessarily have to be exclusively generating ground forces, it could also be modifying city production or having automatic declarations of war, etc). It really depends on what you need or want it to accomplish.

Of course it's not the same as having an artificial intelligence thinking and reacting on its own based on enemy actions but I've found it does provide designers some degree of flexibility in giving the AI a partial 'thinking' ability.

The GoTo command, though not perfect (especially in the case of naval units), can be a useful tool particularly in scenarios where the battlefield is well delimited and constrained (especially when the opponents are going in the opposite direction (think the Russian front)).

Another factor, I've found, in encouraging battle between opposing forces is the production cost difference between units. This may be more difficult to remedy where production plays an important part in your scenario but I've found for example that say a missile type unit that cost 10 production is far more likely to attack an enemy unit that costs at least 40 production point than if it cost 20, i.e. it seems the greater the difference between the attacking and defending units cost the more likely the AI will attack.

Anyhow, these are some of my personal observations based on my own design experience.

I hope this was useful.
 
Last edited:
Moving Units to Attack

As far as I know, we can't actually force units to attack other units, since the goto order will clear when they're adjacent to an enemy unit. If we want units to attack in groups instead of one by one, we should be able to give them orders to go to a "rally point", and then clear their movement so they can't wander off on their own. Then, when there are "enough" units in the stack, they can proceed.

When working on 1937 with @techumseh I found out that the AI chooses what unit to move by going through their IDs one by one, and moving each unit in turn. IIRC, the AI only goes through the list twice. In any case, we can't make units move/attack in an arbitrary order, which means the AI's attack will be at a disadvantage, since we can't make it go from best to worst attack.

There is also the issue of deciding where to attack, and how many units should be involved.
Why give attack orders when you could just calculate the combat results and apply the damage directly?
 
Why give attack orders when you could just calculate the combat results and apply the damage directly?
I hadn't thought of that. I don't see any reason why that wouldn't work, apart from not getting an attack animation. Sound can be played, and movement points deducted by event as well.
 
I think training an AI to recognise the rules file would be interesting and certainly help hunt bugs.
Eventually having the AI being able to understand Lua and create a framework for a scenario is the next step.
If the AI could be used to mess with hex values and somehow access the CIV2 source code values, that a holy grail.
 
I think training an AI to recognise the rules file would be interesting and certainly help hunt bugs.
Eventually having the AI being able to understand Lua and create a framework for a scenario is the next step.
If the AI could be used to mess with hex values and somehow access the CIV2 source code values, that a holy grail.
The only unit type the AI uses ruthlessly and frighteningly on it's own are those with the, "can make paradrops," flag. Beware having ungarrisoned cities (or cities whose garrison has just been destroyed) in my long experience.
 
Back
Top Bottom