1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Artificial Unintelligence

Discussion in 'Civ5 - Mod Components' started by Delnar_Ersike, Oct 23, 2014.

  1. chumchu

    chumchu Warlord

    Joined:
    Nov 21, 2012
    Messages:
    191
    CiV is not a history simulator as much as it is a game with a historical theme. Balance comes before adding a bit of flavor.

    Implementing something similar to WHEOOHRN (onomatopetic, is it not) would help with a part of the cases, increasing the cost would help to the degree of the increase in all cases. Both of these are a major improvement on the current state of the game.

    I see it as a balance between exploitation where the AI do what you want or pose no threat on the one hand and total enmity where the AI ignores you and try to destroy you on the other. In the middle between these poles there is room for meaningful diplomacy

    What made the diplomacy more interesting for me in Civ IV was that friendships was more lasting and important and that war was riskier and more profitable. Sometimes you got a surprise DoW and a doomstack walks all over your cities if you have not prepared (except when they just stand around and wait for their 1 catapult to lower the defenses lol). If you could grab some good land, war was an excellent idea and almost necessary to win at the highest levels. In Civ V war is easier but the gain is more ambiguous. Diplomacy by other means is my favourite type of diplomacy =)
     
  2. chumchu

    chumchu Warlord

    Joined:
    Nov 21, 2012
    Messages:
    191
    Science and policies:
    Nice

    Fortifying:
    I've noticed that as well. It is rarely good to fortify when close to the enemy, often better to attack or retreat to safety. An AI player should probably attack more as it wins by overwhelming the player with units rather than tactical finesse. A good example of this is Japans AI which can actually be a threat. In short, more attacking, less fortifying.

    Diplomacy: I respect that. However, it is a place where a small change would do a lot of good. I'll just have to wait for others to merge your efforts with those focusing on diplomacy.

    The code is lazy, messy and buggy: I have come to expect that =(

    Once again, thanks for your work! I have attached a cat gif as a token of my appreciation.
     

    Attached Files:

  3. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    @Delnar:

    Regarding the tendency for the AI to go OCC, perhaps the

    Spoiler :

    Code:
    <Update>
    			<!-- Lowered from 8, since tall > wide in Civ5 early on; however, this number gets reduced on the DLL side -->
    			<Set Value="6" />
    			<Where Name="AI_STRATEGY_EARLY_EXPANSION_NUM_CITIES_LIMIT" />
    		</Update>
    


    change is the culprit? Never really had the AI try to go OCC so much (so far, I have only seen Napoleon actually make settlers/send them out somewhere, although I did block him since he was on my continent. This was by turn 80-100 as well; Prince Difficulty).

    You mentioned previously that the leader flavors were capped at 20? Does this also apply to unit/building flavors as well? I might just spam-append every single flavor onto the settler just to make the AI actually build one :lol:
     
  4. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Yeah, I've bumped that value back up to 8 internally and the AI's been settling cities properly. Problem is that I don't want to rely on it too much, as the AI will pretty much be pumping out settlers left and right until it hits its city target, which means it prolongs building military units and proper buildings until after it has hit its target.
    Also, it's definitely NOT responsible for OCC behavior. The AI was simply being OK with having 3 cities instead of pumping out settlers until it hit 5.

    Leader flavors are capped at 20 by default, while all other flavors are capped at 1000.
     
  5. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    Mmm, I see. I don't suppose the AI REX-spree could be scaled based on the situation (so long as it remains within the confines of the strategy/doesn't trigger a new one), in that it would tone down the amount of settlers it spams as it approaches its target? (i.e. 50% reduced priority for founding new cities when it's at 6/8 or something).

    Also, for the "general standing/patrolling army" (at least, that's what I interpret them to be, and that's approximately what I observe) values for land and sea:

    Spoiler :

    Code:
     <Update>
          <Where Name="AI_STRATEGY_DEFEND_MY_LANDS_UNITS_PER_CITY"/>
          <Set Value ="1.5"/>
        </Update>
        <Update>
          <Where Name="AI_STRATEGY_NAVAL_UNITS_PER_CITY"/>
          <Set Value ="2.0"/>
        </Update>
    


    Perhaps in the .DLL, perhaps they should be scaled more to be by their era, as well as the 'latest era' as well? (Especially for the Naval units per city). Early game they will sometimes forsake all other production just to build a certain amount (i.e. 3-4 triremes to defend their waters), which by the renaissance, 3-4 ships are simply not enough to deter war against a human. May need to update attack task forces compositions to reflect the greater number of floating/reserve units hanging about however (i.e. larger attack forces, or a secondary reserve/escort that follows in tow).

    Especially so if they have not yet been properly upgraded, or if they are behind in tech (i.e. triremes vs. caravels/frigates). Kind of like "we want the AI to build a sufficient number of units, enough to prevent insta-losing a war, but built gradually over time and not rushed for no reason"; not too worried about maintenance costs, unless at lowest levels, but then taking out the maintenance factor by setting everything to 10-35% across the board, of what a human pays for unit maintenance would solve the problem, as they are gimped enough in their current state as it is (essentially giving them some free gold/removing a not-necessarily-necessary lever/check on their overall growth/strategy).

    I imagine space would run out for land units, unless the max-units-per-tile parameter is raised above 1 (but that potentially creates problems for the tactical AI, in that it doesn't know how to assess situations anymore(?)).
     
  6. chumchu

    chumchu Warlord

    Joined:
    Nov 21, 2012
    Messages:
    191
    TH: If you are want it to be stronger militarily without filling up the map with units why not make the units stronger? See the buffed AI mod for a good example on how to do it.

    I played a test game with random civ, fractal, deity. I also noticed the lack of settling. I did not notice any substantial positive differences except for the walk and shoot-thing from smart AI which makes hand-axes much more deadly.

    I got the Huns and decent capital. Found my first neighbor, byzantium, on turn 5 and took their capital turn 13 with a scout (to distract them) and a battering ram from a hut. Also took 2 workers. I left their second city to farm some more workers and get trade routes. I got 3 more workers in one additional war and when the farms captured their settler. They also sent me trade routes so it was all good. By turn 90 they had managed to found a second city to replace their capital. They took piety and goddess of protection and did not get a religion lol.

    My more distant neighbors were ethiopia who went for piety aesthetics and founded a religion super early with religous idols but did not get any additional cities. I wiped them off them map turn 90-100 with no losses. My army consisted of 5 horse archers and 2 battering rams.

    My third neighbors was the Danes who went for liberty and settled an additional city with the free settler. It was in a really bad spot with almost all tiles being jungle or water without resources. They marched a large army of berzerkers, pikes and trebutchets at me around turn 85 so I bribed them to war with Ethiopia which was on the other side of my kingdom. The army went home again. After I had finished with Ethiopia and moved my units back to the front with the Danes they declared war and I slaughtered their army with horse archers and landsknechts. By this time I had control over my continent; neither the Danes nor the Byzantines could threaten me and it seemed a good time to stop.

    To sum it up, it is quite easy to break the AI. The main ways are worker/settler stealing, bribing for war, them choosing piety and killing their units with ranged units as they are bad at retreating as well as eliminating your units.

    Savefile: https://www.dropbox.com/s/wzb0cr1soksucy0/Attila_0110 BC-0125.Civ5Save?dl=0
     
  7. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    @ ChumChu: I thought the point of a ''Better Artificial Intelligence'' mod to make the AI smarter without having to give it excessive buffs? :p

    The buffed AI mod, on the whole, focuses more on (as it name implies) directly buffing the AI unit stats (or nerfing the human units, depending on how you want to look at it). While it certainly accomplishes a goal of making it harder for the human to annihilate the AI (comparative to the base game), it does very little to address any actual AI behaviour in terms of strategy and just ''playing according to the situation'' (not sure if that's the best phrase to represent/express what I mean... o well).
     
  8. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Heh, turns out the OCS behavior might actually be caused by one of my "dirty" edits that I didn't think of before: the edit in question forced the AI to run TacticalAI stuff twice every turn as a "dirty" fix for units that could move after attacking or attack twice per turn ("dirty" because it's very computationally expensive and inefficient compared to modifying all the actual tactical moves to work with units that can move after attacking). Problem is that this forces certain military units to jump on-and-off of military operations that had civilian units, since civilians are controlled by HomelandAI instead of TacticalAI.
    I'm currently testing to see what difference that "dirty" edit actually makes and am willing to disable it if it causes more problems than it solves. Plus I've already implemented blitz-compatibility code for the ExecuteAttack() function, and I've got an idea how I can implement a fix for almost all the other AI functions (the trick is to modify UnitProcessed(), since that's what actually causes a moved unit to no longer be considered for future tactical moves in that turn).

    Scaling standing army to be per era is not an elegant way of dealing with the AI fielding outdated units. The more elegant way would be to use actual unit strengths instead, but that requires a lot more time to program (since you're not throwing a simple era-factor onto the end of the function, you actually have to consider how unit strength grows over time).

    And yes, I agree with ThorHammerz on the "buffed AI" thing: modifying the game to suit the AI is much easier but also lazier and less flexible (those two combined = less elegant) than modifying the AI to suit the game. The only buffs the AI should ever receive from a mod are knowledge buffs, and only when it massively saves on computational cycles (eg. having the AI remember past turns and perform Bayesian prediction functions to imitate human "intuition" just for figuring out whether an enemy city might have certain air units is a lot more taxing than just allowing them to see said air units).
     
  9. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    Not in terms of "fielding outdated units" persay (although that is what happens a lot of the time), but more of "fielding enough units", especially on the naval end (i.e. 1-2 scouting triremes will be enough in the early classical after u research optics, but a couple triremes/galleass per city is not going to be enough once the AI is going through the early medieval period when the human is likely at, or technologically close to arriving at caravels: the AI is going to need sufficient units to patrol its waters + and as a general deterrent against easy naval invasions (plsu to have enough units to upgrade to caravels and frigates when they come along).
     
  10. chumchu

    chumchu Warlord

    Joined:
    Nov 21, 2012
    Messages:
    191
    I was referring to your earlier suggestion of decreasing maintenance costs which is more indirect way to buff the AI:s performance in combat than just buffing its strength. I did not say that I want this mod to buff the AI, I did say that this would be an inefficient way to do that.

    I am trying to provide suggestion for strategies and tactics that would make the AI more challenging without buffing it from the perspective of players that are good at exploiting its weaknesses and breaking the game as requested by your original post.
     
  11. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    Well, decreasing maintenance cost not only buffs the AI in combat, but their economy in general (since certain civs will go seemingly be perpetually broke). My main consideration at the time was however more so to remove a (debatable/questionable) possibly unnecessary lever on balancing the AI, as opposed to just buffing them (even if that would be ultimate outcome).

    The comment to you was made in jest, apologies for any.... misrepresentation/misinterpretation for your previous comments.

    On another note, it seems that city states seem to only have their expansion flavors set to 0, as opposed to a hard rule restriction on not being able to construct settlers it seems.... saw Zurich build 2 settlers before I remembered I set gold/science/production flavors for the settler as well :lol:.
     

    Attached Files:

  12. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    I would rather take the time and effort to restructure the way the AI handles gold than make up for its existing faults with the help of AI-only buffs. Currently, the AI's implementation of gold spending is extremely flawed, primarily because the five parts it's split into don't talk to each other properly (tile purchases, diplomacy spending, city-state spending, unit upgrades, and unit/building purchases). Factor in the sixth part of unit/building production for maintenance (and a seventh part of tile improvement maintenance that's limited in Civ5 but quite substantial in BE), and you've got yourself the mess you're seeing.
     
  13. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    From what I understand Delnar, the upper-level AI just loops through each of those parts sequentially, so the functions checked last will typically see the least use (due to the available gold being probably spent on the previous items)?
     
  14. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    v8 of the mod is now uploaded and it features a month's worth of bugfixes, extra tweaks, and under-the-hood changes, primarily to choosing logic (eg. policy choosing logic, great person choosing logic, belief choosing logic, improvement choosing logic, annex-puppet-raze choosing logic, etc.) and formation handling.
    Unless something vital ends up needing patching, I'll resume my GitHub commits. Feature creep may delay me though, as there are some things I left out of v8 that I'm really, really curious to see the effects of (eg. having the AI value specialists' great person generation in a dynamic fashion, or allowing Shoshone AI's to properly choose their goody hut bonuses instead of just getting a random one).

    I haven't really delved into the AI's gold purchasing logic and barely touched on its faith purchasing stuff, so I can't really say anything for certain other than the fact that the system is quite disjointed.
     
  15. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    Is the OCC bug fixed with this release? :D
     
  16. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    It should be, 'twas one of the first things I looked into after v7 came out.
     
  17. chumchu

    chumchu Warlord

    Joined:
    Nov 21, 2012
    Messages:
    191
    I played a full game on deity with your mod and noticed the following:

    - The barbs seem more aggressive and more likely to leave their encampments empty. I wandered into 4 empty camps in the early turns.
    - Venice planted its first merchant and built very little troops. I could conquer them turn 80ish with 3 archers and 3 immortals. It feels as if there less AI units over all which makes it easier to war with them.
    - The AI has groups of workers idling in neutral territory:
    https://www.dropbox.com/s/a0ckpo23k9pyr8e/2014-12-03_00004.jpg?dl=0
    - The AI are teching faster than usual. Most people were in modern era, with one in atomic era when I finished.

    Turn 221 (I win next turn): https://www.dropbox.com/s/x76h4gjutkn1nkl/Vägval 2.Civ5Save?dl=0
    Turn 150: https://www.dropbox.com/s/rybf2tt56q7s3hz/QuickSave.Civ5Save?dl=0
    Turn 90: https://www.dropbox.com/s/w6tspf0hesjwz0f/AutoSave_0220 AD-1550.Civ5Save?dl=0
     
  18. ThorHammerz

    ThorHammerz zzz

    Joined:
    Jul 31, 2014
    Messages:
    836
    Not sure if I'm interpreting this accurately, but in CvEconomicAI.cpp of the original source code, line ~1747, is the logic for the AI to rush-buy anything with gold disabled(?).

    Spoiler :
    Code:
    if(GC.getHurryInfo((HurryTypes)iI)->getGoldPerProduction() > 0)
    						{
    							// Don't gold rush at all anymore (save gold to buy tiles)
    
    							// iHurryAmount = pLoopCity->hurryGold((HurryTypes)iI);
    							// iHurryAmountAvailable = m_pPlayer->getGold();
    						}
    
    


    (Is the functionality implemented somewhere else? Not sure if the text-finder is being buggy again, but I can't find any other code calling the HurryGold method in CvCity.cpp, as the canHurryBuilding and canHurryUnit booleans seem only to be defined, but not called/used...)

    Also noticing a lot of "hurryPopulation" functions.... is it code left over from civ4's slavery mechanic?
     
  19. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    That's actually a bug from the original game that doesn't appear in-game because other unit management code bugs cover it up. I've fixed this for v9.
    Venice should only ever plant its first merchant if it's playing on a small map with lots of players, rolls -2 for expansion flavor and +2 for growth flavor (1/81 chance), and/or there are no city states left on the map. I've set a hardcode for v9 that eliminates the first two cases, so it will always desire at least two cities.
    As for the AI having less units than usual, I've noticed that this really depends on the AI and the game in question. For every test game I've seen where no cities traded owners, I've seen at least two games where two superpowers proceeded to steamroll their way across the entire continent. For example, I've never seen a single test game with Poland where the AI did not wreck shop with them.

    Also note that the AI is a lot better at longer game speeds because of a lot of hardcoding that I've yet to remove, so there's that: normal only works well for Small map size or smaller.

    Hmm, haven't really seen that before, I'll check it out, it's probably due to plot danger values. But yeah, the worker AI has some problems when they're not following automation orders.
    After all the modifications I gave them to favor tech buildings and rationalism and to sort out large money issues, I'd be surprised if they weren't.

    Yes, the code to purchase buildings with gold is disabled in the main game. Faith purchases are handled in CvReligionClasses, while purchasing units with gold is handled by MakeEmergencyPurchases() in CvMilitaryAI.
    Smart AI implemented its own version of the building purchasing code (which I copied over into Artificial Unintelligence), and although it works, it's far from optimal, so I'll have a closer look at it later.

    I wouldn't be surprised if the hurryPopulation stuff was leftover code from the Civ4 DLL, there tends to be a lot of leftover Civ4 code in the AI routines.
     
  20. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,073
    Location:
    America
    I just want to say that I'm really impressed with the work you are doing, both from a gameplay and technical standpoint. The AI in my current game with this mod has been giving me a good challenge in wars and your understanding of how the AI works and how to improve its code seems very valuable and detailed.
     

Share This Page