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

Delnar's AI Cleanup 2016-11-06

Delnar's AI Cleanup

Tags:
  1. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    We're talking about two different -7's here. I'm talking specifically about the ones you made to two nodes in TreeData, the "Failure Amount" argument of the Operation Change Target leaves, and that that's kind of overkill compared to the default -2 or -3.

    Pseudoyields still rule at the end of the day, I'm guessing that favored items simply place stuff into three tiers (favored, neutral, unfavored) and pseudoyields are resolved within each tier separately; unit requests for pending operations are placed in favored probably. If you make districts favored, it'd put them into the top tier for choosing what to produce, but they might still get overshadowed due to low pseudoyield.

    The reordering definitely affects units that aren't in operations and units controlled by CvHomelandAI. Units in operations are controlled by the moves in their behavior tree, which have their own functions within CvTacticalAI, but everything else is controlled by the moves I mentioned, and reordering those moves definitely changes the order in which the AI runs them.

    It may be possible, but it would also probably be quite tedious. For example, a "ghost" resource could be spawned near settle plot operation targets that would ruin settle plot values for everything in close proximity, but this "ghost" resource would have to despawned when the operation that spawned it in the first place might reconsider its target. It'd be extremely hacky, would have to be run through lua, may be problematic on resource-rich maps (because there won't be an eligible tile for the "ghost resource"), and will slow the game down quite a bit (because resources would be spawned and despawned all over the place), but something like it is the only way I can see you solving this AI problem without access to CvGameCoreDLL's source code.
     
  2. Horem

    Horem Emperor

    Joined:
    Apr 1, 2010
    Messages:
    1,720
    Location:
    Wales, UK
    I could not decide which of these 2 good sounding AI mods to use, so I combined them :) . Omiting the cross over with Default Tactical and Default Homeland, seems to play great, hats off to you both!
     
  3. Littlebob86

    Littlebob86 Prince

    Joined:
    Oct 24, 2016
    Messages:
    329
    So Delnar I've been using your mod since day one, but I don't know if it's just me or the one game I played, but the Ai in Siesta's mod during battles was actually spot on.. Perfect moving with ranged and melee.. Just thought it might be worth seeing if he's changed combat from yours!
     
  4. civbaloo

    civbaloo Chieftain

    Joined:
    Oct 25, 2016
    Messages:
    6
    Gender:
    Male
    Any chance you could share the combined version here possibly? At this early stage, the two Mods will likely continue to develop further until they might (or might not) merge, yet as interim solution I would be highly interested in playing for awhile with a combined version.

    Would be great, and thanks to ALL of you doing this modding work. For people like me (Civ player since Civ1 but with a lack of technical skills to participate in modding), people like you all are making our game lives so much better!
     
    Mglo likes this.
  5. S4CH4

    S4CH4 Chieftain

    Joined:
    Feb 23, 2015
    Messages:
    24
    Location:
    France
    Yep, i agree with civbaloo! If you could upload the mixed mod it would be nice :D
     
  6. Siesta Guru

    Siesta Guru Prince

    Joined:
    Dec 2, 2007
    Messages:
    498
    Location:
    The Netherlands
    Ah those. Well, I've seen a -50 in some vanilla stuff before, which suggests it at least does something more for higher numbers, but how exactly the two variables work is indeed beyond me. It's possible that they don't do anything different and that some slightly different behavior I appeared to see in testing may just be placebo.

    The citybuilds log suggests that the final step done to choose between options is a choice between the various build contracts that are made through operations, each with its own value assigned. My guess is that an operation is necessary for an option to be available, and that all the systems we can see (pseudoyields, favored, flavors) only affect the internal decision making that ends up supplying that number.

    It's certainly rather confusing what the exact method is. In the case of settler production, we have pseudoyields, the expansion flavor, the behaviortree for the settle operation, some sort of decaying thing that requires a minimum number (which relates to plotevaluations and some kind of distance based algorithm we cant see), some function in the rapid expansion strat that checks whether there's a settle spot, a limit on settle operations that can be running, other operation settings like its team, and possibly the 'favored' mechanic and probably some stuff we can't see in the dll.
    It's honestly bizarre that they introduced so many systems here, yet failed to make the standard settling behavior anywhere near competent and do stuff like completely ignore all the yields beyond the first ring...



    Alright, that does sound promising, I'll try experimenting with it a little too.

    Any idea how you would figure out in the lua that a settler targets a certain spot?
     
  7. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    I have looked at those myself: the only difference between our mods regarding tactical unit control is that Siesta's tries to reorder tactical moves by assigning them values, while I try to reorder tactical moves by physically reordering them within the database. Since vanilla Civ6 orders moves by the order in which they appear in the database and doesn't assign them any values, my method will work for that, and I don't know if Siesta's will (if the DLL is OK with using values instead of primary key order to determine move order, then both should work).

    In any case, neither of our mods actually changes tactical unit control. If you are indeed saying that the AI was using perfect unit control (rather improbable unless you've got low standards, since there are some unit control options that the AI flatout has no access to, e.g. moving and shooting with a ranged unit not adjacent to the target or swapping two units), then it's a result of the core game itself and has nothing to do with any mods. Indeed, unless we're talking about a Lua mod that recreates CvTacticalAI and overwrites it (i.e. an event forces units to move around and run commands, and this event is placed into a listener that is called once per player turn before CvTacticalAI but after core player turn processing), unit control cannot be modded for now.

    Check the reference in my signature. The Operation Change Target node type's second argument (which is the thing you're altering, since the node you're changing is an Operation Change Target node and the DefnID is 1, indicating second argument) is called "Failure Amount". IIRC, in Civ5, the retargetting function for operations contains a large loop that attempts to retarget the operation based on a virtual function, with the loop terminating if a new target is found or if a new target is failed to be found after N attempts. I'm fairly confident that the argument we're talking about control such a loop, and if the internal, retargetting virtual function returned no new target after being run from beginning to end twice, I don't think you'll gain anything by having it run five or 48 more times.

    No, that sounds about right. Civ5's flavor system basically just involved looping through all flavor types, generating the products (leader flavor + player strategy flavor + city strategy flavor)*(entry flavor), summing those products, applying a few conditional modifiers to the sum (e.g. doubling the sum if the entry is a building with no maintenance cost and the current city is a puppet), and multiplying the sum by the output of a power function of production time to determine the entry's total flavor, then building the entry with the highest total flavor. Units requested for operations (remember, Civ5 had operations, too) had modifiers applied through the conditional modifiers section, with a fairly large boost to flavor for sneak attack operation requests at high AI difficulty IIRC.

    What I'm guessing is that this overall structure is still in place, albeit with the flavor summing and product system replaced with an internal scoring system that determines baseline favor from the entry information itself, rather than use pre-defined flavors, and the values you're reading in the log files are the total flavor values I mentioned (they're renamed "pseudoyields", but otherwise they're the same). The favored/disfavored system, as well as all the other values you can use as a part of AIFavoredList, simply feed in as either conditional modifiers in addition to the conditional modifiers we don't have access to, or as a stratification system where the entries are sorted into 3 lists (favored, neutral, unfavored), each of which get their highest value entry determined, and an extra scoring step at the end determines which of the items will be chosen (the favored one, the neutral one, or the unfavored one).

    Create an event in a listener that triggers once per player turn, have that event run through all active operations and filter out any non-settle ones, pass the target of each operation to whatever zone-generation function you plan on implementing.
     
  8. Horem

    Horem Emperor

    Joined:
    Apr 1, 2010
    Messages:
    1,720
    Location:
    Wales, UK
    Um not my place to post modified files in an authors forum without authorization from both authors involved. Bad equitete, sorry.

    EDIT:

    If they both give consent then I would be happy too.
     
    Last edited: Nov 2, 2016
  9. Siesta Guru

    Siesta Guru Prince

    Joined:
    Dec 2, 2007
    Messages:
    498
    Location:
    The Netherlands
    I kind of expected my changes here to do nothing, but it did appear (may be a placebo), that the AI with these on does select between the options decently well. Nothing amazing or close to a human level, but perhaps kind of what you expect from an AI that doesn't seem to consider half the relevant factors. It'll definitely take more experimenting for me to be sure, because it's rather difficult to know, even with extreme values. But I think there's a small chance it's actually working.


    That does make sense. The only strange parts to me are that they use these high values in the vanilla code, and that its actually denoted as a float variable, rather than an int. And floats are rather rare in that file, which makes me think it's intentional. Couldn't find any non-integer values in there, but it's notable at least. It's also a negative value, which makes little sense if it's about some iteration that hits that limit.
    The backup variable is also a float, and some non-integer values have been used for that. And it'd make sense to me that the two values here are rather similar in meaning.
    My first instinct upon seeing the variables was that they are additional weights applied to the scoring system, with 'backup' noting the weight change of any options that are not the current one, and 'failure' being a weight thats applied if the AI thinks it is going to fail, with failure depending on the type of operation. For settlers it may be that the spot is taken, for armies: we think were losing.


    If we can access those variables that sounds like a plan.
    Based on your earlier comment about fake resources, I got an idea we may try. How about we add an invisible yield, have every civ gain a trait that increases that yield by +1 on every tile, then give that yield a negative weight in the plotevaluation thing. That should theoretically make them less likely to put their cities right next to each other. Not sure if we can create invisible yields though.





    I don't mind. Note though that both Delnar and I will probably continue developing our mods and will probably take over the good stuff from the other, meaning there'll be little need for these types of merges. It's likely that the merges will end up worse than both individual mods if we expect certain parts to interact subtly and test based on that.
     
  10. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Do whatever you please. Keep in mind that if you post your files here, they'll probably get buried after a week or so at most. You could also post a separate thread for them and/or give copies out in PMs requesting it. Your call.

    "Selection" isn't how the tactical/homeland move system works, at least not in Civ5 anyway. The way CvTacticalAI works in Civ5 is that it first recruits all units who are eligible: this means all units with combat strength who are in danger (i.e. occupy a tile with a non-zero danger value) and who are not assigned the AI unit role of explore (since those get handled by the exploration moves in CvHomelandAI). Once it has its list of eligible units, it moves through a list of possible moves to run for any and all units. At each move, it will end up running through all the units available to it and check if the specific move can be run for them and should be run for them (for TacticalMoves with targets, the first loop as actually looping through eligible targets for the move, and the second loop is then to run through all available units to see if they can and should run that TacticalMove against the given target). Once all TacticalMoves have been accounted for (with Wander being the last one because all remaining units are eligible for that), CvTacticalAI passes the torch to CvHomelandAI, which runs through a similar process (selecting units, then iterating through HomelandMoves until it runs out) but aimed at non-combat units, scouts, and combat units who aren't in danger and aren't in an operation.

    Assuming Civ6's system works in a similar way, the AI never gets a chance to select the order that the moves are in, only what units to activate for each move (and the remaining units end up with the default Wander move). This is why my reordering is a reordering, not any sort of value assignment: it is meant to get the AI to use a given available unit for one TacticalMove more often than others (e.g. Pillage District), as well as to make sure that TacticalMoves whose outcomes can affect how the AI wants to proceed with remaining TacticalMoves happen before those remaining TacticalMoves are processed (e.g. air unit moves).

    Eh, some arguments have properties that don't make sense. For example, the Allow Disband argument for Upgrade Units is set to accept booleans, but not accept UserData, i.e. it needs to be fed a value through a contract... but contracts return lists or ints, not booleans. Some leaves have only one argument that is labelled as "unused" while others don't have arguments at all, with no real indication as to why a given leaf has an "unused" argument vs. no argument or vice versa. Find Unit Targets' arguments don't make any sense in the context of what the leaf's description says the leaf is supposed to do, especially the first argument (a boolean for "Nearest Owned City" instead of an int for city ID, a CityList, or even a Map Plot?!). For the most part, it seems like argument properties were made in a way that works, not necessarily in a way that makes sense. The Allow Disband funkiness works because the only Behavior Tree that uses the Upgrade Units leaf would have it set to false anyway.

    Still, I see where you're getting. It's indeed possible that Operation Change Target's first few arguments are used as thresholds for the initial check of "is my current target still good enough", instead of as values for how many loops the function should run and how many alternate targets should the function consider. If it is the former though, I don't really know what baselines would be: for example, is the difference between a -3.0f and -2.0f something like a settle plot with 10 more fertility (remember that targeting for settle operations multiplies raw settle plot evaluation values by a constant depending on how faraway the give plot is from the operation's center), or more like one with 200 more fertility?

    Notque and I tried adding new enum types in the past, and it caused the game to crash (we played around with adding a "priority unit" unitaitype enum and assigning it to all UUs, then adding a slot for them in attack operations so that the AI would be more inclined to include UUs in their operations). Since yields are enums, I don't think you can add new ones in XML/SQL without also changing the corresponding enum list on the DLL side... and if we have access to the DLL, might as well just solve the bug the proper way and add in a check for existing settle targets near the loop plot when searching for a target for a settle operation.
     
  11. Siesta Guru

    Siesta Guru Prince

    Joined:
    Dec 2, 2007
    Messages:
    498
    Location:
    The Netherlands
    Interesting! Thanks for the explanation. I'll do some testing tomorrow and see if I can find anything. If I can't, it's probably wise to go with your description since it seems so similar to civ 5.


    I hope the allow disband can be made to work and does something interesting. They may have just forgotten to add the UserData thing, with actual code ready in the dll. A simple update of the definitions could do enough.

    Yeah I'm not entirely sure what it'd do exactly and how strong the effect would be. The most logical would be to assume the vanilla values are at least somewhat in the right direction. In the settler case, it may mean it's just a flat thing added to the total plot evaluation ,since the values are in the same order of magnitude.

    So some good news here, you can at least add items to the operationtypes enum, and I've been able to succesfully use that to create different types of attacks and behaviors. I'm experimenting with a small 'firestarter' operation that basically just declares war with a neighbour if a strategy sets the limit for that operation to 1. Other enums that have no clear meaning may also work.
    It would be awesome if we could create pseudoyields, and just slap unique pseudoyields on all combat units.
     
  12. Siesta Guru

    Siesta Guru Prince

    Joined:
    Dec 2, 2007
    Messages:
    498
    Location:
    The Netherlands
    Followup: you can create yields and apply them! I've managed to create a new empty yield, and applied it to all plots within cities using traits.
    Unfortunately, the trick I imagined doesn't seem to work, probably because it's automatically considering this addition in its settle logic too (settling will give me this yield on these tiles, so i like the spot less). If that's why it doesn't work, some other method of applying the yields may still do though, maybe something with invisible buildings?

    It's also a little unfortunate that the new yield, even with an empty name does show up on the tooltips.. It tells you there's "1 " on the tiles.

    It's at least very promising in the sense that this means we can probably add unique empty pseudoyields to whatever we want, giving us much greater control over what the AI will build.

    Code:

    Spoiler :

    <Types>
    <Row Type="YIELD_EMPTY" Kind="KIND_YIELD"/>
    </Types>
    <Yields>
    <Row YieldType="YIELD_EMPTY" Name=" " IconString=" " OccupiedCityChange="0"/>
    </Yields>

    <TraitModifiers>
    <Row TraitType="TRAIT_LEADER_MAJOR_CIV" ModifierId="SETTLE_BLOCKER_TEST"/>
    </TraitModifiers>
    <Modifiers>
    <Row>
    <ModifierId>SETTLE_BLOCKER_TEST</ModifierId>
    <ModifierType>MODIFIER_PLAYER_ADJUST_PLOT_YIELD</ModifierType>
    </Row>
    </Modifiers>
    <ModifierArguments>
    <Row>
    <ModifierId>SETTLE_BLOCKER_TEST</ModifierId>
    <Name>YieldType</Name>
    <Value>YIELD_EMPTY</Value>
    </Row>
    <Row>
    <ModifierId>SETTLE_BLOCKER_TEST</ModifierId>
    <Name>Amount</Name>
    <Value>1</Value>
    </Row>
    </ModifierArguments>

     
  13. lordhaw

    lordhaw Chieftain

    Joined:
    Nov 24, 2014
    Messages:
    78
    Gender:
    Male
    Location:
    Canada
    Is part of what you guys doing helping to prevent the AI from settling cities right on the borders of your cities? I mean the AI does that in vanilla too and it's annoying and of little benefit to the AI except that it stops your city expansion in that direction. I've had to go to war and raze these cities, thereby incurring the warmongering penalties that go with it. I know you were looking at ways of dealing with this in creating some sort of invisible border zone around each city but wasn't sure if you were able to do anything about this or not.

    I'm liking v7 of this mod so far though, it's working pretty well from what I can see. The settler spam is definitely gone.
     
    plus likes this.
  14. Animist7

    Animist7 Chieftain

    Joined:
    Nov 2, 2016
    Messages:
    48
    Loving this mod so far! I'm using it in combo with Siesta's mod as kindly posted by Horem, so I can't really say which of the following observations are down to which mod but anyway:

    Playing as Gilgamesh on Emperor. Currently at war with Catherine in the late renaissance / early industrial - actually the first civ to DoW me this entire game. Much more potent attack force than the unmodded version with a good number of ranged and melee units appropriate for the era, i.e. crossbows and knights as well as a handful of catapults and battering rams. Luckily I finished researching field cannons the turn after she DoW'd and had enough cash to upgrade my crossbowmen, plus she had to contend with three city state ally neighbours so she didn't really stand much chance. But it was still a pretty fun fight. AI seems better at focus firing and sniping damaged units. No longer a carpet of melee units moving around in circles.

    The only issue was that her otherwise strong attack force also included about four or five settlers which were easy to capture!
     
    Littlebob86 likes this.
  15. sresk

    sresk Chieftain

    Joined:
    Sep 23, 2010
    Messages:
    98
    So I too am playing a heavily modded game and am using the mix of the 2 AI mods... but I wanted to give some feedback as well. While the difficulty isn't dramatically harder(better) it is in fact better. I've had the AI actually kill a number of my units in the first war. (Rather then just staring at half life archers and getting arrows rained on their heads like before) And at least 3of the civs are doing a good job of keeping up with me in settling cities and tech even though I've captured 3 cities and 2 settler (Gandhi is SOOOO bad at war). I'm only into 1300 bc so still early but so far so good I'll play this one a little further and try to provide anymore feedback.

    I am still curious why the AI doesn't ever seem to build archers of their own nor upgrade their slingers. It kinda seems like archery is a mandatory tech and I always have to rush it as the 3rd or 4th tech... is that strategy something that can be prioritized for the AI?

    Oh also I am convinced that adding 1 maintenance to warriors and slingers makes the first 50 turns better as it seems the AI does a better job of building things other than hoards of those two units. I know you are primarily focused on AI and not balance so if you don't want to make that changes is there a way to simulate it and either lower the AI's priority for those early game units or trick them into thinking their is a cost?

    PS all of this is on emperor epic
     
  16. Laurana Kanan

    Laurana Kanan Don’t underestimate who I am. Moderator

    Joined:
    Apr 10, 2014
    Messages:
    3,062
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    @sresk I've noticed that since Archery is a dead-end tech the AI tends to avoid researching it. I made Archery a prereq for Bronze Working and have rarely seen a Slinger since. Also, and even though it's not a dead-end, I made Iron Working a prereq for Construction with the same results for Warriors/Swordsman. As long as the AI has the money and access to iron for the swordsman, they'll build/upgrade them. Imo, adding maintenance to early units caused my games to start way too slow on my expanded huge maps - not enough action, even with 15 civs.
     
    Littlebob86 likes this.
  17. sresk

    sresk Chieftain

    Joined:
    Sep 23, 2010
    Messages:
    98
    Hmm do you have the code to change those prerequisites? And I'm playing with 200% - 350% tech costs (scales by era), and less tech per pop, and 75% production costs... this stretches out eras and gets more units built. I like how it plays.
     
  18. sp00n

    sp00n Prince

    Joined:
    Jan 4, 2007
    Messages:
    347
    So, just wondering, is this expected behaviour? He's been standing there like forever, it started quite early with 7 warriors, I already suspected a warrior rush. We've been friendly right from the get-go, and actually had a declared friendship multiple times. Not sure what to think of this.
    Military strength seems to be massively increased for other civs as well.

    This is on King difficulty, and the most revent v7 (although the modinfo is still set to version 5, maybe an oversight).
    PericlesBlock.jpg
     
  19. Laurana Kanan

    Laurana Kanan Don’t underestimate who I am. Moderator

    Joined:
    Apr 10, 2014
    Messages:
    3,062
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    I used MadDjinns Tech Tree as a start for changing prereqs and moving some techs around. I also play with a modified Gedemon's Slower Tech and part of Quo's Pre-Patch yields for building costs.
     
  20. Delnar_Ersike

    Delnar_Ersike Prince

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    *Professor voice* Good news, everyone!

    I found out that it wasn't just low maintenance cost that caused the AI to spam warriors and slingers. It turns out that almost no military land units had their pseudoflavors set up to point to "combat unit", and builders didn't have their pseudoflavors set up either. The instant I set them, the AI stopped spamming Warriors and Slingers and actually diversified their army! v8 will include the fix, as.

    Way ahead of you, I changed this in v2 of my mod.

    The problem with this is that there's no inheritence system for pseudoyields, so e.g. if a new pseudoyield is introduced that's meant to be a subcategory of an existing pseudoyield (e.g. combat unit -> unique combat unit), then the only way to get the parent pseudoyield modifiers to trickle down to the child is to manually add them in for the child for every case, possibly breaking compatibility with other mods that alter pseudoyields (e.g. they might alter all combat pseudoyields to renormalize them, but because they haven't accounted for your new pseudoyields, so your new pseudoyields that aren't renormalized will mess with the old pseudoyields that are).
     
    Mglo and Littlebob86 like this.

Share This Page