Unciv
Unciv copied to clipboard
AI very stupid in war
The AI will just continue play as normal when they're at war and if their force is destroyed, they just happily hand over all of their cities (except for the capital) to reach a peace treaty.
I suggest to change the following (and I'm planning to start working on this soon):
- The AI should never give up more than 10% of their cities (or more than 1 if leq 5, no more than 2 if leq 20) to reach a peace treaty no matter the imbalance of force.
- once force becomes too low, the AI should go into full survival mode and start producing military units in all cities even cancelling existing build tasks and spend gold on military units
- this is a longer shot: if force is not in favor of AI then AI should withdraw and stick around their own cities, move ranged units into the city (and leave them there)
"bug" is not really the best label for this...? Your choice.
Kudos on your courage. I see clouds on the horizon - this AI might need to remember stuff over several turns? Weren't there preparations for "Tactical AI" somewhere, I haven't seen them yet?
Potentially, but can't it simply be a "is in survial mode" flag that gets set if:
- The player is at war
- One of the other civs at war with has a military force 50% stronger than my own
THEN
- Go into survival mode for at least 10 turns
- Switch production of all cities to a military unit that takes leq 10 turns to complete.
- Buy ranged units in cities that are being attacked (proxy -> in cities that aren't at 100% health) -> This might need the AI to move out a unit that is currently in the city first, but I doubt it's worth the extra effort and can always come later.
I just meant there was something brewing one should not work against - class TacticalAI
, by @vegeta1k95 #8381 - no idea what that does, but I'd want that idea if I were to go into improving AI...
no idea what that does, but I'd want that idea if I were to go into improving AI...
That was beginning of the (partial) port of Civ 5 Vox Populi tactical AI codebase. There are references to C++ sources in #8381 from which I got the idea, you can check it out and try to continue the port.
I am lately quite busy with issues at work and my studies, cannot work on Unciv for a while.
But tactical AI idea looks roughly as follows:
- Divide map into "zones of dominance": split map into chunks - most important chunks are around the cities, other areas are split equally randomly (this is already done via #8381)
- Assign to each such zone a "stregth", "posture" (behaviour of civ's units inside this zone: attrition attack, flanking, defence, withdrawal, city siege, etc) and "dominance" (who has more strength in this zone, us or enemy) - this is based on military units and cities in zone's reach.
- Gather all possible targets to attack on the whole visible map
- When gathering, assign to each target importance score based on unit type (GP > siege > range > melee > civilian etc), status (fortified, embarked, etc) and other stuff like this
- Sort targets in decreasing of importance
- Iterate own units and select those which could possibly attacks most important targets based on unit stats, attacker's and defender's "zone of dominance" which we computed earlier (e.g., less eager to attack units near the enemy city, more eager to attack units near own city)
- Process airplanes and nukes
- Those own units who have no valuable targets to attack are assigned other jobs, like fortifying around own cities, or at the forts on the borders with the enemy
There are more conditions of course which determines unit willingness to attack, like attacking resource tiles to pillage them and make player suffer penalties from absent resources
This is about tactical AI (about using military units on tactical level), there are also:
- Operational AI (which launches coordinated attacks and missions across the map),
- Strategic AI (mostly controls road to victory conditions)
- Economical AI (what to build, what to buy), etc. They are compeletely different beasts.
Thanks for the insights! That sounds like a really cool approach. I think I'll limit my changes to the things that feel buggy then and won't try to make bigger overhauls other than following this path. I still think we can go ahead with:
- Avoiding to trade exorbitant amounts if military force is near non-existent (this feels like a bug to me, because if you trade away everything you own including your cities, it's basically a slow suicide, so no way this ends up being a smart deal)
- Switching your production to military once you're seeing a significant decline in your military force and end up being much weaker than your opponent seems reasonable, too and doesn't interfere with the Tactical AI if I'm not mistaken.
Am Mo., 3. Apr. 2023 um 20:12 Uhr schrieb vegeta1k95 < @.***>:
no idea what that does, but I'd want that idea if I were to go into improving AI...
That was beginning of the (partial) port of Civ 5 Vox Populi tactical AI codebase. There are references to C++ sources in #8381 https://github.com/yairm210/Unciv/pull/8381 from which I got the idea, you can check it out and try to continue the port.
I am lately quite busy with issues at work and my studies, cannot work on Unciv for a while.
But tactical AI idea looks roughly as follows:
- Divide map into "zones of dominance": split map into chunks - most important chunks are around the cities, other areas are split equally randomly (this is already done via #8381 https://github.com/yairm210/Unciv/pull/8381)
- Assign to each such zone a "stregth" (based on military units in it's reach) and "posture" - behaviour of civ's units inside this zone: attrition attack, flanking, defence, withdrawal, city siege, etc
- Gather all possible targets to attack on the whole visible map
- When gathering, assign to each target importance score based on unit type (GP > siege > range > melee > civilian etc), status (fortified, embarked, etc) and other stuff like this
- Sort targets in decreasing of importance
- Iterate own units and select those which could possibly attacks most important targets based on unit stats, attacker's and defender's "zone of dominance" which we computed earlier (e.g., less eager to attack units near the enemy city, more eager to attack units near own city)
- Process airplanes and nukes
- Those own units who have no valuable targets to attack are assigned other jobs, like fortifying around own cities, or at the forts on the borders with the enemy This is about tactical AI, there is also Operational AI, which is compeletely different beast There are more conditions of course which determines unit willingness to attack, like attacking resource tiles to pillage them and make player suffer penalties from absent resources
— Reply to this email directly, view it on GitHub https://github.com/yairm210/Unciv/issues/9085#issuecomment-1494764166, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6CETIMJHIS5CR4ADWHTL73W7MHILANCNFSM6AAAAAAWPQ5DJM . You are receiving this because you authored the thread.Message ID: @.***>
https://github.com/yairm210/Unciv/pull/9109 https://github.com/yairm210/Unciv/pull/9096
@vegeta1k95 So I finally got around to looking at the TacticalAI. While it looks really good and comprehensive, the main class alone has 10kLOC. This seems like a monumental task to port to Kotlin. I can't even estimate how many dependencies need to be ported as well. Did you already have any roadmap laid out or was there a particular process you were planning to follow to get this done? This seems far from trivial and probably so far 5% of the work was done. I don't mean to belittle your effort, just want to understand how and if we can actually complete this.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 15 days.
So, 2 questions:
- Is this still relevant? Is the goal still to use Vox Populi as a reference? Genuine question
- How much of this is necessary to copy Vox Populi? How much of this can we copy Vox Populi? How much of this would ccopying Vox Populi not work with how Unciv is otherwise built?
If no one is actually working on this, I doubt someone new is going to go over the code and be able to port over all of the logic and dependencies, especially with any differences (intentional or otherwise) Unciv has from Civ 5. So these kinda are important questions that needs answers. Otherwise, this probably should be closed as just a generic general acknowledgement that the AI isn't as strong as it should be without any sort of actual statement about what is wrong with the AI
The AI should never give up more than 10% of their cities (or more than 1 if leq 5, no more than 2 if leq 20) to reach a peace treaty no matter the imbalance of force.
This should be fixed in #10370.
I agree with your last point and will see when I get around to it.
For now, I am going to close this since it is clearly stale, you can open a new issue with more up to date goals if you want.