Artificial Unintelligence

Looks interesting, can't wait to try this out :D, great job!

Quick question however regarding the missionary turn limit: does that mean the AI will now completely disregard any cities outside the range of 8 turns of movement, or will they just assign a lower priority?
 
Quick question however regarding the missionary turn limit: does that mean the AI will now completely disregard any cities outside the range of 8 turns of movement, or will they just assign a lower priority?

It's complete disregard for anything outside of range if you're running unmodified code; thanks to your heads up however, I might make a few tweaks to the HaveNearbyConversionTarget() code so it's no longer a clear-cut thing. Oddly enough, even though the game's default for the value is 10, Firaxis devs put a comment at the only place the variable is called, saying that the check is for at least 8 moves.
Also, the range isn't 8 moves, it's actually 8 * (Missionary movement range) tiles from the player's capital, so if two civs are separated by a giant mountain range and are actually 20 moves apart, the AI will still send missionaries.
 
Sounds like the code is checking for the absolute distance (Point A to Point B in a straight line), rather than the number of turns it takes to actually get there....?

It could also be made to scale to map size as well, calling the GridWidth and GridHeight values from Civ5WorldInfos.xml (or the World Size names... but that won't be scalable with custom map sizes).

So something like

Code:
8 * (function that returns a value/co-efficient between a range of X <---> Y, based on map size) * missionary moves


Also, what does "Area is full" (near the bottom of your XML changes list) do for the AI? Does that just mean they will start looking for new places to settle on another island?
 
Sounds like the code is checking for the absolute distance (Point A to Point B in a straight line), rather than the number of turns it takes to actually get there....?

It could also be made to scale to map size as well, calling the GridWidth and GridHeight values from Civ5WorldInfos.xml (or the World Size names... but that won't be scalable with custom map sizes).

So something like

Code:
8 * (function that returns a value/co-efficient between a range of X <---> Y, based on map size) * missionary moves

That's almost exactly how it works (remember, I am reading stuff from source code), but without the map-scaling part. It's (XML value for missionary moves) * (plot distance between target city and player's capital) * (missionary moves).

The quick changes I've implemented on my part makes it now calculate the distance from any of the player's non-puppet cities instead of just from the capital; in the long run, I'll see if I can swap out the distance part with an A* path calculation, though the latter can be quite computationally expensive.

Also, what does "Area is full" (near the bottom of your XML changes list) do for the AI? Does that just mean they will start looking for new places to settle on another island?

The parameter ties into the Early Expansion economic strategy. "Areas" are actually continents, so the "Area is Full" parameter works by checking how many tiles on the player's starting continent are owned by any player; if more than (value)% of land tiles on the continent are already owned, the Early Expansion economic strategy will no longer trigger.
 
The parameter ties into the Early Expansion economic strategy. "Areas" are actually continents, so the "Area is Full" parameter works by checking how many tiles on the player's starting continent are owned by any player; if more than (value)% of land tiles on the continent are already owned, the Early Expansion economic strategy will no longer trigger.

So in other words, if the "continent" is a small archipelago 1-2 city sized island, this particular economic strategy gets screwed over? :lol:
 
So in other words, if the "continent" is a small archipelago 1-2 city sized island, this particular economic strategy gets screwed over? :lol:

The AI does not depend on the Early Expansion strategy for island maps: instead, it depends on Island Start, Expand to Other Continents, Really Expand to Other Continents, and Naval Map economic strategies. These strategies do not make use of the "Area is Full" parameter.
 
I'm going to be using the lite version for now. When you come close to a finished project would you consider working with Whoward to integrate your mod's DLLs so I don't need to choose?
 
I'm going to be using the lite version for now. When you come close to a finished project would you consider working with Whoward to integrate your mod's DLLs so I don't need to choose?

I'm already running through my current changes and converting to Whoward's "code format" (ie. wrapping everything I can into preprocessor directives for easy merging and feature toggling); future changes will all be in Whoward's code format as well. As a result, merging should be a sinch (once I'm done with my conversions), both for Whoward to merge my changes with his DLL and for me to merge existing AI changes with my DLL (and maybe improve on those as well).
 
This might be a little off-topic, but in HandicapInfos.xml, is the 'HANDICAP_AI_DEFAULT'' setting kind of like the ''base'' setting for the AI? (i.e. these values are applied before the modifiers from Settler &#8594; Deity are applied).
 
This might be a little off-topic, but in HandicapInfos.xml, is the 'HANDICAP_AI_DEFAULT'' setting kind of like the ''base'' setting for the AI? (i.e. these values are applied before the modifiers from Settler &#8594; Deity are applied).

The game's code uses two handicap levels: a per-player one for things like diplomacy (I honestly couldn't find anything else where this is used) and a global "game" handicap for everything else. The global "game" handicap is set by the human player's difficulty level upon game creation (though I don't know what happens in multiplayer) and determines pretty much everything you'd tie to difficulty levels, from bonus production to ideal earlygame city count (higher difficulty level AIs need more cities than on Prince before Early Expansion switches off).
The HANDICAP_AI_DEFAULT you're talking about is the per-player handicap level AI players get assigned, even though their routines will almost always interact with the game's handicap, and therefore the human player's handicap, instead.
 
Mmmm, a little confusing, but ok xD.

Also, if I have another mod that modifies some of the same Defines values, which one would take precedence (i.e. ''OPINION_WEIGHT_LAND_FIERCE'' is set to 200 for one mod, and 125 for your mod)? Would it just be the mod that is loaded last?

Also, with regards to the AI flavours (leaderheads), in your observation of the code, is the default 4-9 range sufficient enough to properly ''incentivize'' the AI into different playstyles/form distinctive personalities? (Because as they are all crazy.... well, Montezuma more crazy than the others). Would an expanded range (i.e. 1 to 20 or something) be sufficient in injecting some semblance of sanity/stability and/or distinctive personality into them?
 
I've got to say, having to update functions with preprocessor directives helped me catch a few oversights in my code. Military AI, Tactical Map Analysis, and Unit changes (including promotion calculation tweaks and a lot of Smart AI stuff) have been uploaded to GitHub. Keep in mind some of my code may be a bit unoptimized (eg. Tactical Map Analysis will call the pathfinder twice for ranged units in its current state, I'll probably fix this via an overload of the used Smart AI function that operates on a bool pointer indicating if a tile can be moved through).

Also, if I have another mod that modifies some of the same Defines values, which one would take precedence (i.e. ''OPINION_WEIGHT_LAND_FIERCE'' is set to 200 for one mod, and 125 for your mod)? Would it just be the mod that is loaded last?
I am unclear how load order is handled in Civ5.

Also, with regards to the AI flavours (leaderheads), in your observation of the code, is the default 4-9 range sufficient enough to properly ''incentivize'' the AI into different playstyles/form distinctive personalities? (Because as they are all crazy.... well, Montezuma more crazy than the others). Would an expanded range (i.e. 1 to 20 or something) be sufficient in injecting some semblance of sanity/stability and/or distinctive personality into them?
Ho boy, flavors... basically, anything above 10 will be "crazy", it's just that the game lets you go up to 20. The default value is 5, but even the smallest change from 4 to 5 or 5 to 6 can have huge effects on the DLL side of things, especially for code that relies on the ratio of two flavors (eg. Early Expansion check uses the ratio of Expansion Flavor to Growth Flavor, so there can be quite a difference between 5/5 and 5/4, especially compared to 5/5 and 6/5). I haven't done a lot of messing about to see what flavor values give "reasonable" personalities, but you should probably never set Expansion or Growth flavor to 2 or below.
 
Ho boy, flavors... basically, anything above 10 will be "crazy", it's just that the game lets you go up to 20. The default value is 5, but even the smallest change from 4 to 5 or 5 to 6 can have huge effects on the DLL side of things, especially for code that relies on the ratio of two flavors (eg. Early Expansion check uses the ratio of Expansion Flavor to Growth Flavor, so there can be quite a difference between 5/5 and 5/4, especially compared to 5/5 and 6/5). I haven't done a lot of messing about to see what flavor values give "reasonable" personalities, but you should probably never set Expansion or Growth flavor to 2 or below.

So in other words, Gandhi needs his nuke flavor updated from 12 to 20 :lol:.

Also, with regards to AI expansion strategy, I find that the AI on Archipelago at times will be somewhat "blind" in terms of expanding - say they spawn on an island with enough room for ~2 to 3ish cities squeezed on the corners along the coast - often times instead the AI will either go OCC or try (sometimes they are blocked however) to settle on another island/landmass.
 
This is sorely needed work. Some thoughts about tweaks in AI strategy to reflect the current game balance:

- Science should be a higher priority as it is important for all victories. If we can get them to plant scientists before the renaissance and bulb them afterwards it would make a difference.

- Prioritize growth (see above).

- The AI should probably avoid piety, and more so the more civs that choose piety. If you alone have the dominant religion then it might be a decent choice but when 5 civs take piety they themselves immensely.

- Get the early warriors to slavishly follow early workers/settlers to avoid them being snatched as this can completely destroy an AI.

- Prioritize building ranged units.

- Prioritize eliminating units, especially ranged units.

- Increase cost of bribing them into war.

- Make them charge significantly more or less likely to trade lump sums of gold than gold per turn

- Stop them from purchasing unnecessary luxuries/strategics.

Some of this has been done in the Buffed AI mod: http://forums.civfanatics.com/showthread.php?t=504220
 
Setting Piety to unlock in the Classical era may solve some of the "ERMYGOD RELIGION GOGOGO" craze some AIs (lookin' at you, Isabella :rolleyes:) tend to pursue, although that would be more of a gameplay change/forced workaround than an actual re-work of the AI's valuation of policies.

Increasing the price to bribe for war is not all that feasible/sensible in terms of gameplay/balance: unlike say, Civ4, where you could trade away techs (which are frankly a lot more valuable than resources/gold), the system has fewer (or, in the case of lump-sum gold, restricted) leverages and checks to provide the trading parties with things to trade with.

Additional reluctance to trade lump sums of gold may not be needed - you need DoF as a pre-requisite, and the AI values it slightly less as it is.

Trading for additional luxuries doesn't seem that bad though in gameplay terms (assuming the AI is not broke), considering you want as much happiness as you can feasibly produce with your economy for more GAs.

(Just my $0.02 :p)
 
But having things to trade with is a secondary concern to creating an AI that is actually a threat.

The system as it is now is easily exploitable. As soon as you see someone plotting against you or just generally growing strong you can pay either them or their neighbors to go to war. It works most of the time and then it is such a strong tactic that you can ignore army entirely.

For instance, you can pay an AI a small bit of gold to attack a city state, occupy all the tiles from which it may be captured, and then it is distracted forever. Or pay it to attack city states and watch as it becomes hated by everyone. Look at it from the AI:s point of view: in almost all cases this is a bad deal for the AI making it and therefore they should not accept.

The exception is two cases: 1 - the AI already planned to attack that other AI ( why not get free stuff). 2 - The player and the AI both attack the third party. Then it is likely that both the player and the AIs has a similar interest in thwarting or conquering the third party.

Regrading lump-sum gold and gold per turn: It is actually inconsistent in this regard. Furthermore, friendships end.

Surplus happiness and strategics is useful, but the gold traded away is probably more useful, especially on the higher levels when the AI has ridiculous amounts of happiness.
 
Oh, I didn't know you could pay the AI to attack a CS, thought it was only with other major players..........do you get a influence drop with the targeted CS if you do so?

A function could be implemented for the AI to call off war-plans if target is unreachable/blocked by units (if there is not one already.... the DLL code is so frickin huge -.-, only reading through a couple hundred lines per day) for a certain amount of time (but the counter would have to be kept and not reset to prevent toggle abuse).

If the "distraction" factor is too big, could always remove the "1 operation at a time" limitation for the AI (may fuzz up some of the AI assignments on the per-unit basis, since it's simply coded as "if there is no operation already; proceed", may cause units to be re-assigned back-and-forth between 2 operations).

I do not think it may be possible for the AI to evaluate a bribe-to-DoW fairly, because often times, the human will not have the necessary resources/gold (note: ignoring cities as trade items for now) to actually make up for the trade they will lose from other players, as a consequence of the diplomatic fallout they will incur. (Again, lack of actual levers/items to trade).

An "AI-bribed-to-DoW-warmonger-penalty-reduction" might be band-aid workaround for the diplo penalty I suppose, but that would ultimately serve as just a stop-gap solution, but while preserving the classic game element of being able to bribe people to DoW.

Personally, I think it's a good mechanic (i.e. you can either scare the AI off with a superior/sufficient military garrison, or pay them to attack another juicy target); just not executed in the smoothest of fashion/with enough oversight.

(Again , just my $0.02 :p)
 
You can do it for cheap, they get hated by everyone and it does not affect your standing with the city state. =)

Paying for war has the possibility to be a good mechanic, but right now it is mainly a way for the player to throw off the AI so that it does stuff that is not in its best interest. This is a problem because the AI is very sensitive to distractions. When I see an army approaching I bribe them and watch it marching its armies to the other side of its civilisation instead of attacking me. This is a very common exploit in deity games with regard to the AI together with worker stealing. If you look at deity cahllenges in the strategy forum you will see a myriad examples of this.

Further, when the threat from the other civilisations is lessened or removed it means that you do not have to care what they do, interact with them or try to build good relations. Diplomacy regresses to optimisation of exploitation.

Combined this with trading resources for gold and the higher science rate of the AI this means that winning science on deity is faster than all other levels bar settler which is bass-ackwards.

You could try to provide a remedy but it will be more effective to provide a cure. The AI can hardly determine whether it is in their interest, but we can infer that it probably is not from the fact that the player want it and is willing to pay for it. AT the least I want to limit it by either raising the cost massively or disallowing it except in the two exceptions mentioned above. If that is hard to do, I want to remove it entirely.
 
Well, we could always have the cost scale exponentially as a function of [Attitude towards asker]*[Attitude towards target] with a "No-Deal-Whatsoever" cut-off in inside both scales (i.e. they don't like you enough, or they like the other guy sufficiently) - a-la-Civ4 diplomacy.

Paying for war as a option to distract the AI I believe should ultimately be kept in to a degree (but, that's just my opinion) - it's not exactly inaccurate historically (Byzantium paid off the Arabs/Muslims while Justinian(?) went on a conquering spree in Italy), but I do agree it should be a large amount of money, scaling on your own military power as well (with a cap on the strong end, don't want everyone declaring war on each other for cheap, just because you're the strongest, but it should cost more if you are militarily weak).

With regards to whether something is in the interest of the AI, we all know the answer is "almost never", but being manipulated to some degree is still an integral part of the game (why else do we even bother with "diplomacy"?).

With regards to distractions: Civ4 had the WHEOOHRN ("We have enough on our hands right now") mechanic - where being bribed to make war on someone else was impossible if they already had war plans in motion. A re-implementation would help greatly with the distraction abuse.

(Now I'm even more nostalgic for the Civ4 style of diplomacy again -.-)
 
Also, with regards to AI expansion strategy, I find that the AI on Archipelago at times will be somewhat "blind" in terms of expanding - say they spawn on an island with enough room for ~2 to 3ish cities squeezed on the corners along the coast - often times instead the AI will either go OCC or try (sometimes they are blocked however) to settle on another island/landmass.
Hmm, I haven't looked at island map expansion functions yet, I'll see if I can get around to it sometime.

- Science should be a higher priority as it is important for all victories. If we can get them to plant scientists before the renaissance and bulb them afterwards it would make a difference.
I've already implemented this in the current version in the form of situational science flavor boosts: under certain situations, the Science Flavor value of buildings, wonders, and techs gets multiplied by up to 8. The situation and the exact multiplier depend on the AI's Grand Strategy ratio (or selected grand strategy if it's turned off): for example, if the AI has a high culture GS ratio and does not have Archaeology, or if the AI has a high diplomacy GS ratio and the UN isn't active, the multiplier gets applied in full force. Other situations will only return half of the full multiplier: high culture GS with Archaeology but without Internet, high diplomacy GS with UN but without Globalization, high conquest GS and not high enough in tech compared to other players, etc. To stop the AI from crippling itself by instantly going for libraries and science wonders early on, the boost is inactive in Ancient Era and only applies at half strength in Classical Era.
Great Scientists and Great People in general are a separate matter entirely; I've already done so preliminary tweaks, but I'll definitely go back for a more thorough run later down the line.

- The AI should probably avoid piety, and more so the more civs that choose piety. If you alone have the dominant religion then it might be a decent choice but when 5 civs take piety they themselves immensely.
Policies aren't something I've addressed a lot in the current public version, but I'm definitely working on things on my end. So far, examples include: multiplying the Spaceship flavor of policies (since only Rationalism policies have Spaceship flavor) and the Science flavor of tenets by the same amount as the building/wonder/tech science flavor boost, dividing the Offense, Defense, and Military Training flavor of policies by 2 if the civ does not have any unlocked policies (to stop Honor openers), and multiplying the Happiness flavor of policies by 2 if the civ is unhappy (4 if they're very unhappy). I've also been messing around with a function that triggers for civs with Great Person UU's and multiplies all flavors for policies associated with that GP (with a second multiplication pass for policies in a branch that unlocks faith purchasing of that GP). Inserting a Religion flavor divider that triggers if the civ does not follow a religion took maybe 3 minutes after I read your post.

- Prioritize growth (see above).
- Get the early warriors to slavishly follow early workers/settlers to avoid them being snatched as this can completely destroy an AI.
- Prioritize building ranged units.
The logic for building units is still untouched, since I haven't really gotten around to upturning the super-basic (leader's flavor)*(unit/building flavor) logic that governs all aspects of production.

- Prioritize eliminating units, especially ranged units.
I found that the problem is less to do with the AI not prioritizing ranged units highly, but rather that its logic to decide when to fortify and when to attack is extremely flawed.

-Increase cost of bribing them into war.
- Make them charge significantly more or less likely to trade lump sums of gold than gold per turn
- Stop them from purchasing unnecessary luxuries/strategics.
These are diplomacy-related functions, which I am not planning on touching until I've got everything else improved significantly enough. The reason is threefold:
1) Debugging diplomacy is a nightmare compared to debugging other game systems. I can use the in-game UI to check what policies the AI has unlocked at any time or to see how well it handles attacking a city, but diplomacy stuff related-stuff requires me to keep track of 20 or so number values for each civ via .csv logging. The .csv logging part is what annoys me, as I constantly have to re-import the log into my spreadsheet viewer on every log update if I want to view things in real-time.
2) Unlike all the other AI systems that are heavily intertwined with each other, the AI's diplomacy system is almost completely isolated. It's almost like there are actually two people controlling the AI: one handling diplomacy and deals, while the second handles everything else. As a result, improving the diplomacy system does not have as visible effects, especially in AI-only games where no player is actively abusing the stuff (see: debugging is a nightmare)
3) As a result of (2) and the fact that the diplomacy system is quite game-y in nature, a lot of past AI-improving efforts have concentrated on the diplomacy AI to varying degrees of success. There are also a metric ton of mods out there that expand the diplomacy system as well, some quite popular. It would therefore be more efficient of me to leave the diplomacy system relatively untouched, allowing people to merge my DLL with the diplomacy mod of their choosing without worrying about conflicts.

A function could be implemented for the AI to call off war-plans if target is unreachable/blocked by units (if there is not one already.... the DLL code is so frickin huge -.-, only reading through a couple hundred lines per day) for a certain amount of time (but the counter would have to be kept and not reset to prevent toggle abuse).

If the "distraction" factor is too big, could always remove the "1 operation at a time" limitation for the AI (may fuzz up some of the AI assignments on the per-unit basis, since it's simply coded as "if there is no operation already; proceed", may cause units to be re-assigned back-and-forth between 2 operations).
To my knowledge, pathfinder calls can only be called for units, so you'd essentially have to run at least one pathfinder call for every potential target. While this can be done, it would not be a good idea: since any unit, city, or improvement can be a tactical target, the AI would need to run an excessive amount of pathfinder calls each turn, even more if any possible target were inaccessible to at least one unit (since the target needs to be inaccessible for attack to all the AI's units, it would then need to run a call to the target for every one of its military units). Pathfinder calls are quite expensive computationally, so AI turns would take forever if you implemented anything like this.
You don't need to "remove" the "1 operation at a time" thing: all you'd need to do is lower the "distracted" operation's recruit priority and let other operations recruit from "distracted" operations. However, the recruitment logic of operations needs to be improved anyway, so if you're already working on something like this, might as well go all the way and revamp the entire operation recruitment logic.
 
Back
Top Bottom