Artificial Unintelligence

it isn't the only necessary step: for example, if the AI wants to kill a unit that is stacked with another combat unit, executing attacks in a certain order is important.

Could you kindly elaborate on what you mean by this?

Assuming however, that a change to combat mechanics is already implemented to select the best defender from a stack.
 
Could you kindly elaborate on what you mean by this?

Assuming however, that a change to combat mechanics is already implemented to select the best defender from a stack.

Let's say two units are stacked: one is at full health with 12 combat strength, the other is also at full health at 8 combat strength. The AI has two units that can attack the tile: one with an effective combat strength of 24 and one with a combat strength of 12. If the AI attacks with the stronger unit first, the unit with 12 combat strength is taken down to about 32 health, which puts it at 7.87 combat strength; this means that the other unit becomes the best defender for when the weaker AI unit attacks, taking 68 damage as well, but neither unit is killed from the combined attack. If the AI attacks with the weaker unit first, the 12 strength unit is taken down to 60 health, which means its effective combat strength is 9.6, maintaining it as the best defender; when the AI then attacks with the stronger unit, enough damage is dealt to completely kill the 12-strength defender.
By default, the AI tries to attack with its strongest units first and its weakest units last, albeit ignoring a few modifiers that might change strength order (eg. a stronger unit might be weaker because it would be attacking across a river) and favoring ranged attackers before melee attackers.
 
albeit ignoring a few modifiers that might change strength order (eg. a stronger unit might be weaker because it would be attacking across a river)

To your knowledge, what other modifiers does the AI ignore when calculating/guessing combat outcomes (and would these modifiers implemented in v10)?
 
To your knowledge, what other modifiers does the AI ignore when calculating/guessing combat outcomes (and would these modifiers implemented in v10)?

Effective attack strength is always calculated assuming the unit attacks out of the plot it is currently located. If this is not the, eg. the unit needs to move a tile before attacking, the effective attack strength is miscalculated: river crossings, great general modifiers, friendly territory bonuses, outside friendly territory bonuses, and other effects that depend on which plot the unit attacks from onto the tile are all affected. Fixing this is a bit trickier than usual thanks to 1UPT: it means I'd have to constantly compute the best plot an attacker would attack from, so if a unit that is ordered to attack before a certain unit occupies the given unit's best attack tile, it would recalculate its new best attack tile, then re-sort itself in the list accordingly. Very slow, especially for carpets of doom and/or if I handle units that can move after attacking as well so that they can vacate the next unit's best attack plot if needed (and even slower if they can attack twice per turn and must either choose between attacking twice and staying or attacking once and vacating).
 
Great project. Looking forward to v10. I've tried compiling what you've made so far myself but unfortunately the AI freezes after 30 or so turns into the game.

I was playing around with making your mod work in multiplayer and noticed a few problems. I checked whether or not your XML changes were making it into the database and only found some were. A few of the files seem to have errors in them which causes the whole XML file to fail loading.

The errors:
New_CIV5AICityStrategies
AICityStrategy_Flavor instead of AICityStrategy_Flavors


New_CIV5AIEconomicStrategies
AIEconomicStrategies_Flavors instead of AIEconomicStrategies_Player_Flavors (??)


New_CIV5AIMilitaryStrategies
AIMilitaryStrategies instead of AIMilitaryStrategy_Player_Flavors (??)


New_CIV5CitySpecializations
CitySpecializations_Flavors instead of CitySpecialization_Flavors


New_GlobalAIDefines
<Where Name="AI_STRATEGY_MINIMUM_SETTLE_FERTILITY /> - Missing the last ".
Also POLICY_WEIGHT_PERCENT_DROP_NEW_BRANCH is added rather than updated

After changing these values the XML files all load up correctly and all changes make it through to the database with no errors in the logs.

EDIT:
Fixed XML files attached. These came from the workshop with the modded DLL as well.
 

Attachments

Thanks, half of those are caused by me not paying attention, and the other half is caused by the game's database setup changing from vanilla Civ5 to BNW; for the latter half, I'll have to duplicate the necessary sections with renamed versions to keep vanilla Civ5 compatibility. I'll upload fixed version soon.
 
