Announcement

Collapse
No announcement yet.

Conversations with Richard Myers (Azmel)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conversations with Richard Myers (Azmel)

    Richard Myers, if you didn't know, wrote the AI routines for Ctp2. He contacted me a couple of weeks ago and offered his help with an AI questions that I had. Needless to say, I was delighted to hear from him, and had many questions to ask. Below I have pasted Richard's answers to my first round of questions, which dealt with issues in the strategies.txt.

    My questions were aimed at addressing problems or questions I had regarding the Med mod II, but I think his answers shed light on things that many of us have been wondering about. In his second letter, he covered some things that I am a little fuzzy on, so I would like for some of you who can expound upon these things further to post your comments and help me out. I have marked these areas with "Apolyton question".

    In addition to posting Richard's answers, I want us to put our heads together and share notes and ideas of our own regarding AI problems still in the game. I read through the second patch wishlist a couple of days ago, and made notes on the issues that I would like for us here at Apolyton to get together and work on, since they affect gameplay in general. There are also some questions that others here have asked me to ask Richard, and I have posted those below as well so that we can work on them too.

    NOTE: I want to restrict this thread to only those topics and questions raised in my initial posts here.

    I will make another thread for other questions that any of you might have, and perhaps Richard will answer them when he visits the forums.

    <font size=1 face=Arial color=444444>[This message has been edited by WesW (edited February 06, 2001).]</font>

  • #2
    Here are the letters:

    My answers are below, (see RM .
    1. Strategies.txt -

    1.1. Increasing the percent of workers dedicated to specialists
    increases the impact of PopAssignmentElements. If players are
    getting ahead of the AI by using specialists then this change
    should help, otherwise it might overbalance the AI toward
    specialists.

    Reply: Actually, I decreased the number of specialists used, since from my observations with my own cities, you are better off not using specialists unless you have to.

    1.2. By setting SliderElement Delta's to 0 you have told the AI to not
    try and optimize sliders. When a player has mostly small cities
    in the early game (or after getting beaten up) the AI can get a
    jump start. However, if you have found cases where the automatic
    slider settings are causing problems it might be worth creating
    specific strategic states when the sliders get optimized.

    WW: This change relates to changes I made in the govern.txt. I made
    the per-notch penalties for moving the sliders 4 and -6, since the
    1-point penalties were not enough to offset the advantages gained by
    maxing out the sliders. Now, it should be like Ctp1, where you only
    manipulated the sliders in cases of distress.

    RM: If you take a look at my post http://apolyton.net/forums/Forum35/HTML/000554.html#6)
    on apolyton you'll see a simple example of switching strategies based on a SLIC script. You can use the same basic concept to redefine the SliderElement deltas, but with one caveat. You must use the SetStrategicState (see 'Strategic State' section of ai-customization.shtml on Apolyton for why). You could change the slider settings of the base strategic state under specific conditions (like when a civ has only small cities for example).

    2. Goals.txt -

    2.1. You set the DistanceToHome bonus of the Seige goal to 250. This
    number might have more influence than you want since the actual
    bonus is computed by multiplying this value by the straight line
    distance to the center of the players empire. The
    DistanceToEnemy bonus is also computed this way, but all of the
    others are normalized so that no goal receives more than the
    specified value. For example, the enemy city most threatened by
    foreign units will recieve a bonus of 500, and the enemy city
    with half of that threat will recieve a bonus of 250. However,
    an enemy city 100 cells away will receive a bonus of 25,000
    compared to a city half as far will recieve a bonus of 12,500.
    Such an out of scale bonus swamps the other bonuses and generally
    leads to abnormal goal choices. Values of less than 10 are
    advised here unless it's negative. The Chokepoint goal is an
    exception since we really only want to guard chokepoints near
    home.

    Reply: Thanks for the explanation. Here I was trying to get the AIs to prioritize those enemy units/cities closest to its home, in hopes of encouraging the counter-attack ability I mentioned previously. I see now that I was just not figuring the numbers properly, and so I have changed the number from 250 to -10 for both the seige and attack modes. Thanks for seeing this, as it would have screwed up the game.

    2.2. GOAL_BOMBARD should not have TargetTypes of both City and
    AttackUnit/SpecialUnit. I can't remember exactly how the code
    will handle this in all cases. Better to create a new goal,
    perhaps GOAL_BOMBARD_ARMY that is identical to GOAL_BOMBARD, but
    replaces TargetType:City with TargetType:Army and SpecialUnit.
    You'll also have to add this new goal to all of the goal lists in
    strategies.txt. Seems you found an oversite here; good catch.

    WW: You can add new goals to the strategies.txt? I didn't think you
    could add things that weren't already defined in the exe.

    RM: Yes! You can add new goals. You'll create a new Goals.txt record and also add a GoalElement reference to it in each of the base strategies in the strategies.txt file. You could, for example, create two different attack goals with different force matching and priorities. The goals are created dynamically based on the attributes in goals.txt and referenced in strategies.txt by their record name in goals.txt.
    2.3. FYI, GOAL_SALLY is not used at all and should have been removed.

    WW: How about using this goal for the new Bombard_Army goal?

    RM: No need really, just create new goals with appropriate names and hook them up.

    3. Diplomacy.txt -
    3.1. Your changes look reasonable, but I might also suggest that
    creating specific diplomatic states is a good way to get leverage
    on this aspect of the game. You trigger diplomatic states in a
    similar way to how you trigger new strategic states. I can go
    into more detail later if you want.

    WW: I, and many others, would want more detail, when you get time.

    RM: A good general description is available in the 'Diplomatic State' section of ai-customization.shtml on Apolyton. However, the basic idea is that you can define your own diplomacy states (like DIPLOMACY_PROVOKE_WAR in diplomacy.txt) and trigger them to be loaded from the diplomacy.slc file by defining a handler for the NextDiplomaticState event.

    RM: You can also redefine specific diplomatic responses and new proposal triggers. The commented out handler in diplomacy.slc titled 'WantGoldAdvance_NewProposalEvent' is an example of how to make the AI consider sending a new proposal with high (1000) priority requesting a desired gold advance.

    RM: If you can phrase a change to how the AI responds to a specific new proposal then I can probably tell you how to add a new handler to diplomacy.slc that will implement that change. For example, if you think the AI should never accept a cease fire within 20 turns of getting into a war or something like that, it's pretty easy to do.

    1. WW: In the Force Matching section, does the AI include terrain and city
    improvement modifiers in its calculations of the matching values, or
    does it simply compare unit stats?

    RM: The defense and terrain modifiers for a target army or city are
    considered, but the terrain modifiers gained by a particular attacker
    are not considered because it's not obvious what those bonuses might
    be when the attacker gets close enough to attack.

    Reply: Thanks for the insight. I seems like a guessing game as to what to set the matching values to. However, since most attacks are made along roads, and roads usually are made through flat terrain (no defense value), then I think it would be wise to assume that the attacker will not have a bonus most of the time.

    2. WW: Next, please take a look at my changes to the unit build lists
    categories in the Siege, Attack and Defense strategy modes. What I
    have done is to let the AI build by using the standard lists in times
    of peace, and then shift to specialty lists in times of war. I did
    this in the hopes of tailoring the units the AI chooses to build to
    better match the situation at that time. This resulted in tripling the
    total amount of unit build lists that are listed in the
    unitbuildlist.txt. Do you see any problems with doing this?

    That looks fine. Good idea!

    WW: Finally, would you mind if I posted these letters on the forums?
    I would delete your email address, for obvious reasons, and I will
    understand if you would rather not do it, or wait until we can covered
    more things. Posting these will inform the other mod-makers, and
    probably lead to good questions that I have not thought of.

    RM: I have no objection to you posting my comments, but I don't want to raise expectations too high. If you want to triage what questions you think are most important to answer, that would be very helpful too. I'll be happy to do what I can to answer any questions I can.
    Best wishes,
    -- Richard

    SECOND LETTER:

    Wes,
    The remainder of my answers to your questions are below:

    WW: Then come the goals settings. I chose 600K as the critical value for the main goals. Settings above 600K are what I want the AIs to prefer in a given situation, and those below 600K should only be chosen if unable to accomplish the higher priorities. I chose 5K as the standard difference between goals. Do you see any problems with these settings?

    RM: I think the 5K skip should be ok. The priorities set in the
    strategies.txt file specify a base. All of the bonuses specified in
    the Goals.txt file are applied to this base priority to come up with
    what we call the goals raw priority. You'll notice that all of the
    computations needed to compute the bonuses refer to the goal and not
    to which particular army is executing the goal. The raw priority is
    used to do a first pass sort of the goals which is used when applying
    the MaxEval.

    RM: All goals of a particular type are sorted based on the raw priority
    and only the top MaxEval are matched to the valid armies for that goal
    (ie. Attack goal only matches with armies that contain units that
    CanAttack). This is purely an efficiency thing, so you can always
    increase the MaxEval if you don't care about performance. Be warned
    though that increasing this number can seriously impact turn speed for
    goals like attack that are executable by many different armies.

    RM: For each army matched to a particular goal, a final utility is
    computed by taking the raw priority of the goal and applying the
    DistanceModifierFactor (from strategies.txt) multipied by the distance
    in number of turns the army is from the target of the goal (as the
    crow flies, not path length). The number of turns is an approximation
    that takes into account how many cells a given unit type can move each
    turn. We call the final value the Matching Value for the goal-army
    match pair. All matches for all goals are sorted into a big list and
    are executed from highest to lowest. Armies can be matched to
    multiple goals, but if they have been executed by a higher matching
    goal, they won't be executed for any other lower matches that might
    exist.

    Apolyton question: I am not sure exactly what Richard means with that last sentence, though his example a little ways below with the 5 armies did clear some things up for me.

    RM: The reason I say 5K should be ok is that with such a value, goals
    will execute mostly based on the raw priorities, but will still use
    armies that are far for the action for other things. The MaxExec
    parameter from strategies.txt will also ensure that not all armies are
    doing the same thing.

    WW: Ideally, I want an AI that will shift from one goal
    to another if an opportunity presents itself, or if the strength of
    the opponent changes suddenly. What I don't want is an AI that is
    indecisive, and ends up moving back and forth but never accomplishing
    anything. An example of the ideal would be an AI that would
    counter-attack and re-take a fallen city if it had a stack strong
    enough to defeat the opponent, who is often weakened by his assault.

    RM: The AI should take advantage of opportunities as you describe, but
    there are many factors that come into play. The best way to tune for
    this situation is to create some small test cases using the scenario
    editor. Create a reproducable situation where the human can take an
    AI city, but lose enough units that the AI should retake the city. By
    tweaking the force matching and goal priorities you should be able to
    improve the AI's ability.

    Apolyton question: This next comment below is a big one, imo.

    RM: Another potential problem that may occur is that when the AI units
    are tasked, they retain those orders until interrupted or until
    certain specific events occur to clear them. You might consider
    writing a new slic event handler triggered by the CaptureCity event
    that calls the ClearOrder function all on all nearby armies. That
    will make sure that they consider attacking the recently captured city
    rather than what they might have been tasked to do last turn. Joe's
    documentation on events and on the ClearOrder function should make it
    clear how to do a brute force version of this that clears all orders.
    The downside to clearing all orders every turn is, again, performance.
    I considered on the highest difficulty level always clearing orders
    every few turns, but never got a chance to implement this.

    Apolyton question: Locutus, I believe, had asked before about clearing orders, and I think the above suggests that this is a good idea. What I would want is a trigger to clear all unit orders say, every 3 turns, and another trigger to clear orders whenever an AI civ loses one of its cities. If this is hard to do, then a trigger which makes the seige goal the highest priority whenever a city is lost may work just as well.

    WW: Also, would you give me a brief explanation of what triggers the
    goals the AI chooses in the game. I *think* I understand their
    individual effects pretty well, but I still don't really know what
    determines their choices in the first place. I am sure motivations and
    desires enters into this, but how does it decide between attack, siege
    and harass, for example.

    RM: In your example, say you've got 5 armies and 2 of each goal
    (attack, siege and harass). Matches will be made between each army
    and goal (5 * 2 * 3 = 30 matches). If the attack goal has the highest
    raw priority, then all 5 armies will execute attack goals. However,
    if the MaxExec for attack is set to 2, then only the 2 highest attack
    goals will get armies (as many as are needed to force match).
    Assuming one attack goal needs 1 army, and the other need 2 armies,
    then you'll have 3 armies left. Those will match to the next highest
    goal, which might be seige. If the highest priority seige goal needs
    more attack strength than the 3 armies you have, then the goal
    will fail. On the next match cycle (there are 6 total match cycles),
    the failed goal won't be considered, so the 3 armies will be assigned
    to the next highest priority seige goal. If none of the siege goals
    can be satisfied by the 3 armies, then the next highest matches might
    be to harass goals which need very little matching strength so all
    three armies might go to different harass goals.

    Apolyton question: I start getting a little confused by the rest of his answer below. If someone could expound upon this, I would appreciate it.

    You might see here
    another potential source of problems. If there are many seige goals
    that require more units than we have the system could run out of match
    cycles before any valid goals are found. This is a trade off, and I
    wish I had made the match cycles a parameter that could be changed.
    But it can't be, so don't ask me. The best way to avoid this is to
    make sure the MaxEval for goals that might often need more units than
    you have to be low, like 2 or 3. However, if siege is your highest
    priority, and you don't have enough units to do a successful seige,
    the best bet is to not do anything until you build up your strength.

    Apolyton question: I am a little confused by the recommendation to set things at 2 or 3. In the original strategies.txt, the MaxEval and MaxExec are both 25 for the Attack and Harass goals, and around 4 for seige and bombard. Does this mean that the original settings are way off, or am I mis-interpreting Richard's comments?

    WW: On the Start strategies, are they determined by personality as far
    as Careful or Aggressive? Also, how many turns into the game do they
    stay in effect?

    RM: Yes, the start strategies are determined by the parameters in the
    personalities.txt file. They stay in effect for the whole game, but
    you can write triggers that trump them later in the game.

    Apolyton question: I definitely need a trigger to disable the start strategies after about 125 turns or so.

    WW: On the Explore strategies, what is the difference between Far and
    Wide, and what setting determines which of these is used?

    RM: In the personalities.txt file (again) each personality has a
    Exploration: setting. If Exploration: Minimal is set, then
    STRATEGY_EXPLORE_NEAR is used, Exploration: Medium loads
    STRATEGY_EXPLORE_FAR and STRATEGY_EXPLORE_WIDE is loaded by
    Exploration: Wide. If the Exploration: Wide or Maximum are set, then
    STRATEGY_AGRESSIVE_START is used, otherwise STRATEGY_CAREFUL_START is
    loaded, btw.

    WW: In the Improvement List Production, I added commerce improvements
    to that list, and filled out the improvelist.txt to include all the
    individual terrain improvements that I wanted the AI to consider. I
    restricted the commerce TIs to terrains which could not support farms
    or mines, so reduce possible conflicts. Do you see any problems with
    this?

    RM: Your changes look fine. My one caveat is that there is some logic
    that tries to build goalgold improvements preferentially only on cells
    that produce gold and not food or production. The logic looks at the
    food rank of a cell, and if it's low, looks at the production rank, if
    that is low, then it looks at the gold rank, if that's reasonably
    high, it tries to build a gold improvement. In retrospect, the logic
    should have done the check for whether a food/production improvement
    was even possible before considering food/production improvements.

    Apolyton question: We will need to keep track of what the AI does in this area during the beta testing.

    WW: In the Goal Defend element, would it be wise to up the maxeval and
    max execute numbers from 2 and 1 to 4 and 2, respectively?

    RM: For the Goal Defend, it's evaluating 2 defend goals *per city* and
    executing one per city. They could actually be MaxEval 1 per city and
    MaxExec 1 per city since you never have more than one defend goal per
    city anyway. The important thing to note is the PerCity tag at the
    end of the line.

    WW: I changed the fear and desire motivations for all the AI
    types. Looking at the ones for the Scientist, for example, do you see
    any problems with them? One thing I wanted to address was the fact
    that a militarily stronger AI would often not attack the human,
    presumably because the human was strong scientifically or financially.

    Apolyton question: This answer is very important, imo.

    RM: The motivations are only used for computing which new proposals an
    AI should make, so I don't think this gets at what you want. If
    you want the AI to ignore economic strength when determing if it
    should want to be at way, that's tougher. However, if you force the
    AI to declare war and make sure the diplomatic state for the AI (in
    diplomacy.txt) will refuse peace that should do what you want. So how
    do you foce the AI to declare war? Sigh, I have a function to do
    this, but I forgot to expose it via SLIC. However, there is a fun way
    you can do this. Create a new goal (maybe called
    GOAL_PROVOCATION) that looks a lot like an attack goal, but in which
    the TargetOwner: is ColdEnemy rather than HotEnemy. This will cause
    the AI to preemptively attack, and once at war it will stay at war as
    long as it never makes or accepts a ceasefire. You'll have to add the
    goal to everyone, but only set it to have maxeval > 0 for beligerent
    AI. You could also swap in a strategy specifically that enables this
    goal only when the AI has military superiority.

    Apolyton question: I would like a trigger to swap in a strategy that enables this goal when they have military superiority. I will set the MaxEval > 0 for Militaristic and Ecotopian AIs.

    WW: In the build list sequences, I have made many changes to the
    default settings. Please look these over for the Scientist, for
    example, and let me know if you see any mistakes I made.

    RM: In general these look fine to me, but Dave White (or lead designer)
    might have comments about your choices, I'll cc' him on this too.

    WW: Finally, at the bottom of the file, there is a list of Defense
    Strategies. What triggers these? I know nothing about when they come
    into effect, or how long they last.

    RM: At the beginning of each turn, the Maximum Threat for an AI is
    computed, and as the threat increases, the minimum garrison in each
    city increases. Essentially this is a way to make sure the AI
    protects its cities with more units when things get more dangereous
    later in the game. If you add a new strategic state that is triggered
    every turn (with a priority > 1000 or so) which redefines the garrison
    counts, then you can use your own system. I forget the actual threat
    levels and don't have the code available right now to check when each
    level is invoked.

    I hope this helps. I look forward to seeing what new and improved AI
    strategies you and others will create!
    -- Richard

    [This message has been edited by WesW (edited February 08, 2001).]
    [This message has been edited by WesW (edited February 10, 2001).]

    Comment


    • #3
      Here are a couple of questions that Harlan and Locutus have asked before, and that I would like for us to work on.

      > > The responses to your questions brought a couple of questions into my mind.
      > > First, what is the scale of trust and attitude towards other civs, and second,
      how can one check to see exactly where the other civs are on these scales?

      But at any given time, there are concrete numbers for
      each civ, not just general tendencies. For instance,
      Civ2 might have a trust of 153 and attitude of 203 on
      turn 5. So my questions are what are the ceilings and
      benchmarks for those numbers? For instance, maybe you
      can have a max of 1000 attitude, and anything over 800
      means the AI wants to have peace with you. But who
      can say with the info we've got? We're just groping
      around in the dark. And my second question is how to
      know exactly where each civ stands at any given time
      on all of these. Instead of getting a vague notion
      that a civ is "wary" of you, as a scenario maker I'd
      want to know what the concrete number was. In the
      pre-release, there was a debug version of the game
      that had extra tools allowing one to find out stuff
      like this, but now they're gone.

      Here's a pipedream: maybe he could send us the final
      debug version of the game, if he still has it?

      Harlan

      I have a question for Richard, in case you think feel like asking (it's no
      problem of course if you want to edit it so it seems to come from you or
      whatever).

      I've been studying AI movement behaviour for Harlan's Alexander scenario.
      During this testing I noticed that the AI makes movepaths to send units from
      one point to another, just like a human player. But unlike human players the
      AI doesn't seem to have the option to clear that movepath before the stack
      reaches its destination and give the units another order if the situation
      asks for it (tell me if I'm wrong about this though). The orders only seem
      to be cleared when a stack encounters an enemy stack or something like that,
      just as with human stacks.

      Do you have any idea of what the effect would be if I used SLIC to clear
      every stacks orders every turn? As I see it, this would force the AI to
      re-analyze the situation every turn and give all its units new orders every
      turn and thus all AI actions would be based on the latest information. I
      realize this will probably make the AI slower but if the AI also becomes
      smarter then this might be worth it. Would the AI actually become smarter?
      Or would it just have less time to think over what actions to take and make
      dumber decisions? Or would it have little effect at all? Are there any side
      effects I may be overlooking?

      Do you have any wise words on this or is your guess as good as any? I'm not
      too much of an AI expert so I hope I'm not making a total fool out of myself


      Wouter

      Comment


      • #4
        Here are a couple of additional problems that I would like for us to work on. I gleaned these from the 2nd patch wishlist.

        1)The AI does not appear to know how to use Fighters correctly, often letting them run out of fuel and crash. Otoh, I have seen it use Bombers correctly, and return them to base. I need a trigger to make the AIs return their planes to the nearest city, airbase or Carrier when they have used up half their fuel. There is already something in the game which changes the paths color from green to yellow, I believe, when this fuel point is reached, so hopefully a trigger can be made which is tied to this point as well.

        2)I have changed several wonders in the game to give improvements in every city. I need a trigger that removes the option to build improvements if a civ has a wonder that grants that improvement to every city. This has been discussed before, but I don't recall the options to disable this "feature".

        Comment


        • #5
          quote:


          WW: I changed the fear and desire motivations for all the AI
          types. Looking at the ones for the Scientist, for example, do you see
          any problems with them? One thing I wanted to address was the fact
          that a militarily stronger AI would often not attack the human,
          presumably because the human was strong scientifically or financially.

          Apolyton question: This answer is very important, imo.

          RM: The motivations are only used for computing which new proposals an
          AI should make, so I don't think this gets at what you want. If
          you want the AI to ignore economic strength when determing if it
          should want to be at way, that's tougher. However, if you force the
          AI to declare war and make sure the diplomatic state for the AI (in
          diplomacy.txt) will refuse peace that should do what you want. So how
          do you foce the AI to declare war? Sigh, I have a function to do
          this, but I forgot to expose it via SLIC. However, there is a fun way
          you can do this. Create a new goal (maybe called
          GOAL_PROVOCATION) that looks a lot like an attack goal, but in which
          the TargetOwner: is ColdEnemy rather than HotEnemy. This will cause
          the AI to preemptively attack, and once at war it will stay at war as
          long as it never makes or accepts a ceasefire. You'll have to add the
          goal to everyone, but only set it to have maxeval > 0 for beligerent
          AI. You could also swap in a strategy specifically that enables this
          goal only when the AI has military superiority.



          Wes:
          Through working with the diplomacy mod I found that you can totally bypass the motivation priorities in strategies.txt. This may work as a workaround for you. (Reminds me of the comments in tut2_msg.slc) For example: if you want to SLIC your own motivations, you make the priorities in the ConsiderNewProposal statements higher than the ones in the motivation ratings in strategies.txt. I can't remember where I read it, but the AI will only consider the 3 highest priority things.

          IE:
          I SLIC some ConsiderNewProposal statements that force the following:
          DeclareWar priority = 1500
          DemandAdvance prio = 1400
          DemandGold prio = 1300

          Motivations set the following in strategies.txt:
          CeaseFire prio = 1100
          OfferGold prio = 1000
          MakeAgreement prio = 900

          The AI will only consider the three highest prios which are DeclareWar, DemandAdvance and DemandGold.

          Hope this helps in the proposal priority settings.

          ------------------
          Author of Diplomod. The mod to fix diplomacy.

          Rommell to a sub-commander outside Tobruk: "Those Australians are in there somewhere. But where? Let's advance and wait till they shoot, then shoot back."

          Comment


          • #6
            quote:

            Originally posted by WesW on 02-06-2001 04:34 PM

            2)I have changed several wonders in the game to give improvements in every city. I need a trigger that removes the option to build improvements if a civ has a wonder that grants that improvement to every city. This has been discussed before, but I don't recall the options to disable this "feature".


            If possible, have the trigger also cause the AI to sell any existing redundant buildings. I know some people have expressed an interest in keeping this feature, so an alternative would be not to remove the possibility of building it but somehow distinquish it as redundant such as a colored font or asterick.

            ------------------
            History is written by the victor.

            Comment


            • #7
              AW:
              Maybe not so much as 'sell' these improvs as don't build anymore. It'll be a timewaste for the AI to sell these improvs and then find someone conquers the city with the wonder, or when the wonder becomes redundant. The AI will just have to rebuild them all. Just a suggestion.

              ------------------
              Author of Diplomod. The mod to fix diplomacy.

              Rommell to a sub-commander outside Tobruk: "Those Australians are in there somewhere. But where? Let's advance and wait till they shoot, then shoot back."

              Comment


              • #8
                I've been studying the AI files and the all available info on AI on Apolyton (including Richard's emails) and I think I'm beginning to understand how the AI works. In this post I'll try to parafrase Richard's explanation since putting things on paper like this made things a lot more comprehensible for me and hopefully it will help others in undertanding this part of the AI as well. There's probably at least a few things I misunderstood or overlooked or whatever (some things I even had to guess about), so it's quite possible some of this is incorrect. If anyone (esp. Richard himself) can correct me where I'm wrong, that would be very helpful.

                I'll explain this with an example. Let's assume this is the situation in the game at some point: there are 10 armies capable of attack (A1 to A10), only 3 goal types are defined (attack, siege, harass) and 3 goals of each type are present (a1, a2, a3, s1, s2, s3, h1, h2, h3). These goals represent specific actions, like Attack army near London (this might be a1) or Siege Liverpool (this might be s3). The various values I'm using are all based on strategies.txt and goals.txt as they were in the original game. I'm not saying these exact numbers can actually occur in a real game, most of them were chosen pretty much at random (without completely loosing track of what would be realistic though), but something similar to this might actually occur in a real game.

                In original game priorities are following:

                Attack: 405k (MaxEval 25, MaxExec 25)
                Siege: 405k (MaxEval 20, MaxExec 4)
                Harass: 500 (MaxEval 3, MaxExec 1)

                For all goals in the game raw priorities are determined, meaning that the values of goals.txt are added to the base values in strategies.txt in the correct proportions. The formula looks something like this:

                RawPriority(goal) = BasePriority(goal) + SUM(Priority(bonus, goal) * Mul) for all bonuses, with Mul >= 0 and Mul <= 1
                (sometimes Mul is just 1 or 0, sometimes something in between, depending on what type of bonus it is - flat or scaled)

                This results in a big list that is sorted on raw priority. It might look something like this:

                Goal Raw Priority
                s1 405199
                a1 405187
                a2 405134
                s2 405084
                a3 405078
                s3 405058
                h1 820
                h2 712
                h3 634

                Since s1, a Siege goal, is the highest goal, all Siege goals will be evaluated first. Then all Attack goals will follow (since after Siege it is the highest goal-type on the list) and if needed the Harass goals will follow as last. So even though a1 has a higher raw priority than s2, s2 will be evaluated before a1. This seems like a rather odd thing to me, but that's what I understand from reading Richard's explanations (I read them over and over and over again but I can't make anything else of it).

                Now the MaxEval number is applied to a sorted list of all Siege goals. Since MaxEval is 20 only the 20 goals with the highest priority will be kept and the rest of the list will simply be thrown away and not looked at anymore for this particular turn. In this case there are only 3 Siege goals so the list looks like this:

                goal raw priority
                s1 405199
                s2 405084
                s3 405058

                Now all these goals need to be matched with all valid armies, all 10 armies in this case:

                (s1, A1)
                (s1, A2)
                (s1, A3)
                .
                .
                .
                (s1, A10)
                (s2, A1)
                (s2, A2)
                .
                .
                .
                (s2, A10)
                (s3, A1)
                .
                .
                .
                (s3, A10)


                So 10 armies * 3 goals = 30 matches.

                Now the Matching Value for all these armies needs to be determined. So for all these 30 matches, do the following calculation (and once that's done sort the list again, on Matching Value this time):

                MatchingValue(goal, army) = RawPriority(goal) + DistanceModifierFactor * NumberOfTurnsFromTarget(army, goal.location)

                RawPriority has been calculated and DistanceModifierFactor is -50 in strategies.txt and the game will use some (to us unknown) algorithm to find the NumberOfTurnsFromTarger, so the Matching Value can be calculated.

                Let's say army A1 is 10 turns away from goal s1. In that case the formula looks like this:

                MatchingValue(s1, A1) = 405199 + (-50 * 10) = 404699

                The entire list might now look like this:

                goal/army Matching Value
                (s1, A3) 405049
                (s2, A1) 404984
                (s1, A7) 404949
                (s3, A1) 404908
                (s3, A5) 404858
                .
                .
                .
                (s1, A1) 404699
                .
                .
                .
                (s1, A9) 403799

                Now all Siege goals are executed by the armies with the highest Matching Value. The only catch is that sometimes the Force Matching numbers of this army aren't sufficient. In that case other armies need to attack that same goal as well. The number of armies that will attack is the number of armies needed to match the Force Matching numbers. So if some goal requires 40 ranged attack points to Force Match and A1 and A2 are the armies with the highest priorities for this goal and A1 has a 23 ranged attack points and A2 has 18 points, then both A1 and A2 will attack these goals since only one of the armies doesn't have the required amount of ranged attack points and thus doesn't Force Match (this is presuming all other values match as well).

                Since s1 is the highest goal on the list, as many armies from the list will be selected to Siege that particular goal as needed to match the Force Matching numbers (hereby the armies with the highest Matching Values are always picked). Let's say that in this case 2 armies will be enough. In that case A3 and A7 will Siege s1 (since those are the two armies with the highest Matching Values for goal s1). The next goal might need only 1 army, so A1 will Siege s2. Let's say s3 needs one army as well. Normally A1 would be the army to Siege it, but since it already Sieges s2, it cannot Siege s3 as well and will be skipped. The army with the next highest Matching Value for Sieging s3 is A5, so that army will do the job. No more than MaxExec goals can be executed but since there are only 3 goals this doesn't cause a problem in our case. The armies that aren't sieging (A2, A4, A6, A8, A9 and A10), will be available to Attack and if necessary to Harass (for both of which the whole process starting with making a list of all goals of those types of goals starts all over again). Let's say A2 and A6 Attack a1 and A4 and A9 Attack a2.

                This leaves only A8 and A10 to attack a3. Let's assume however that they don't Force Match. Let's say 25 attack points are required to attack but A8 only has 10 attack points and A10 only 12. In this case a3 will be fail. Now all the goals need to be evaluated a second time to give all armies a goal. In this second pass s1, s2, s3, a1 and a2 already have enough armies assigned to them and a3 has been disabled, so the game will try to use A8 and A10 to Attack a4, should it have existed. If that would have failed as well a5 would have been evaluated, etc. This process can repeat itself 6 times, so if there are more than 6 Attack goals in a row which can't match the Force Matching numbers, no (additional) army will Attack, even if goal number 7 Force Matches easily. If this happens, the units not yet assigned to a goal won't get any goal assigned to them and do nothing for at least one turn (maybe they'll fortify). Another option might be that they'll still be available for other goals, like Harassing, but if that is the case I don't quite see why Richard presents this as a problem (it's not ideal but not really a problem either, if you ask me).
                Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                Comment


                • #9
                  quote:


                  Apolyton question: I am not sure exactly what Richard means with that last sentence, though his example a little ways below with the 5 armies did clear some things up for me.



                  What he means is that armies are assigned to all goals for which they are valid, but once it has been determined they will execute a certain goal, they won't be assigned to execute any other goal anymore. One army can never execute more than one goal: the goal for which they have the highest Matching Value and for which no other armies with a higher Matching Value are available (unless those armies don't Force Match the goal of course).

                  quote:


                  Apolyton question: Locutus, I believe, had asked before about clearing orders, and I think the above suggests that this is a good idea. What I would want is a trigger to clear all unit orders say, every 3 turns, and another trigger to clear orders whenever an AI civ loses one of its cities. If this is hard to do, then a trigger which makes the seige goal the highest priority whenever a city is lost may work just as well.



                  Will look into that, shouldn't be too hard to code.

                  quote:


                  Apolyton question: I start getting a little confused by the rest of his answer below. If someone could expound upon this, I would appreciate it.
                  (...)
                  Apolyton question: I am a little confused by the recommendation to set things at 2 or 3. In the original strategies.txt, the MaxEval and MaxExec are both 25 for the Attack and Harass goals, and around 4 for seige and bombard. Does this mean that the original settings are way off, or am I mis-interpreting Richard's comments?



                  As I explained above, if there are too many goals with high Force Match numbers and the available armies don't match to any of these goals, not all units will be assigned to goals and not all goals will get armies assigned to them, even though they may have very low Force Matching numbers.

                  Richard advises to keep MaxEval low for those goals that require high Force Matching numbers and for which little units will be available (in other words, goals that have low priority). This situation will generally only occur when you have a fairly small army and the units in your army are fighting an enemy that is stacking very well or that is far ahead of them in tech. On top of that, Siege and Bombard have fairly high priorities. I suspect that under normal circumstances it will be fairly unlikely that the AI will run out of matchin cycles for goals like Siege and Bombard and that low MaxEval numbers aren't needed. With other goals, you might have to be more careful (though I wouldn't know off the top of my head which ones) and assign lower MaxEval numbers.

                  quote:


                  Apolyton question: I definitely need a trigger to disable the start strategies after about 125 turns or so.



                  Sure, if you write strategies to replace them, it's a piece of cake to write the SLIC code for this.

                  quote:


                  Apolyton question: I would like a trigger to swap in a strategy that enables this goal when they have military superiority. I will set the MaxEval > 0 for Militaristic and Ecotopian AIs.



                  Define military superiority... More units? How many more? Better technology? How much better? Any other properties to take into acount? Once I know exactly what you want, it should be fairly simple to code.

                  quote:


                  1)The AI does not appear to know how to use Fighters correctly, often letting them run out of fuel and crash. Otoh, I have seen it use Bombers correctly, and return them to base. I need a trigger to make the AIs return their planes to the nearest city, airbase or Carrier when they have used up half their fuel. There is already something in the game which changes the paths color from green to yellow, I believe, when this fuel point is reached, so hopefully a trigger can be made which is tied to this point as well.



                  I think I can do this. There's no pre-made code to detect when a unit is half-way, but by playing around with values from Units.txt, this probably won't be necessary either.

                  quote:


                  2)I have changed several wonders in the game to give improvements in every city. I need a trigger that removes the option to build improvements if a civ has a wonder that grants that improvement to every city. This has been discussed before, but I don't recall the options to disable this "feature".



                  Come to think of it, this should actually be fairly simple.

                  Wouter
                  Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                  Comment


                  • #10
                    FIrst of all, I want to congratulate Wouter for figuring out the AI routines, if he indeed was correct. I got cross-eyed about 75% of the way through just from trying to read the explanation. And the explanation was as simple as it could be made. Anyway, responding to Wouter's remarks...

                    Apolyton question: Locutus, I believe, had asked before about clearing orders, and I think the above suggests that this is a good idea. What I would want is a trigger to clear all unit orders say, every 3 turns, and another trigger to clear orders whenever an AI civ loses one of its cities. If this is hard to do, then a trigger which makes the seige goal the highest priority whenever a city is lost may work just as well.

                    Will look into that, shouldn't be too hard to code.

                    WesW: Ok, good.

                    Apolyton question: I definitely need a trigger to disable the start strategies after about 125 turns or so.

                    Sure, if you write strategies to replace them, it's a piece of cake to write the SLIC code for this.

                    WesW: I just want the AI to use it's default personality strategy when at peace, and the three war strategies when in that state.
                    You see, I have added some things to the Start strategies that should help the AIs at the start of the game, but these settings will interfere with the other strategies if they are in play for the entire game.

                    Apolyton question: I would like a trigger to swap in a strategy that enables this goal when they have military superiority. I will set the MaxEval > 0 for Militaristic and Ecotopian AIs.

                    Define military superiority... More units? How many more? Better technology? How much better? Any other properties to take into acount? Once I know exactly what you want, it should be fairly simple to code.

                    WesW: I thought that there were settings in the game already to determine relative military strengths. Doesn't the AI use these in deciding whether to declare war, or what war strategy to use?

                    1)The AI does not appear to know how to use Fighters correctly, often letting them run out of fuel and crash. Otoh, I have seen it use Bombers correctly, and return them to base. I need a trigger to make the AIs return their planes to the nearest city, airbase or Carrier when they have used up half their fuel. There is already something in the game which changes the paths color from green to yellow, I believe, when this fuel point is reached, so hopefully a trigger can be made which is tied to this point as well.

                    I think I can do this. There's no pre-made code to detect when a unit is half-way, but by playing around with values from Units.txt, this probably won't be necessary either.

                    WesW: Fixing this bug will be a significant improvement to the game.

                    2)I have changed several wonders in the game to give improvements in every city. I need a trigger that removes the option to build improvements if a civ has a wonder that grants that improvement to every city. This has been discussed before, but I don't recall the options to disable this "feature".

                    Come to think of it, this should actually be fairly simple.

                    WesW: As usual, I was thinking of the AI when suggesting this trigger, to answer some of the thoughts posed by AW prior to Wouter's posts.
                    As far as I know, the AIs will use their normal building queues whether or not they have a wonder which grants said building's effect. Since some of the Wonders grant expensive buildings like Forcefields, they need to be kept from wasting resources on unneeded buildings.

                    Btw, I can't wait until we get into the Unit-Wonders.

                    Wes

                    Comment


                    • #11
                      I have edited the first letter from Richard to include some important things that I had deleted in my reply to him. Those of you interested should scan that letter again and take note of these new sections.

                      Comment


                      • #12
                        So it should also be possible to force the barbarians to use the barbarian strategy every turn even if they want to become civilized?

                        I'm with Wes about the the fuzzy eyes. I thought I understood how changing the maxeval and maxexec affects game play even tho I didnt know the exact details behind it. But the defend example has thrown me. Say the AI has a city that due to whatever reason is lightly defended. I'm moving towards it with say 5 units. Between me and the city are 3 stacks (4,2,5 units). Is Richard saying that only one of those stacks will move to defend the city?

                        ------------------
                        History is written by the victor.

                        Comment


                        • #13
                          Glad I could be of help...

                          No AW, MaxEval and MaxExec 1 means that 1 goal per city will be defended, it doesn't mean 1 army per city will be used to Defend, armies and goals are completely unrelated. In this particular case, goals represent the cities to be defended. Since the only valid goals for Defend are your own cities, Defend will be evaluated and executed for all your cities: for every city you have, 1 goal will be evaluated&executed, i.o.w. for every city you have, 1 city will be defended, hence all your cities are defended. If the defense of this city only requires 1 additional army to Force Match, 1 army will go back to the city to defend. If it requires all 3 armies to Force Match, all three armies will Defend the city. As many armies are sent in as is necessary to Force Match.
                          [This message has been edited by Locutus (edited February 09, 2001).]
                          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                          Comment


                          • #14
                            quote:

                            Originally posted by WesW on 02-08-2001 05:25 PM
                            WesW: I just want the AI to use it's default personality strategy when at peace, and the three war strategies when in that state.
                            You see, I have added some things to the Start strategies that should help the AIs at the start of the game, but these settings will interfere with the other strategies if they are in play for the entire game.


                            Oh, wait a minute. I misunderstood what you meant by Start strategies, but now I get it. I think reloading the standard personality strategy (with SetStrategicState) after 125 turns or whenever you want will undo the changes of the Start strategies. I think this can be done.

                            quote:


                            WesW: I thought that there were settings in the game already to determine relative military strengths. Doesn't the AI use these in deciding whether to declare war, or what war strategy to use?



                            You're right. MilitaryRank can be used for this. I didn't think of this yet, it's hardly ever useful for anything but it's perfect now. Should be fairly simple then.

                            quote:


                            Btw, I can't wait until we get into the Unit-Wonders.



                            If you mean that you're waiting for me to send you the code for it, I did that weeks ago. If you meant anything else, ignore this paragraph
                            Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                            Comment


                            • #15
                              That sounds great, Wouter. Maybe we can be rid of the most annoying AI inadequacies right from the start of the beta if you can get all these in to me in the next few days.

                              As to the unit-wonders, I have a much more detailed plan for them than what I out-lined a few weeks ago. Once we get everything else working in the mod, I will start a thread about these. I think everyone is going to love this feature once they get the details laid out before them.

                              Comment

                              Working...
                              X