Tactical AI in the works but how realistic is CivV integration?

schmop

Chieftain
Joined
Nov 19, 2011
Messages
22
Hi,

I've been working in my spare time on a tactical AI for CivV (or any hex based strategy game I guess). Since no integration is possible before the DLL is released (at least that is my understanding), I've created for my testing purposes a small interface mimicking the tactical aspect of CivV (just units, no cities, only basic terrain, crappy graphics, etc.). The AI has gotten strong and usually beats me every time I play it (although many features are still missing, like embarkment, promotions...) so my focus is now gradually shifting towards preparing the integration with the DLL.

The thing is, I have never modded for Civ before (hmmm... actually I think I added a tank with two canons in CivII twenty years ago!) and have no idea what to expect. This is my fantasy strategy for how the integration would work:
1. At the start of AI player's turn, read the entire state of the board and transform it to the mod's own data structure
2. Identify units that can attack or be attacked
3. Run the mod's AI algos on the identified units
4. Translate unit actions (moves and attacks) generated by the mod into actual CivV actions
5. Let the default AI handle the rest of the units and whatever else it does
Could someone knowledgeable comment on the realism of this strategy? The goal is to let the AI play as it usually does, but just take over for combat, an area where it kinda sucks.

I'm guessing there is a lot to be learned by looking at the CivIV dll, but I'm afraid the 1UPT system might have forced a total AI overhaul (and I'm quite lazy). To make matters worse, my AI so far is written entirely in Java because I can prototype and test ideas a lot quicker that way. But I took care not to do anything too Javaesque so the conversion to C++ should be straightforward.

Hmmm... I could write a hundred pages about what I've done so far in the project (it uses a kind of alpha-beta!), what I want to do and questions about integration but I'm curious to see any replies on what I've said so far... or just if there is anyone out there interested in discussing this stuff at all.

Cheers
 
This is my fantasy strategy for how the integration would work:
1. At the start of AI player's turn, read the entire state of the board and transform it to the mod's own data structure
2. Identify units that can attack or be attacked
3. Run the mod's AI algos on the identified units
4. Translate unit actions (moves and attacks) generated by the mod into actual CivV actions
5. Let the default AI handle the rest of the units and whatever else it does
Could someone knowledgeable comment on the realism of this strategy? The goal is to let the AI play as it usually does, but just take over for combat, an area where it kinda sucks.
Could already be done in Lua, except perhaps point 1, it maybe too slow to process then.

I'm using 2-3-4-5 to force interception/sweep on fighters or force destroyers to hunt subs in my WWII mod for vanilla civ5.
 
Could already be done in Lua, except perhaps point 1, it maybe too slow to process then.

I'm using 2-3-4-5 to force interception/sweep on fighters or force destroyers to hunt subs in my WWII mod for vanilla civ5.

Huh. I had no idea so much could be done in LUA... So you can:
-Query the board state before a player's turn (for terrain, improvements, cities, units...)
-Give units orders (land units as well) and query the board state AFTER the orders are carried out
-At some point tell the AI you're finished and have it complete the remainder of the turn
Is this correct?

I don't suppose you can invoke a native DLL as well? If that were the case I might not even have to wait for the SDK DLL.
 
Yep, using the GameEvents PlayerDoTurn, it's called before an AI player starts using it's units.
 
Would I be wrong in saying that access to the DLL is not really important given we can do so much in LUA?

I gather the DLL access would enables us to write new event handles and tweak balance issues, but LUA is more than sufficient to do things in-game as long as you find an appropriate event to hook into!
 
Would I be wrong in saying that access to the DLL is not really important given we can do so much in LUA?

I gather the DLL access would enables us to write new event handles and tweak balance issues, but LUA is more than sufficient to do things in-game as long as you find an appropriate event to hook into!

You may be right.

But among the things I would like to do, I see several that probably require the dll:
-simulating unit attacks independently from the state of the board
-experimenting with randomless combats (could really improve the AI)
-toying with ai missions. This may be possible in lua but I couldn't find any documentation for the mission types passed to unit:PushMission. In particular, I need to control the order in which units move.

Then there's performance. Does anyone know if it is possible to call native libraries from lua in the CivV environment?
 
-toying with ai missions. This may be possible in lua but I couldn't find any documentation for the mission types passed to unit:PushMission. In particular, I need to control the order in which units move.

I know that Gedemon is probably your best source of info on this point. Have a good look over his RED WWII mod. I am still learning LUA so probably not a good source to explain pushing missions (actually that's one of the dark areas of the SDK I have not figured out yet).
 
look at the Mission table in the DB.

Spoiler :
"MISSION_MOVE_TO"
"MISSION_ROUTE_TO"
"MISSION_MOVE_TO_UNIT"
"MISSION_SWAP_UNITS"
"MISSION_SKIP"
"MISSION_SLEEP"
"MISSION_ALERT"
"MISSION_FORTIFY"
"MISSION_GARRISON"
"MISSION_SET_UP_FOR_RANGED_ATTACK"
"MISSION_EMBARK"
"MISSION_DISEMBARK"
"MISSION_AIRPATROL"
"MISSION_HEAL"
"MISSION_AIRLIFT"
"MISSION_NUKE"
"MISSION_PARADROP"
"MISSION_AIR_SWEEP"
"MISSION_REBASE"
"MISSION_RANGE_ATTACK"
"MISSION_PILLAGE"
"MISSION_FOUND"
"MISSION_JOIN"
"MISSION_CONSTRUCT"
"MISSION_DISCOVER"
"MISSION_HURRY"
"MISSION_TRADE"
"MISSION_REPAIR_FLEET"
"MISSION_SPACESHIP"
"MISSION_CULTURE_BOMB"
"MISSION_FOUND_RELIGION"
"MISSION_GOLDEN_AGE"
"MISSION_BUILD"
"MISSION_LEAD"
"MISSION_DIE_ANIMATION"
"MISSION_BEGIN_COMBAT"
"MISSION_END_COMBAT"
"MISSION_AIRSTRIKE"
"MISSION_SURRENDER"
"MISSION_CAPTURED"
"MISSION_IDLE"
"MISSION_DIE"
"MISSION_DAMAGE"
"MISSION_MULTI_SELECT"
"MISSION_MULTI_DESELECT"
"MISSION_WAIT_FOR"
"MISSION_SPREAD_RELIGION"
"MISSION_ENHANCE_RELIGION"
"MISSION_REMOVE_HERESY"


OT: I hadn't noted MISSION_MULTI_SELECT and MISSION_MULTI_DESELECT before, maybe something usable for a UI mod with multiple units per tile ?
 
Good luck guys using the game's mission stuff ! IMHO I don't see how the tactical AI could be improved to an acceptable level without controlling in detail each and every unit movement. Since 2 units cannot occupy the same space, given the need to shelter weak ranged units behind frontline melee, and given the advantageous flanking bonuses, coordination between units and their movement sequence becomes significant. Also the default path finding routine will make stupid choices such as embarking units near enemy naval superiority, moving low defense units next to strong enemy melee units, leaving the road/rail network to optimize this turn's move but crap out the next etc...
 
Thanks for the list Gedemon.

Good luck guys using the game's mission stuff ! IMHO I don't see how the tactical AI could be improved to an acceptable level without controlling in detail each and every unit movement. Since 2 units cannot occupy the same space, given the need to shelter weak ranged units behind frontline melee, and given the advantageous flanking bonuses, coordination between units and their movement sequence becomes significant. Also the default path finding routine will make stupid choices such as embarking units near enemy naval superiority, moving low defense units next to strong enemy melee units, leaving the road/rail network to optimize this turn's move but crap out the next etc...

Well, even with the dll I don't plan to evaluate "flanking bonus moves", there's just too many of them. But controlling the order of the moves is absolutely crucial. And things like reevaluating a move if a unit discovers something in the FOW. Is there an event sent when an enemy unit is spotted during the turn? I'm looking at the events in the wiki and the list seems VERY short.
 
Back
Top Bottom