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

Real Strategy 1.2

Making AI better. One bit at a time. Test version.

  1. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    Current Version 1.2, posted on 2019-03-17.

    Goals and guidelines
    Also a little bit about my modding philosophy.
    Civ is a complex game, with many subsystems interacting with each other. It is not possible to make them all perfect and ideal, especially with constraints that come from the business side (money, money, money...)
    Having said that, I think that devs did a really good job making all this working together and opening most of the system for modding. Modding gives endless possibilites, however my goal is to make Civ a better game, not a different game. I think that this can be achieved by fixing errors, tweaking things, and fully utilizing the features of the game.
    And this is the goal and guidelines of this mod - to make AI better by fixing / tweaking / enhancing, not by throwing it away and re-programming everything.

    Victory strategies and conditions
    This is actually the story of how the mod has started.
    There are 4 victory strategies as of now in the vanilla game. Please note that GS added Diplomatic Victory but there is no strategy created to support that. RST however adds a strategy for Diplomatic Victory. They are activated when 2-3 conditions are met. These conditions are very simple e.g. is there war, do we have a good science / culture / faith city, do we have a religion, are we in top 33% of techs or military power, did we acquire a great writer, etc.
    These conditions are so simple that victory strategies are enabled, disabled, changed, multiple ones are active, etc. Only in the late game, once the civ is really close to a victory, it kind of locks-away others and focused on one strategy. There is nothing that even remotely resembles some background thinking or determination in pursuing a goal.
    And I think that for the AI to actually have a chance to win, it must focus exclusively on one goal and pursue it as much as possible.
    The mod uses an amazingly powerful mechanism that allows to call a Lua function as one of the strategy conditions. This allows for implementation of virtually anything to make AI better in making decisions about strategy and behavior in the game.

    Implemented algorithm
    Active Strategy is decided based on a scoring that evaluates the current situation. Initial ideas for this algorithm were taken from Civ5 engine enhanced by Vox Populi, however I had to re-think many of them and adjust to a) Civ6 realities b) no-cheating policy (use only information that is available to the human playe).
    There are tens of parameters available to tune this process (file RealStrategy_Params.sql).

    Flavors
    The key element of the process are flavors (numbers ranging 1..9). They are assigned to Leaders and show their predispositions for various victory types. In order for this to work they must ofc correspond with the overall civ and leader design, their uniques, etc.
    The other groups of flavors are assigned to various items that the civ can acquire during the game: Policies, Wonders, Governments, Great People, Beliefs and City States (acquired = being a suzerain). The idea here is to evaluate how the civ is prepared to pursue a specific victory type.

    Process
    1. Base. Leader flavors are used to establish a base scoring. There is however a bit of randomization applied to flavors (-1..+1) allowing for the leaders to behave a small bit differently (we don't want the game to be boring).
    2. Specfic. Each victory is scored against the progress of the civ in specifc areas. Usually it is a comparison to ther civs (no cheating - only ones we've met), etc.
      • If a specific victory type is disabled - the scoring is negative making sure that the civ will NOT pursue this strategy.
      • CONQUEST - our military power, capitals taken, expansion factor, desperation factor, etc. This is actually the most complex algorithm.
      • SCIENCE - comparison of science yield and number of techs acquired, progress of the Space Race projects.
      • CULTURE - comparison of culture yield, evaluation of the cultural progress (expotential formula)
      • RELIGION - comparison of faith yield, evaluatonof the convertion progress (num of cities, expotential formula), civs converted, inquistions launched.
      • DIPLO - number of diplo points and amount of favor gathered.
    3. Generic. All the acquired items (see flavors) are accounted here.
    4. Game progression. Specific & generic scoring becomes more important as the game progresses to make sure that the civ actually pursues the victory that it is good at.
    5. Bit of randomization but also current strategy is boosted, to avoid temporary mood-swings.
    6. Guessing. The civ tries to guess what others are doing and adjust accordingly our scoring.
      • Algorithm for guessing is very similar as the main one, however only uses available info. So, in particular no leader flavor is used or what policies were taken, etc. It is more based on actual progress of the civ.
      • We evaluate if the civ performs better than us. Algorithm here is very similar to the one used in the Victory Tracker window. Basically, 2 key params are compared.
      • Important part. For each civ doing better than us, our scoring gets cut down by 25% (a parameter ofc.) It is a very important parameter because it allows for better dynamic during the game. As for now, if 1 civ is better than we are - we most likely still gonna go after that, for 2 better - well, we really need to be predisposed for that victory, if we are not - probably better pursue another strategy. If 3 are better, well a new strategy will be selected like in 99% cases.
    7. The algorithm accounts for disabled victory conditions. The scoring is set to 0 in that case and the strategy will never be selected.

    Enhanced leaders
    Going through the original programming of the Leaders, I found out that most of them use just the basic systems available in the game. Like, really basic. Favored Wonders and Favored Techs / Civics which usually are just the ones that hold their uniques or wonders. Sometimes DiploActions, very few use PseudoYields.
    There are ofc exceptions, especially for civs added in DLCs and R&F. More systems are used, but still - imho - there is a HUGE area for improvement here.

    RST enhances each leader accordingly, in various ways. It all depends on the leader and how well (or bad) it was already programmed.

    Each leader has been reviewed and enhanced accordingly to its design. By design I mean all the uniques and features that a civ & leader possess, giving it an advantage to pursue specific victories.
    There are too many leaders, so I would like just to point out some guidelines.
    - Virtually all parameters from vanilla game are still there. I usually added bit more specific ones, trying to make each civ/leader as unique as possible.
    - The changes are designed to enhance the civ/leader design. Example. Alexander has a boost for siege units because his unique ability triggers when he conqueres a city. Monty has boost to look for luxuries and settle more aggressively to get them. Etc.
     
    Last edited: Mar 17, 2019 at 3:39 PM
    glider1, Elhoim and Gedemon like this.
  2. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    Strategies
    An important note. Strategies (all of of them) have an intrinsic intertia. They affect civ-wide global behavior but it is difficult naigh impossible to get immediate effects. It simply because the civ tries to first finish current things (building, researching, etc.) Then, when a new decision is made, new params will influence it.
    City queues DO however sometimes abandon things and start working on something else. Increasing one param drastically could potentially force a civ to react faster but it is dangerous because it affects all cities and all queues, so I really try to avoid this approach.

    Supporting strategies
    As for now there are 8 supporting strategies implemented. There could be more in the future, also more sophisticated could be implemented when necessary. Basic premise here is that Lua allows for a detection of the specific situation in the game (strategy conditions) and then the actual strategy can modify various parameters as needed.
    - Peace - a bit more focus on infrastructure, yields, people, etc.
    - War - more focus on military, slowed down infrastructure and things like Wonders.
    - Catching (up) - a civ should try to have a comparable military size to the neighbors, it starts producing more military once it falls below 60% of the average.
    - Enough - to prevent from over-investing in the military, once we are the leader and we have more than 230% of the average, we should slow down with combat units. Also, due to our might, we get bolder, allowing to attack stronger cities.
    - Defense - this is a war time strategy when we are attacked by a really stronger opponent (2x stronger); basically we stop doing anything and try to produce military as much as we can - this is about survival.
    - More GW slots - this is a scalpel-type strategy; there are 2 problems with GWAMs. (a) a civ gets them but doesn't create GWs (b) there is no place to put more GWs; this strategy detects the second situation and forces the civ to build a Theater Square. Once we have enough slots, the pressure is lifted. It counts also slots that are currently in production. To save a bit of time, it runs every 4 turns.
    - More Science - simple strategy, that activates when we fall 3-6 techs behind the average, depending on Era; forces to build a Campus and science-generating buildings.
    - More Culture - simple strategy, that activates when we fall below 80% of average culture output; forces to build a Theater Square and culture-generating buildings.

    I am working on adding a Threat strategy that would activate before the war when our neighbor starts being dangerous, e.g. denouncing us, moving an army, increasing military, etc.

    Time Strategies
    Existing Time Strategies have been revised, also added some tweaks for Atomic and Information eras.
    In general:
    - Classical - more culture, science and food
    - Medieval - more faith, food, prod, less science, more wars (I hope)
    - Renaissance - less faith and food, more culture and science, less wars (I hope), more naval for exploration
    - Industrial - more production, more wars, less faith, less settlers
    - Modern - more gold and culture, bigger armies, more wars, less settlers
    - Atomic - more sci and prod, more air units, less settlers
    - Information - shrink armies, less wars, more gold, less food, less settlers, more air units

    Naval Strategies
    A civ based on revealed tiles determines its geo-situation and tunes its behavior accordingly.
    - Pangea - naval units are virtually ignored.
    - Default - standard situation when there is land with some coast.
    - Coastal - land with lots of coast and peninsulas - civ will prioritize Harbors and build more naval units. More naval ops.
    - Island - little land, mostly coast, lots of water. Civ will prioritize Harbors and build mostly naval units. More naval operations should be visible. Exploration is sea focused and should last much longer than usually.
    There is also a quite complex strategy implemented that should result in civs using more ranged ships from Medieval era onwards. In Ancient era only Galleys should be used, in Classical Quadriremes should start appearing.

    An old note regarding vanilla Naval strategy. I find it a bit peculiar when this strategy activates. The detection is hardcoded in the engine, so it is unknown how the algorithm works. There is only one condition "Is On Island" that activates this strategy. Issues:
    - I am positive that it somehow takes into consideration the Area in which a civ spawned. Area is a technical division of the map. So, Minors get small areas, and they "detect" island much faster. Majors - the bigger area, the more time it takes. Problem is that Area is an artificial idea, it doesn't affect e.g. where a scout can go, etc.
    - Clearly, this is a binary condition. No way to actually change behavior for situations like "small island" or "big island" or "small continent" or "pangea". I've seen situations where civs on one continent were "naval" and on the other were not, and the continents were very similar in size.

    Existing Strategies
    Early Exploration - important change here; in vanilla it lasts until 2nd city is settled, so not so long. I changed it, so it lasts until 3rd city. This gives a bit more pressure for AI to scout the area. Also - it applies only to land-type strategies. Coastal and Island have their own exploration strats, more sea oriented.
    Rapid Expansion - tweaks only
    Naval Strategy - now part of Naval Strategies (used as Coastal one).
    Dark Ages - not changed yet.
     
    Last edited: Mar 12, 2019 at 7:53 AM
    Victoria likes this.
  3. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    How to test

    1. In this version, the mod produces a lot of output to Lua.log. Basically key information about evaluation and guessing is there.
    Important. Please try to post Lua.log - it contains crucial information needed for analysis and tuning.
    2. In the FireTuner you can watch on-the-fly the situation in the game - what strategies are chosen and key information about the civs.

    Lua.log

    Two parameters enable / disable logging of strategy decisions and guesses, RST_OPTION_LOG_STRAT and RST_OPTION_LOG_GUESS respectively. They produce lines showing the scoring for each strategy or a guessed strategy.
    Code:
    RealStrategy: 301, RSTSTRAT, LEADER_SHAKA, CONQUEST @ 207.4, CONQUEST @ 207.4 (-69.1), SCIENCE @ 33.9, CULTURE @ 37.7 (-12.6), RELIGION @ 37.0 (-110.9)
    RealStrategy: 301, RSTGUESS, LEADER_SHAKA, LEADER_TRAJAN, CONQUEST @ 97.6, CONQUEST @ 97.6, SCIENCE @ 25.4, CULTURE @ 93.6, RELIGION @ 50.4
    
    Other lines (many) are for debugging purposes and eventually will be removed. They show detailed info about how the scoring was calculated.

    FireTuner

    The FireTuner screen looks like this.
    Top-Left section
    Information from the mod about the strategies. Please be aware that strategies are updated every 7 turns. . T# - turn when updated. What strategy. Scoring for each strategy. Era. How many majors met. If religion is founded. How many civs converted.

    Botton-Left section
    Key statistics. This is updated online. Num of cities. Military Strength. Capitals taken. Num techs researched. Science yield, culture yield, tourism yield. Progress of the cultural victory. Faith yield. Num of cities converted.

    Top-Right section
    Various additional information. Supporting strategies active (letter=active): Peace, War, CatchinUp, Enough, Defense. Government. Gold balance. Trade Routes. Pantheon.

    Botton-Right section
    Information about Districts. Each full number is 1 built district. Each 0.1 is a district being built. E.g. 3.2 means that there are 3 districts and 2 are being built. In order: Holy site, Campus, Theater square, Encampment, Harbor, Commercial hub, Industrial zone. Unique distrcts are also counted respectively.

    Version 0.7
    There is a new panel on the right that shows Naval Strategies and a Coast2 ratio calculated by the algorithm.
     

    Attached Files:

    Last edited: Mar 17, 2019 at 4:53 PM
  4. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    Systems
    There are currently 27 systems in use that control the AI and game behavior. They are used by creating AiLists that contain Items stored in AiFavoredItems table. In general, one can say which Item is favored or not, and through the Value also by how much. Value is usually a percentage. This information is then used by e.g. scoring systems to evaluate various options and choose the best one.
    Not all columns in the table are used by each system - it all depends on the system.

    AiBuildSpecializations
    Pre-configured system (DefaultCitySpecialization).
    Value here most likely is Priority (so, Defenses are the highest). Notice that Traders are lowest and this could be the reason of Gold problems for AI in late game. RST boosts Traders, so AI fully utilizes TR capacity.

    AiOperationTypes
    Controls the number of operations that can be run simultaneously.

    AiScoutUses
    Controls the number of exploring units and their purpose (e.g. land scouting, naval scouting). There are 5 default types available. Values used here are in percentages (confirmed by a dev comment in Vikings Scenario).

    Alliances - added in R&F
    System to manage favored alliances.

    Buildings
    One of simple systems; setting a building as Favored boosts its valuation significantly; it is used usually for Wonders. For normal buildings the result will be that the building will virtually appear everywhere. Opposite option also works - setting Favored to "0" gives the opposite effect. Civ most likely never build it.

    CityEvents
    System that controls type of operation triggered by various types of city events. There is a default list (DefaultCityBuilds) that contains all of them. Theoretically it is possible to trigger multiple ops with single event (PK is made of 2 columns), but I couldn't do it.

    Civics
    One of simple systems; tells which Civics are preferred. The civ will usually go for them as first. It can be used to influence which government a civ should choose as the first. There is no "preferred gov" system, so forcing a civ to go for a civic will eventually make it change the gov because the new one has more slots (bigger scoring).
    Edit. I found out by testing that Favored=0 doesn't do anything. Shame.

    Commemorations - added in R&F
    Favored dedications (internally they are called commemorations).

    DiplomaticActions
    System to manage favored diplomatic actions. Also allows for setting "disfavored" ones.

    Discussions - added in GS
    World Congress support. Allows to define which disussions are favored and which are not.

    Districts
    System to manage favored Districts. It boosts valuation for a District quite high.
    Please be aware that setting a District as Favored will result in building it in virtually every city.

    Homeland
    Available Homeland actions. Seems to be pre-configured.

    PerWarOperationTypes
    Controls the number of operations per started war.

    PlotEvaluations
    This system is used to score plots for settlement purposes. It is possible the see the scoring (there is a Lua function for that) for 3 plots that the game "recommends". This allows for testing.
    Important. This system ignores Favored flag. I changed that flag for different params and the scoring was always the same. Also, fractions don't work. XML and SQL allows for fractions, but only integer is used for calculations.
    Parameters.
    - Foreign Continent - adds Value to the scoring if the plot is on the foreign continent.
    - Coastal - adds Value to the scoring if the plot is on the coast.
    - Fresh Water – adds Value when spot has fresh water (river or lake).
    - Inner Ring Yield - adds Value * yield for a specified YieldType; Inner Ring is 6 tiles around the spot, the central plot is not counted.
    - Total Yield - adds Value * yield for a specified YieldType counting Rings 1-3; please note that it overlaps with Inner Ring!
    - Resource Class - adds Value for each Resource of the specified class within Rings 1-3. Important. AI doesn't cheat here - it counts only revealed resources.
    - New Resources - adds Value for each copy of the new resource in Ring 1. Important. Improved resources are not counted and the tech to improve the resource is not required. I.e. it will count tea even if you don't have Irrigation.
    - Specific Resource - adds Value for each copy of the specific resource within Rings 1-3. No cheating, only revealed are counted.
    - Specific Feature - adds Value for each tile of the specified Feature within Rings 1-3.
    - Nearest Friendly City - key parameter that controls how far away from our city a new one is settled. It adds Value * Distance to the score. Notice however that Value is negative (-10 by default), so it means that 1 tile is worth 10 points. Since there has to be at least 3 tiles, so by default the score gets a -30 hit. This explains (mostly) why most of the AI cities are 4 tiles away from each other.
    - Cultural Pressure - parameter added in Rise & Fall. I think it was supposed to work in a way that Favored=0 adds your pressure (closer to your cities) and Favored=1 subtracts pressure from others (so, away from others). Well, imho Favored=1 doesn't work (Favored is ignored in the entire system). Thus only Favored=0 gives an effect and it adds Value * (20+Pressure). This partially explains why sometimes AI settles cities in the pressure zone - because even with pressure -10, it still adds Value * 10 to the score. If the 2nd parameter would work, AI would never settle a city in a pressure higher than -10 (-60 hit), even -5 would be very unlikely (unless a crazy good spot).
    Additional info.
    There is no support for Terrain. So, hills and mountains are ignored and hills influence settling only via production yield.

    Projects
    Favored Projects.

    PseudoYields
    This system contains many various parameters. Important info on usage. In all the parameters I have tested, Value in AiFavoredItems was a percentage (increase or decrease). In some cases it was capped at the bottom to -95, but in some not, allowing to zero the value by using -100.

    PSEUDOYIELD_CITY_* - City Valuation. Used in evaluation the operations.
    I determined that:
    - Bias value is always a percentage and it is bottom-capped at -95%.
    - BASE and ORIGINAL_CAPITAL - just plainly add the value modified by bias_percentage
    - POPULATION formula: Value += floor(CityPop/5) * (base * (1+bias_percentage)) - notice that it changes every 5 pop
    - DEFENSES - it subtracts the value depending on city's Defense Strength, Value -= base * (city_defense+11)/37 * (1+bias_percentage)
    - also, this applies only when city_def >25 if city has walls, and >20 if city has no walls;
    - if def is less than that, a standard factor is applied which is not affected by pseudo value at all
    - DEFENDING_UNITS - it subtracts the value depending on how many units are defending the city; I couldn't determined an exact formula for that, just hints:
    - it seems to account for units within Range 3, garrisoned unit is treated differently
    - the stronger the units, the more is subtracted
    - basically 2-3 units around decrease the valuation quite signifcantly, 4-5 almost make it 0
    I noticed that in later eras, due to huge increase in City's Defense, many cities have value simply 0. This could be one of reasons why wars disappear in time.

    PSEUDOYIELD_CIVIC & PSEUDOYIELD_TECHNOLOGY
    These Pseudos affect the valuation of Civics and Technologies
    However, each is applied to a separate tree respectively, and since the trees are separate they don't clash
    Tweaking these probably would result in a bit different order of selecting civics and techs, but without the details of the algorithm it is hard to predict results.
    I determined only that:
    a) Each civic and tech has a residual valuation that can be seen when setting those Pseudos to 0.
    b) The pseudo default value is multiplied by a factor of 30..100 and added to the valuation; this factor is different for each civic / tech, and that is why it could affect the order.
    c) The bias value (from AiFavoredItems) affects this factor even further, so formula is: factor * def_value * ( 1 + bias_percentage )

    PSEUDOYIELD_GPP_* valuation of Great People and means to get them. Affects District valuation for sure. Does not affect policies (BUG). Edit. I found out by accident that GP policies are affected by YIELD_GOLD (BUG).
    PSEUDOYIELD_UNIT_* units valuation. Unit's pseudoyield is defined in Units table. There is a default PSEUDOYIELD_UNIT_COMBAT which is for all combat units that don't have a PseudoYield in the Units table.
    PSEUDOYIELD_GREATWORK_* valuation of Great Works. Details unknown (e.g. does it affect also trading?)
    PSEUDOYIELD_CLEAR_BANDIT_CAMPS - probably for evaluating the need to fight barbs, details unknown.
    PSEUDOYIELD_ENVIRONMENT - national parks, new forests, not-chopping, etc.
    PSEUDOYIELD_IMPROVEMENT - valuations of improvements. Please note that increasing the valuation of UNIT_BUILDER does not mean that more improvements will be built. Builders are contracted for building improvements. Once contracted, the valuation will affect how quickly they are build.
    PSEUDOYIELD_INFLUENCE - envoys
    PSEUDOYIELD_DISTRICT - districts
    PSEUDOYIELD_WONDER - wonders. I assume that this is an additional parameter applied on top of normal building valuation.
    PSEUDOYIELD_DIPLOMATIC_BONUS - probably evaluation of diplomatic actions, unclear what exactly does it affect (worth? cost? modifier value?) Lower values make civs don't care about the relation. Appears also in relation to warmongering.
    PSEUDOYIELD_NUCLEAR_WEAPON - WMDs, details unknown.
    PSEUDOYIELD_SPACE_RACE - valuation of Space Race projects. Details unknown.
    PSEUDOYIELD_TOURISM - tourism yield - crucial for Cultural Victory.
    PSEUDOYIELD_HAPPINESS - amenities.
    PSEUDOYIELD_GOLDENAGE_POINT - as commented by devs: Note: Dark Age point is the value of avoiding getting that point. We assume no AI's will be deliberately seeking a dark age
    PSEUDOYIELD_GOVERNOR - governors, but details unknown. Since this applies to all of them and we get them by going through Civics, it is really unclear what this could influence. Could be GovernorType, but there is no usage at all.
    Added in GS:
    PSEUDOYIELD_DIPLOMATIC_FAVOR - diplo favor valuation,
    PSEUDOYIELD_DIPLOMATIC_GRIEVANCE - grievence valuation, it has a negative value so it actually decreases chances of a diplo action,
    PSEUDOYIELD_RELIGIOUS_CONVERT_EMPIRE - from devs: Religious Convert is a value intended to help AI pursuing a religious victory to choose targets in other empires. It is used only in ReligiousVictoryPseudoYields.

    Resolutions - added in GS
    World Congress support. Allows to define which resolutions are favored and which are not.

    SavingTypes
    Seems to set priorities for the usage of Gold.
    There is a very strange order however: Plots & Great People / Slush Fund / Units. Unclear if lower number means higher priority or lower priority.
    AI for certain does upgrade units however this process is only run when civic or tech has been researched. If it lacks gold to upgrade them all, it seems to stuck however.

    SettlementPreferences
    Controls the dynamics of the settlement process in relation to the scoring done by PlotEvaluations. There are 6 values SETTLEMENT_*
    I am not certain how they work. Most likely, to settle a city, the scoring needs to have a minimum value MIN_VALUE_NEEDED. This is increased when a city is settled by CITY_MINIMUM_VALUE. Then this value decays over time, by DECAY_AMOUNT for every DECAY_TURNS.
    ADDITIONAL_VALUE_PER_CITY - unclear if this affects min value needed or city value.
    CITY_VALUE_MULTIPLIER - no idea what it does.
    Example. Trajan uses this system. MIN_VALUE_NEEDED is decreased to allow to crappy places. ADDITIONAL_VALUE_PER_CITY is decreased, so expectations for next cities aren't too high. Decay params are tweaked, so the value decays much faster - allows to find next settle spot faster. CITY_MINIMUM_VALUE is increased - and this one I cannot explain. Maybe to balance other params, so Trajan would not end with only crappy cities.

    Tactics
    Available Tactical actions. Seems to be pre-configured.

    TechBoosts
    This system controls AI behavior when pursuing Eurekas and Inspirations. As for now, it is pre-configured with a set of various triggers. Checking out the logs, it seems that AI is actively trying to pursue every boost for which a trigger exists. It doesn't mean that it gets every boost, because it depends on the timing also (e.g. if a unit or building is built on time).

    Technologies
    One of simple systems; tells whch Techs are preferred. The civ will usually go for them as first. I discovered that the reason why so many civs were building Holy Sites very early were because they had Astrology as preferred tech. After the tech was discovered, HS was the district the civ could buld atm and Districts have high valuation just by themselves. Enough to force the civ to build HS.
    Edit. I found out by testing that Favored=1 doesn't work here (BUG).

    TriggeredTrees
    System to control AI reaction to various events. List of events is pre-configured.

    UnitPromotionClasses
    This system allows to influence the valuation of units that have a specific Promotion Class.

    Units
    This system allows to influence the valuation of a singular unit.
    For units in general, I believe that Combat Strength is a base for valuation. No idea what is used for Civilian units.

    YieldSensitivities - added in Rise & Fall
    Unclear. It is either redundant to Yields or controls a different, unknown, aspect of the valuation.

    Yields
    One of the most important systems. Affects all valuations that are related to yields: policies, civics, techs, buildings.
    Default value for each yield is stored in Yields table. It is 1.0, except for Gold which is 0.5.
    Bias value from AiFavoredItems is a percentage. It is not capped at the bottom, so putting -100 basically sets the yield value to 0.
    Valuation assumes 30-35 turns of a yield generation.
     
    Last edited: Mar 17, 2019 at 4:52 PM
    Das Capitolin likes this.
  5. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    Work in progress and Plans
    1. Implement better Naval strategies. Basically, I don't like the binary condition that the game provides 'Is On Island'. There is a difference between actual island and peninsula, or just a continent with lots of coast, etc. I am working on a algorithm that would detect those situations and after that apply different strategies.
    2. Late game behavior. It is difficult to test late-game because turns take too much time. But I would like to implement some sort of "finishers".
    3. "Anti-strategies" - related to late-game. If some civ is close to victory, I would like others to more focus on disrupting this victory.
     
    Last edited: Jan 15, 2019
  6. pokiehl

    pokiehl Chieftain

    Joined:
    Mar 5, 2017
    Messages:
    481
    Nice work infixo! I'll test this when I get a chance.
     
    Infixo likes this.
  7. Revolutionist_8

    Revolutionist_8 Chieftain

    Joined:
    Jan 30, 2016
    Messages:
    299
    Location:
    Hungary, Earth, M.W. Galaxy
    Sounds very-very promising, impressive work! Looking forward to try it / give feedback :)

    Please let me ask two questions:

    - reflecting to this sentence: "And I think that for the AI to actually have a chance to win, it must focus exclusively on one goal and pursue it as much as possible." - how much does it "lock" AIs into one victory condition? If I understood correctly they constantly check their progresses and make decisions based on their current situation, right? So it's not like X civ decides that they pursue lets say cultural victory in ancient era, and they pursue throughout the game even if they would have better chance at lets say conquest.

    - how much mods that affect policies / governments etc. affect AI decision making with RST? (I'm thinking about like a government that doesnt exist in vanilla, so it probably has no flavor in RST. Could it affect AI "thinking" in any harmful / significant way?)
     
  8. pokiehl

    pokiehl Chieftain

    Joined:
    Mar 5, 2017
    Messages:
    481
    For what it's worth, I think this mod would gain a lot more traction on Steam if you squeezed the word "AI" into the title.

    Anyway, Infixo, do you have any insight into whether this is multiplayer compatible? As in, do you think the Lua functions would cause desyncs?
     
  9. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    8,165
    Location:
    France
    that would depend on how the pairs() function is used, and how random numbers are generated.

    edit: and the Events used.
     
    Last edited: Jan 7, 2019
    pokiehl likes this.
  10. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    Ad. Locking. You understand correctly. Civs change their goal depending on the situation. It may happen on various occasions, most likely:
    - meeting a new civ; like you rocking with science on your continent but mid-game you discover a new continent and there is Korea and GilgaBro 10 techs ahead of you :)
    - just a game progress - others may become better - that is the whole idea here;
    - war effect - this happens often too; when you'll loose a city or 2 then your yields and infrastructure get a serious hit, so a change might happen
    Ad. Other mods. If you enter data into RSTFlavors - they will be ofc taken into account. This a very simple mechanic here - sum of items and multiply by weight. From my observations, as for now this generic part accounts for approx. 10-25% of the score. This needs more tunning probably. I would give it more weight but I find choices of polices or wonders that AI builds to some extent random(ish).

    My goal is to achieve the situation where early-game leader flavors matter the most (~40-50%), and progress ~20-30%. Mid-game progress should take over, accounting for 60+% late game.
     
    Last edited: Jan 7, 2019
    Revolutionist_8 and pokiehl like this.
  11. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    People understand AI in many ways, often as Tactics (why planes are not used? etc.) I don't want to create false expectations.
    I don't play multiplayer and I have no experience in programming in this area. Can't even answer your question :(
     
  12. Revolutionist_8

    Revolutionist_8 Chieftain

    Joined:
    Jan 30, 2016
    Messages:
    299
    Location:
    Hungary, Earth, M.W. Galaxy
    Thank you for the infos :) Keep up the good work! :)
     
  13. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    Can you pls elaborate a bit more?
    I can see why random numbers could be a problem (i assume each player runs its own scripts). But why pairs()?
     
  14. CrazyVulcan

    CrazyVulcan Chieftain

    Joined:
    Dec 7, 2016
    Messages:
    11
    Gender:
    Male
    Location:
    Rock Hill, SC
    I was actually musing on how to better implement a Ai improvement myself and am super glad to see LUA once again showing its power. I have a question on how you plan to handle the unit micro Ai? I have not had a chance to really dig into your work and see so perhaps you could give a brief explanation as to your changes to the Ai tree that each unit loops though? I do see you are focused on the Macro and that definitely needs the most work as that is the front end of what a player experiences for the Ai but I was wondering how you were handling the individual units taking a city?

    First is who is the strongest? Go through every unit in the group and find the unit with the highest combat strength. If there is a tie chose the units closest to the objective.

    1.Am I over %50 combat strength?
    Yes? Go to #2.
    No? Is my Group’s total combat strength over %50
    Yes? Can I move back to the tile I moved from last turn or the Staging Zone?
    Yes? Move!
    No? Fortify!​
    No? Go to #2.​

    2.Can I move to a enemy unit?
    Yes? Can I make a stalemate or better?
    Yes? Attack!
    No? Go to #3 if still No Attack!​
    No? Go to #3 Or Move toward City Center Objective​

    3.Can I move and attack the city center?
    Yes? Are there walls Up?
    Yes? Can I do a Stalemate Or Better
    Yes? Attack!​
    No? Is there a “siege” unit within 4 tiles of City Center? No? Attack!
    Yes? Fortify!
    No? Treat as if wall are down​
    No? In my Groups total strength under 50%
    Yes? Fortify in seige
    No? Attack till death!​
    No? Attack Closest enemy or Move toward City Center.
     
  15. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
    I don't plan to go into this using Lua - that is for sure. Moving units via Lua is very problematic as it clashes with normal engine genarated moves.
    I might do some tweaks or enhancements to Behavior Trees - this is possible but first I need to see Gathering Storm.
     
  16. CrazyVulcan

    CrazyVulcan Chieftain

    Joined:
    Dec 7, 2016
    Messages:
    11
    Gender:
    Male
    Location:
    Rock Hill, SC
    Sounds about right from my experience Last I tried to do something to the Behavior trees I was not sure what I could do to fully access them and there was no documentation as to what string operated what. I may have to have another look but I will fire up Civ6 here in a bit as I am very excited to try this mod.
     
  17. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    8,165
    Location:
    France
    Yes, each player runs its own script.

    For random numbers, you can use TerrainBuilder.GetRandomNumber() instead of math.random(), it will give the same number on all computers in a MP game, as long as the number of calls are identical.

    For example if computer A call TerrainBuilder.GetRandomNumber() more than computer B (because one call was made after a local event or action) then the next result of TerrainBuilder.GetRandomNumber() will be different on computer A and B, leading to desyncs.

    pairs() is unordered, which means the loop is not done in the same order on computer A and B, or even when called another time on a specific computer for the exact same table.

    It would be an issue for the following function:
    Code:
    -- get a new table with random integers in range -iRand..+iRand (both inclusive)
    function PriorityTableRandom(iRand:number)
        local tNew:table = {};
        for strat,_ in pairs(Strategies) do tNew[ strat ] = math.random(-iRand, iRand); end
        return tNew;
    end
    because even if math.random() was replaced by TerrainBuilder.GetRandomNumber(), computers A and B would get the same random number at each iteration, but the "strat" that number would be applied on could be different.

    You can use the orderedPairs() function that Firaxis has added in SupportFunctions.lua (which I added in my mod from the same source before realizing they used it already)
    Spoiler :
    Code:
    -- ===========================================================================
    --    orderedPairs()
    --    Allows an ordered iteratation of the pairs in a table.  Use like pairs().
    --    Original version from: http://lua-users.org/wiki/SortedIteration
    -- ===========================================================================
    function __genOrderedIndex( t )
        local orderedIndex = {}
        for key in pairs(t) do
            table.insert( orderedIndex, key )
        end
        table.sort( orderedIndex )
        return orderedIndex
    end
    function orderedNext(t, state)
        -- Equivalent of the next function, but returns the keys in the alphabetic order.
        -- Using a temporary ordered key table that is stored in the table being iterated.
        key = nil;
        if state == nil then
            -- Is first time; generate the index.
            t.__orderedIndex = __genOrderedIndex( t );
            key = t.__orderedIndex[1];
        else
            -- Fetch next value.
            for i = 1,table.count(t.__orderedIndex) do
                if t.__orderedIndex[i] == state then
                    key = t.__orderedIndex[i+1];
                end
            end
        end
    
        if key then
            return key, t[key];
        else
            t.__orderedIndex = nil;        -- No more value to return, cleanup.
        end   
    end
    function orderedPairs(t)   
        return orderedNext, t, nil;
    end


    but if you do you'll have to make sure you don't escape the iterations with a break (or return) unless you clean (or check before next call) the __orderedIndex added by the function to the table

    see TechTree.lua:
    Spoiler :
    Code:
        -- Loop items again, assigning column based off of total columns used
        for _,item in pairs(m_kItemDefaults) do       
            local era        :table  = m_kEras[item.EraType];
            local i            :number = 0;
            local isFound    :boolean = false;
            for cost,columns in orderedPairs( era.Columns ) do
                if cost ~= "__orderedIndex" then            -- skip temp table used for order
                    i = i + 1;
                    for _,itemType in ipairs(columns) do
                        if itemType == item.Type then
                            item.Column = i;
                            isFound = true;
                            break;
                        end
                    end
                    if isFound then break; end
                end
            end
            era.Columns.__orderedIndex = nil;
        end


    (in my code I simply do the "myTable.__orderedIndex = nil;" before each "break;" or "return;" in a orderedPairs() loop)
     
    Infixo likes this.
  18. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw
  19. Raven_2012

    Raven_2012 Chieftain

    Joined:
    Dec 10, 2016
    Messages:
    51
    Gender:
    Male
  20. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,828
    Gender:
    Male
    Location:
    Warsaw

Share This Page