In other news, I've been messing around trying to implement my own version of Active AI in multiplayer, and I think I've got a good framework down, I just need to test it to make sure it works and doesn't cause unintentional side-effects before I commit it to the Experimental branch. Basically, the way it works is that whenever the AI wishes to contact a human player who has simultaneous turns, it will send a notification to that player saying "A deal has been proposed". Once the player clicks on that notification, the leaderhead scene pops up as if it were singleplayer, essentially letting the player control when they want to respond to AI diplomacy stuff. I need to test it quite thoroughly because I messed around with a lot of code that controls how AI diplomacy requests are sent, both in singleplayer and in multiplayer, and I need to make sure everything still works despite my reshuffling. If things are working fine, I'll see if I can add in localizations for "[player] wishes to contact you", which will be used for notifications about non-deal leaderhead diplomacy.

Very interested in this - I'd be happy to help test if needed.
 
Very interested in this - I'd be happy to help test if needed.

Thanks, but I can manage on own when it comes to testing. I've already temporarily redirected the two relevant code bits so that what should happen in multiplayer happens in singleplayer, and I don't think I need to test for sync issues (famous last words?). Right now it's pretty buggy, but I have gotten the AI to send the player a notification and have gotten the leaderhead scene to pop up with the AI's deal once the notification is clicked. The notification text is bugged though, the notification does not disappear once you click it, and only the first notification's leaderhead scene works, the other ones don't activate at all.
 
The notification text is bugged though, the notification does not disappear once you click it, and only the first notification's leaderhead scene works, the other ones don't activate at all.

Hmm, maybe JaiiDerHerr has run into this problem and can help?
 
Hmm, maybe JaiiDerHerr has run into this problem and can help?

JdH probably came up with a different solution than me, so I don't know how much he'd be able to help. In any case, I seem to have fixed the bugs, they were caused by me not understanding how the notifications update function was called (I thought it was called once per turn, it's actually called constantly while the player's turn is active). A single notification pops up saying "[Leader] has proposed a deal", the player clicks on it, the leaderhead screen appears with the AI offering a deal, the player can choose to accept or refuse it, the notification disappears when the player quits out of the leaderhead scene or ends their turn without talking to the AI. Still need to test how it holds up when the AIs get real chatty. I should probably also test for sync issues, since one part of my framework replaces a single variable used for temporary storage with a 23x23 array, and I'm worried the game will have trouble syncing an array of 529 throwaway CvDeal variables (since multiple deals can be offered during simultaneous turns, each one needs to have its own, separate, temporary storage while the game is waiting for the player to accept or refuse the deal).
 
JdH probably came up with a different solution than me, so I don't know how much he'd be able to help. In any case, I seem to have fixed the bugs, they were caused by me not understanding how the notifications update function was called (I thought it was called once per turn, it's actually called constantly while the player's turn is active). A single notification pops up saying "[Leader] has proposed a deal", the player clicks on it, the leaderhead screen appears with the AI offering a deal, the player can choose to accept or refuse it, the notification disappears when the player quits out of the leaderhead scene or ends their turn without talking to the AI. Still need to test how it holds up when the AIs get real chatty. I should probably also test for sync issues, since one part of my framework replaces a single variable used for temporary storage with a 23x23 array, and I'm worried the game will have trouble syncing an array of 529 throwaway CvDeal variables (since multiple deals can be offered during simultaneous turns, each one needs to have its own, separate, temporary storage while the game is waiting for the player to accept or refuse the deal).

Looking forward to seeing the finished product - especially since you put your work in Github for others to see.
 
That's it, this is the last straw: I had a gander at the AI's flavors for policies, and it turns out that not only are a lot of policies' flavors set incorrectly, eg. happiness flavor when the policy has nothing to do with happiness or gold flavor when there is no gold involved, but Firaxis has also flatout forgotten to include proper flavors for the policies/tenets Mercenary Army (flavor of 1 Gold, which is nothing), Treasure Fleets (flavor of 1 Gold, which is nothing), Futurism (no flavors), Lightning Warfare (no flavors), and Universal Healthcare for Autocracy and Order (two entries of offense flavors).

This is ridiculous, I'm going to start working on the flavor system...
 
That's it, this is the last straw: I had a gander at the AI's flavors for policies, and it turns out that not only are a lot of policies' flavors set incorrectly, eg. happiness flavor when the policy has nothing to do with happiness or gold flavor when there is no gold involved, but Firaxis has also flatout forgotten to include proper flavors for the policies/tenets Mercenary Army (flavor of 1 Gold, which is nothing), Treasure Fleets (flavor of 1 Gold, which is nothing), Futurism (no flavors), Lightning Warfare (no flavors), and Universal Healthcare for Autocracy and Order (two entries of offense flavors).

