Two Questions about the AI

Discussion in 'Modding' started by Ftoomsh, Feb 20, 2018.

  1. Ftoomsh

    Ftoomsh Well-Known Member

    1. How is time counted by the AI? If I wanted to code in the AI "don't do action X until after Peacetime minus five minutes" how would I code that? I guess it's "IF gametime > Peacetime minus five minutes then etc". But is gametime measured in ticks or seconds or minutes and seconds anywhere in the code? What is the standard for time triggers?

    2. Why does the AI stop upgrading mines at 10? One of each type even stops at 5. So the gold mines, for example, end up with 35 gold miners in a 4 gold mines quadrant.

    I know the development rationale: the AI begins to rely on sales of wood, food and stone.

    But what is the technical reason? Where does the AI, in progresseconomicai or elsewhere, define that 3 gold mines get upgrades to 10 miners each (only) and 1 gold mine stays at 5?
     
  2. Ebel

    Ebel Moderator Staff Member

    Never looked into AI but, there are constants for time & frames in dmscript.global.

    gc_frames_to_time = 0.03125;
    gc_time_to_frames = 32;

    Start running a search in all files for "time" & "frame". Something will popup.

    Also 'speed" or "time' has some settings in data\env\time.cfg , especially the speedfactor & normalspeedfactor define how fast time goes by and there must be more lines of code for this. You'll just have to search.
     
  3. Ftoomsh

    Ftoomsh Well-Known Member

    Yes, I was thinking too that missions have time triggers so maybe I can find how time triggers are handled by missions code.
     
  4. Ftoomsh

    Ftoomsh Well-Known Member

    UPDATE:

    It appears I should be able to work something out from this.

    [*] = ; var ptleft : Float = gfloat_peacetime-GetGameTime;

    and this;

    [*] = ;function _ai_GetTimeFromStart(plind : Integer) : integer;
    [*] = ;begin
    [*] = ; Result := floor(GetGameTime-gPlayer[plind].aidata.inittime) div 60;
    [*] = ;end;

    I assume it return seconds so that a ptleft of 300 would mean 5 minutes.

    My overall thinking is that the AI could be considerably improved by some relatively simple changes. These changes would be based on basic heuristics (rules of thumb).

    Heuristic 1 - Resources in storage are worth less than resources embodied in structures and units.

    Corollary - Resources translated into structures and units will grow your economic and military force faster. Resources left in the "bank", unused and un-traded, are idle resources doing you no good unless you are saving for a specific, much needed upgrade. Therefore, sell un-needed resources for more needed resources. In doing this, sell down to a "floor" stock. A "floor" stock is retained for ongoing needs. Food is a good example. Progresseconomicai certainly implements floor stocks when selling but it is not aggressive enough in selling surplus stock for more needed resources, especially at the start of games above 1,000s resources.

    Heuristic 2 - Just in Time (JIT) management of upgrades. It is best to push economic upgrades first and delay military upgrades as long as feasibly possible.

    Corollary - If you grow a bigger economy in safe time (usually peacetime) you can convert that into more military upgrades (and likely more military buildings and units) by the time peace time ends.

    This is what I want the time function for, to trigger upgrades at the appropriate time using something like [*] = ; var ptleft : Float = gfloat_peacetime-GetGameTime;

    Heuristic 3 - The best economic build order is that which gives you the greatest numbers (of peasants and military units) by time "T" whatever that time is.

    Corollary - Quantity will confer a win if all else is equal. (Of course, this is a big "if" because military upgrades, unit quality, tactics and strategy all play in to this equation.) The AI has to choose a point or points to cut over from pure economic upgrades to running miliatry upgrades


    C3 simplifies the choice of next building structure for best growth purposes. Its design with rapidly inflating building costs essentially prunes the move possibility tree in terms of the choice of the next structure to build. Given other necessary buildings to satisfy build dependencies, the next structure which produces units and which the AI can afford is the next structure it should build. One does not even need a move tree search to implement this rule of thumb. A scripted build list will do.


    Summing up

    The AI does some of the above but it does not do all of it. Even what it does do, it does not do it well enough. It can be improved upon.

    The above would be only a first step. It does not address the efficiencies or inefficiencies AI micro-ing and AI pathing (shortest path analysis).

    Beyond that, it does nothing to address military tactics and strategy, which of course will be the most difficult to make "intelligent" in any way.

    Still, the first steps have to be taken (given that I want to pursue this currently). Applying the above heuristics as a first step will still be a scripted AI, not a true adaptive AI. But it will make some "intelligent" choices based on starting peacetimes, starting resources, the 3 heuristics, resource floors, more active selling and a way of valuing each resource in commodity money (gold) based on market prices to determine which resource to sell when another is needed. This last would require an algorithm to determine "most urgent upgrade", then "most needed resource(s) for most urgent upgrade" and "(most) sellable" resources. "Sellable" would involve calculations based on determining that some resources are "surplus to current requirements given current urgent needs".

    It occurs to me that two different nations which have very similar buildings, units and cost structures (I would say the two most similar Euro nations) could be given different versions of the AI being tested (with different parameter weightings etc. in the AI). Then they can be tested and re-tested against each other and the most effective weightings thus progressively discovered. This is a standard method of testing to improve AI.
     
    Last edited: Feb 21, 2018
    Loner likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice