Results 1 to 4 of 4

Thread: "Best Friends Forever" AI Code

  1. #1
    EBII Council Senior Member Kull's Avatar
    Join Date
    Jan 2003
    Location
    El Paso, TX
    Posts
    13,502

    Default "Best Friends Forever" AI Code

    In the interest of improving AI play for other M2TW mods, here's a synopsis of the "Best Friends Forever" AI code and why it's a problem:

    Most of the playtesters were reporting a rapid increase in positive relationships among all the AI factions, and even toward the human player. So I ran a series of fixed tests using Pontos as the baseline human faction, and establishing relationships with two of the largest factions (Ptolemaioi & Seleukids) and one of the smallest (Pergamon). Extensive testing pointed to the descr_faction_standing.txt file, and specifically three pieces of code within it. The last test looked just at those (everything else was pulled out):

    - Difficulty setting is at "Medium":
    - Using XAI (descr_campaign_ai_db.xml)
    - Using a "partial code" descr_faction_standing.txt file (Code sections 89, 90, & 91)
    - Ran the same 10 turn Pontos test.

    Result? All three factions progressed to Outstanding in only six turns:
    Attachment 12153

    Here is the offending code:

    Code:
    ; Make factions try and band up with smaller factions
    ;------------------------------------------
    Trigger 0089_Update_Band_Together1
        WhenToTest FactionTurnStart
    
        Condition FactionHasRank
            and FactionScorePercent overall < 30
            and FactionScoreRank overall > 3
    
        FactionStanding exclude_factions { } normalise 1.0 40
    
    ;------------------------------------------
    Trigger 0090_Update_Band_Together2
        WhenToTest FactionTurnStart
    
        Condition FactionHasRank
            and FactionScorePercent overall < 20
            and FactionScoreRank overall > 4
    
        FactionStanding exclude_factions { } normalise 1.0 25
    
    ;------------------------------------------
    Trigger 0091_Update_BandTogether3
        WhenToTest FactionTurnStart
    
        Condition FactionHasRank
            and FactionScorePercent overall < 10
            and FactionScoreRank overall > 5
    
        FactionStanding exclude_factions { } normalise 1.0 10
    So clearly the code is broken. In addition to the ridiculous pace of improvement, if the idea is for small factions to "band together", then why would relations improve between Pontos and the Seleukids/Ptolemaioi? They are the biggest factions out there. Doing some research, this code is shared (as-is) by both the Savage AI and Lusted AI. The code used by XAI is different, but not significantly so:

    Code:
    ;------------------------------------------
    Trigger 0089_Update_Band_Together1
        WhenToTest FactionTurnStart
    
        Condition FactionHasRank
            and FactionScorePercent overall < 40
            and FactionScoreRank overall > 8
    
        FactionStanding exclude_factions { } normalise 1.0 60
    
    ;------------------------------------------
    Trigger 0090_Update_Band_Together2
        WhenToTest FactionTurnStart
    
        Condition FactionHasRank
            and FactionScorePercent overall < 30
            and FactionScoreRank overall > 10
    
        FactionStanding exclude_factions { } normalise 1.0 45
    
    ;------------------------------------------
    Trigger 0091_Update_BandTogether3
        WhenToTest FactionTurnStart
    
        Condition FactionHasRank
            and FactionScorePercent overall < 20
            and FactionScoreRank overall > 12
    
        FactionStanding exclude_factions { } normalise 1.0 30
    Overall, the effect of this code is extremely powerful. Consider the parameters below:

    Code:
    ; faction standing parameters
    ; ===========================
    
    ; initialisation parameters
    
    min_faction_standing	-1.0
    max_faction_standing	1.0
    
    relations_improved_thresholds
    {
        0.25
        0.4
        0.6
    }
    At game start, Pontos has a relationship of "0" with Pergamon, Seleukids & Ptolemaioi. Strip out all the other code so we are only testing the "Band Together" code, and by turn 3, Pontos was at "Good" relations with all. That means the relationship had improved to:
    >.25 but <.4

    By turn 4 it was "Very Good":
    >.4 but <.6

    By turn 6 it was "Outstanding":
    >.6

    Which is basically +.1 EVERY turn. Even with the most abysmal relationships (-1.0), it will only take 20 turns to make them BFFs. That rate of improvement could be reduced by altering the formulas in several ways (as we saw with the XAI code - it took 13 turns to reach "Outstanding"), but that's not the real issue. The idea of small factions banding together is not a bad one, but these formulas are not correct for that purpose, so we pulled it completely out of EB2.
    Last edited by Kull; 02-11-2014 at 03:29.
    "Numidia Delenda Est!"

  2. #2

    Default Re: "Best Friends Forever" AI Code

    you could base it on relations like no relation 0 neighbours but not talking minus 0.01 per turn trade agreament increase 0.02 per turn alliance if yes the points double for good and bad

    you are at war with an enemy who also shares borders with your allies and he doesn´t provide help minus points on the relation he sends money or breaks alliances or cancels trading rights in your favour your standing increases if he doesn´t it decreases

    no talking no shared border no comunication means the trend goes to 0 no matter how bad or good the relation was before

  3. #3

    Default Re: "Best Friends Forever" AI Code

    I am no modder by any stretch of the imagination. So please take this with a pinch of salt - I could be completely wrong.

    What seems to be a good idea if you intend to make such code work, is to play a bit with the variables (both in coding, as well as in game - e.g. have relationships with more factions). Once you get different results, it is easier to track down when a change has kicked in, and how the game actually uses these triggers. What happens when you start a game as the Seleukids or Ptolemaoi, and particularly with regards to the relationship between those two powerhouses?

    From what I can gather from the MT2W documentation FactionScorePercent compares the score against the leading faction (likely to be Seleukids or Ptollies in the beginning). While FactionScoreRank, tests the faction score ranking with respect to other discovered and alive factions. From my reading, once Ptollies get their turn, the trigger is checked, but because they will have a "FactionScorePercent" that is way above the threshold, they would not get anything. The same is not true of Pontos. In the case of Pontos it is certainly not that hard to know more than 5 other factions (and given the difficult position of Pontos, that most likely means 5 factions that are stronger than Pontos). Since none of the factions is excluded via FactionStanding, this applies to all factions.

    So it seems that every time the turn starts for Pontos, the 1.0 / 10 kicks in, and thus you get 0.10 improvement in relationships, irrespective of the size of the other faction. So what seems to be missing is a variable that excludes the biggest factions from getting this relationship boost. You want to do that dynamically, rather than use a blunt tool to exclude the Seleukids and the Ptollies.

    As said, I could be completely wrong here.

  4. #4
    EBII Council Senior Member Kull's Avatar
    Join Date
    Jan 2003
    Location
    El Paso, TX
    Posts
    13,502

    Default Re: "Best Friends Forever" AI Code

    The takeaway is we have TONS of AI code that does many different things. The problem was that those three pieces of code (less than 1% of the total) overwhelmed all the rest of it.
    "Numidia Delenda Est!"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO