AI Project - Progress

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

  1. Ftoomsh

    Ftoomsh Well-Known Member

    I have started my "little" AI project. As a first step, I am making a better AI for the vanilla game. The first step is to improve AI development (economic / military development). The project is intended to go like this.

    Stage 1 - Economic / Military Development
    Stage 2 - Tactics
    Stage 3 - Strategies
    Stage 4 - AI Control Module to link the first 3 stages.

    As the first part of Stage 1, I am refining the thousands (5,000s) resource build for peace times from 10 minutes up. This is really so that I can simply learn the basics. At this point, it is still a fully scripted AI development path. However, I am iteratively testing and improving the build. I am also applying a set of heuristics (high level "rules of thumb") to guide my development of the build script.

    I can report some early success. My test of the standard AI Impossible with Prussia on 30 PT and thousands had Prussia reaching a score of 415.75 at the end of peace time. This score is achieved with food and gold cheats which the standard AI gives itself in progresseconomicai when it runs infantry upgrades in the barracks.

    I have removed these cheats (I want no cheats in this AI) and applied my heuristically guided design for the build process and the new AI achieved a score of 502.05 at end of PT. I might add that there is a whole set of extra possible efficiencies which I have not applied yet. I will have to learn more about coding the economic AI to maximize all efficiencies.

    Of course, this is only the early part of Stage 1 of this project. The only file being modded so far is progresseconomicai.inc. When each stage of the project is finished, I will release the AI with that stage added. Stage 1 release might be in about 1 to 2 weeks time.

    The first releases of Stages 1 to 3 will be scripted AI. Then, if I can start stage 4, the first 3 stages will also need re-working to become genuine goal-seeking AI, not just scripted AI. I have no idea if I can get all the way in this project. I will simply go as far as I can with it.
     
    Last edited: Feb 23, 2018
    Burak Damgacı, Loner and Johny like this.
  2. Ftoomsh

    Ftoomsh Well-Known Member

    I have found what I believe are AI resource cheats (3 of them). If anyone knows of any more please let me know. The AI resources cheats are in;

    procedure _ai_TryUnitUpgradeEx(plind, cid, id : Integer; var sid : String; bprocesshuman : Boolean);

    ... code omitted ...

    [*] = ; if (bai) then
    [*] = ; begin
    [*] = ; if (food>0) then
    [*] = ; food := food+1100;
    [*] = ; if (gold>0) then
    [*] = ; gold := gold+150;

    When the AI tries for a unit upgrade it gives itself a resource cheat boost first. This is in economicprogressai.inc.

    There are also two cases in unit.script of similar form where, when it orders units to build and when it orders unit upgrades (again!), it hands itself a resource cheat boost. These ones also take the basic form of the above example. These are in functions which are called by economicprogressai.

    Do modders concur that these are AI resource cheats? Do you know of any more? I know the AI cheats in other ways. It has full sight through the fog of war and it can interrogate what military upgrades the human player is doing and (potentially) use these as advice for its own upgrades.

    I am trying to remove all AI cheats in my project. I am trying to replace the AI cheats with greater AI efficiency and eventually more comprehensive AI goal seeking. AI cheats encourage lazy AI programming. It's a lot easier to program cheats than program good AI. Also, true intelligent and goal-seeking AI is more responsive to the opponent's moves but only when it scouts them. Thus its behaviors become more complex, more responsive and more interesting to play against. This is what I am aiming at.
     
    Last edited: Feb 25, 2018
    Loner likes this.
  3. Ftoomsh

    Ftoomsh Well-Known Member

    I am not above crowd-sourcing when I can't find answers quickly or when I don't understand some of the code.

    Does anyone know what parameters or variables I would change to make the AI;

    (a) place buildings closer together?
    (b) place the next building right next to the last building?
    (c) make peasants selected to build then build close to where they were selected?
    (d) place all stores and Town Centers south-west of stone and wood patches?

    All of these changes would reduce useless path-walking (long journeys) by the peasants, thus leading to an increase in building efficiency and resource collection efficiency. Time spent walking or carrying resources is wasted time. A short walk is more efficient than a long walk. All these incremental savings in peasant journey time (wasted time) can really add up over the course of a full game.

    I am aware that a couple of the above measures could be counter-productive. That problem needs to be dealt with if and when it manifests itself significantly in tests. I mean that building structures close together will eventually start obliterating nearby forests. The stone patches are safe of course. The forest problem might not be too acute especially if a small open zone is left around buildings. Either that, or new routines would be needed to burn down sheds which have become almost useless and to build sheds further out.
     
  4. Ftoomsh

    Ftoomsh Well-Known Member

    Project Update 1

    I have just run a test of my scripted build for normal resources (1,000s), rich mines (4 of each) and 30 mins peace-time. Market and diplo are allowed. Under these conditions, the vanilla game with Prussia reaches a score of 313 on a plains land map, on my PC anyway. My new scripted build reaches a score of 356. (Decimal points are left off.) Remember, my scripted build removes three sets of of food and gold cheats that the vanilla game uses so this means this is a fairly good result. There will be a couple more important resource gathering efficiencies I can add when I can figure out how to code them.

    AI cheats are being removed and AI efficiencies are being added instead. This allows human play against the AI to be logical in the sense that attacking certain forms of resource collection will have the results you expect. If you are raiding food and gold collection and the vanilla AI is using food and gold cheats, then you will wonder why your damaging raids are not slowing the AI down or at least having very little appreciable effect on it. If the AI is playing efficiently but honestly, then your raids will have their proper and expected effect.

    Of course, it is early days yet. This is a scripted build that does very little "thinking" for itself. One bit of "thinking" it does is to delay military upgrades until a calculated time based on peace-time and the size of the map. The time that military upgrades are started is 5 minutes before the end of peace time minus half the traverse time for a pike to traverse half the map. This causes the AI to delay military upgrades until just a few minutes before the end of peace time and then to rush the upgrades through. This allows most of the peace-time build to concentrate on getting more economic resources and more raw (non-upgraded) troop numbers.

    Of course, the military algorithms will have to be modded to adapt to this approach. I have not even started on military algorithms yet.
     
    Burak Damgacı and Loner like this.
  5. Ftoomsh

    Ftoomsh Well-Known Member

    Project Update 2

    Much remains to do on stage 1 and release is still at least a week away. My progress is rather slow.

    I hope that Stage 1 will have these elements up to point (8) at least;

    (1) Starting sequences based on Resources (1000s, Rich, 5,000s, Millions) and then;
    (2) Also based on Peace Time and then;
    (3) Also based on map size.

    (Note: The AI will estimate possible rush times based on starting resources and map sizes, especially for 0 PT)

    (4) No use of resource cheats by AI.
    (5) Efficient collection of resources by ensuring short build paths and resource delivery paths (peasants walking less distance).
    (6) Active use of the market to speed up build sequences.
    (7) Delays of military upgrades until necessary (a just in time approach which allows the AI's economy to grow faster and then it converts to military power at the last moments).
    (8) Proper creation of formations.
    (9) More military aggression and more attention to having greater numbers engage at battle sites.
    (10) Retreat in the face of superior numbers.
    (11) More raiding by the AI.
    (12) Better defensive response to threats to infrastructure.


    I know I am going to have to look at the mod TA AI for ideas on coding points (9) to (12) and these elements might not be in Stage 1. Also, I haven't looked at making builds for specific nations better as yet. Ditto for unique units.

    Eventually, I will need to make the AI more responsive to what the opponent is doing. Only a truly responsive AI will become interesting to play against. A combination of this tactical responsiveness and of random selections of possible starting strategies (viable ones only) will make the AI deliver much more variety of actual play instead of being boring, scripted and predictable. Indeed, the more sophisticated and responsive it becomes the more its strategies (rather than just its tactics) can become responsive.

    I warn that I don't know how far I can get with this project. My actual coding skills and knowledge leave a lot to be desired. This is a bit of a learning exercise for me.
     
    Last edited: Mar 2, 2018
    Burak Damgacı, HUNRex and Loner like this.
  6. Hansol333

    Hansol333 Active Member

    For me the AI was one of the biggest problems. While the AI is somewhat decent in campaign missions it is garbage in random maps.

    -performs +cavalry speed upgrade before even one single stable is build
    -builds up to 5 18c barracks before a 17c barracks is build
    -still trains 17c pike even so the AI is much more dangerous now with 17c muskets.

    I personally think that the developers dont give a damm about the AI. Now that 17c musket have been buffed it is totally easy to counter 17c pike even early in the game with 17c muskets. So you build a larger and larger army while the AI trains pike which then instantly dies. Well I replaced in economicAI 17c pike with 17c muskets and the games are much harder now. I see ZERO changes in the AI development and that means the developers dont care about their game any longer except some tournaments. The name impossible for very hard is such an insult.

    I tried to make the AI better. I gave them +300% gathering speed and a bonus that every private upgrade also increases training time. I was still able to win. After a few attacks at the beginning the game they retreat and dont do anything. Several minutes pure boredom until the army is so huge that they attack and then win.

    I tried to make the AI more aggressive but I wasnt able to do so. Also the AI dont combine units very well. So rather then attacking with one squad of 17c pike at the front as meatshield and a 18c musket squat behind to deal damage they attack alone making them pretty bad.

    If a new dlc would or have appear(ed) and the devlopers would promise that the AI would be buffed. Maybe even add new options like aggressive, devensive, neutral I might would give C3 a try again and continue with modding.

    But right now the game is dead to me especially since the developers dont care about C3. I dont have either the time or the skill to make a somewhat decent AI, thats the job of the devlopers not me. changing bad balance is so much easier then bad AI. I have uninstalled C3 and are not planning to give it another try.