This is ridiculous, I'm going to start working on the flavor system...

You're really going to be annoyed by this then: FLAVOR_OFFENSE for policies is only used for Ideological tenets and only Ideological tenets that are level 3. Oh, and CvHomelandAI::EstablishHomelandPriorities checks the civ's FLAVOR_OFFENSE, but never actually uses it for anything.
 
You're really going to be annoyed by this then: FLAVOR_OFFENSE for policies is only used for Ideological tenets and only Ideological tenets that are level 3. Oh, and CvHomelandAI::EstablishHomelandPriorities checks the civ's FLAVOR_OFFENSE, but never actually uses it for anything.

Eh, CvHomelandAI::EstablishHomelandPriorities also does that with Tile improvement flavor and Sea tile improvement flavor, so I'm not that annoyed by that. After all, flavor systems are meant to facilitate picking the best choice out of many choices, not trying to determine which order certain algorithms are executed.

Also, I found plenty of places where Offense flavor was used in policies: Honor opener, Warrior Code, Discipline, Military Tradition, Volunteer Army, Arsenal of Democracy, Elite Forces, Mobilization, United Front, Police State, Third Alternative, and Total War all have FLAVOR_OFFENSE entries, as does Universal Healthcare's Autocracy and Order variants (though I think those were done by mistake). I am more bothered by the fact that the game has no separate Tourism flavor and by the fact that ideologies are chosen for their level 3 tenets without consideration of what those tenets might be focused towards (eg. Space Procurements is Spaceship with Gold, Spaceflight Pioneers is Spaceship with Great People, Gunboat Diplomacy is Diplomacy with Offense, etc.); I've already fixed the former and will work on the latter once I'm over my current hurdle.

I'm currently debugging my Lua flavor script, it's not activating at all for some reason (I have the function set to output a message in Firetuner when it's run and no messages are outputted). Since I'm relying on this script to generate flavors for things like Petra and Neuschwanstein, as well as enabling mods to generate flavors for their own, weird buildings and wonders, having the script work is a fairly high priority.
 
Hi Delnar, quick question if you will...

The AI employs a number of
Code:
[some vector].ChooseFromTopChoices(iNumChoices, &fcn, "some text string");
calls.... would you happen to know where the "ChooseFromTopChoices" function is defined (and what effect does the random delegate have, and to what extent)? The find-all function VS provides isn't showing anything for this :crazyeye:
 
Also, I found plenty of places where Offense flavor was used in policies: Honor opener, Warrior Code, Discipline, Military Tradition, Volunteer Army, Arsenal of Democracy, Elite Forces, Mobilization, United Front, Police State, Third Alternative, and Total War all have FLAVOR_OFFENSE entries, as does Universal Healthcare's Autocracy and Order variants (though I think those were done by mistake). I am more bothered by the fact that the game has no separate Tourism flavor and by the fact that ideologies are chosen for their level 3 tenets without consideration of what those tenets might be focused towards (eg. Space Procurements is Spaceship with Gold, Spaceflight Pioneers is Spaceship with Great People, Gunboat Diplomacy is Diplomacy with Offense, etc.); I've already fixed the former and will work on the latter once I'm over my current hurdle.

They're set in the XML for those policies, but CVPolicyAI::ChooseNextPolicy only checks FLAVOR_OFFENSE in the aLevel3Tenets.size() > 0 condition, completely ignoring it for non-level 3 tenets and therefore regular policies completely. It doesn't check it at all in the non-BNW DLLs.
 
Actually, looking at it now and maybe I'm missing something, but I don't actually see it using flavors anywhere else when it's selecting policies or an Ideology in general. It sets their flavor elsewhere, but it never seems to factor it in within CVPolicyAI::ChooseNextPolicy or DoChooseIdeology.
 
Ah, disregard me. I see it now. The flavor is factored into the weight and then the vector of adoptable policies is sorted by weight before ChooseFromTopChoices is called.

To answer ThorHammerz question, ChooseFromTopChoices is a method of CvWeightedVector which must be defined in the engine and not the DLL.
 
Back
Top Bottom