Performing AI battles

Discussion in 'Mod Discussions' started by Quitch, April 20, 2015.

  1. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    wondible now has a tool for this https://github.com/JustinLove/ai_showdown

    So I've come up with a really hacky and imperfect way to have AIs battle one another. See these examples of Queller fighting the default AI. Both videos use a slightly modified version of Queller 1.2.4, so there may be some odd behaviour from changes which haven't yet been fully tested.





    I posted a while back about having the AI build an object which then determined which AI was used using lots of sub-checks in the AI build lists. I didn't like the idea because firstly it was a lot of work, and secondly because the object would both influence play and result in the AI reverting to default if destroyed.

    Recently I found I could change which commanders were used by the AI by modifying \media\server-script\lobby\commander_manager.js

    Code:
    var default_commanders = ['ProgenitorCommander', 'AlphaCommander'];
    I then modified the json files of both commanders to give one of them UNITTYPE_Bot and the other UNITTYPE_Tank (the game appears to have a set list of supported unit types). Then using the power of search & replace I assigned an additional check to everything in Queller's files and the default AI's files. In effect, every single item got one of the following two additions:

    Code:
                   {
                      "test_type":"UnitCount",
                      "unit_type_string0":"Commander & Tank",
                      "compare0":">=",
                      "value0":1
                   }
    
                   {
                      "test_type":"UnitCount",
                      "unit_type_string0":"Commander & Bot",
                      "compare0":">=",
                      "value0":1
                   }
    
    I then modified every Queller build list items' name to be prefixed with Queller -, in case unique names are required. All Queller platoons were postfixed with _Queller to differentiate them from the default platoons.

    Finally I smooshed the two AIs into one set of files.

    However, there's one limitation. The ai_config file has no means by which you can have two versions, you either use the default or you use your modified copy. You could potentially work around this by building all the logic into the other files, but there may be some subtle differences in behaviour if you do this. For my test videos above I did battles using both ai_config files.

    Here's my full file of search & replace stuff for Notepad++ based on files formatted using this validator.

    Code:
    "name":"
    "name":"Queller -
    
    SWITCH TO EXTENDED EXPRESSION
    
    }\r\n            ]
    }\n            ]
    Vanilla
    },\r\n               {\r\n                  "test_type":"UnitCount",\r\n                  "unit_type_string0":"Commander & Bot",\r\n                  "compare0":">=",\r\n                  "value0":1\r\n               }\r\n            ]
    Queller
    },\r\n               {\r\n                  "test_type":"UnitCount",\r\n                  "unit_type_string0":"Commander & Tank",\r\n                  "compare0":">=",\r\n                  "value0":1\r\n               }\r\n            ]
    
    MAKE SURE THE PLATOON FILES GOT UPDATED TOO
    
    SWITCH TO REGULAR EXPRESSION
    
    platoon_*_builds
    ("to_build":".*)(",)
    \1_Queller",
    
    platoon_templates
    ":{
    _Queller":{
    Last edited: May 28, 2015
    SXX, burntcustard, crizmess and 2 others like this.
  2. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    The search & replace I used results in entries in placement rules which shouldn't be there. I haven't been able to discern a negative effect from this, but I'm going to adjust the rules next time I use them to put the commander check at the top of each build item rather than the bottom. This will allow it to avoid inserting them into placement rules because the spacing is different.
  3. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    Would this be worth semi-automating?

    If so, are you comfortable running programmy tools? I've been doing my JSON mashup stuff with node and grunt so far, on the assumption that PA modders will be somewhat familiar with javascript.
  4. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    I can't code worth a damn :) It's certainly doable, but it's unlikely that it'll be done by me. You'll also need a tool that can handle format differences, because things like spacing changes according to the formatter used, and even order can change. The batch script that has been posted on this forum for example essentially reverses the order of each block (which I hate and is why I don't use it).
  5. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    Just if you were comfortable installing and running command line tools; configuration would be roughly at json level of complexity.

    I usually parse the JSON and regenerate it. A quick look at one of my mods suggests that it preserves key order, though there could be some effects from the modifications.
  6. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Oh yeah, I used to do sys admin work, command line stuff is something perfectly within my comfort zone.
  7. squishypon3

    squishypon3 Post Master General

    Messages:
    7,971
    Likes Received:
    4,356
    Honestly PA is my first time interacting with javascript- though it's great experience for future classes I'll be taking. :3
  8. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Updated search & replace to avoid the issue of things being inserted into the placement rules.

    Code:
    "name":"
    "name":"Queller -
    
    SWITCH TO EXTENDED EXPRESSION
    
    platoon_ files
                [\n              {
    everything else
                [\r\n              {
    
    Vanilla
                [\r\n               {\r\n                  "test_type":"UnitCount",\r\n                  "unit_type_string0":"Commander & Bot",\r\n                  "compare0":">=",\r\n                  "value0":1\r\n               },\r\n               {
    Queller
                [\r\n               {\r\n                  "test_type":"UnitCount",\r\n                  "unit_type_string0":"Commander & Tank",\r\n                  "compare0":">=",\r\n                  "value0":1\r\n               },\r\n               {
    
    MAKE SURE THE PLATOON FILES GOT UPDATED TOO
    
    SWITCH TO REGULAR EXPRESSION
    
    platoon_*_builds
    ("to_build":".*)(",)
    \1_Queller",
    
    SWITCH TO NORMAL
    
    platoon_templates
    ":{
    _Queller":{
    
    REMEMBER TO FIX PLATOON_TEMPLATES IN THE OPENING LINE
    
    Last edited: April 21, 2015
  9. s03g

    s03g Member

    Messages:
    111
    Likes Received:
    22
    I've been trying my best at getting notepad++ to do what you've managed to achieve although I'm having great difficulty in doing so. I've uploaded the file that I've managed to get out of it as such so that you may give me some pointers as to where I'm going wrong please :).

    Attached Files:

  10. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    Current output: http://wondible.com/pa/com.wondible.pa.ai_showdown._Default_Quellar_s03g.zip

    Nothing blows up when I run it, but I'm not not an expert in AI behavior. I did discover the bug where where replacing an AI will show you the personality of the last AI, but the server will be set back to the default. (stable, haven't retested in PTE yet)

    WIP repo: https://github.com/JustinLove/ai_showdown

    I started with the tool I'd build for myself. Tell me where it hurts, and we'll evaluate whether it can be done with refinement, or needs a different strategy.
    Quitch likes this.
  11. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Wow, awesome work!

    I'm amazed to say it seems to work, which has me really questioning my testing because it shows me that two things I thought I had established are, in fact, total bullshit:

    1. Only the standard AI file names work
    2. Custom UNITTYPE_ tags don't work

    Which has me wondering why my UNITTYPE_Boom experiments failed. I guess I'll need to revisit it.

    Where a file had a x.0 in it the tool appears to be dropping the .0. I don't think this will break anything, but I've never tried it for numbers I found formatted in this fashion. I think the safest approach is to reproduce the file as found to avoid introducing complications, or fixing bugs which lead to changes in behaviour.

    The tool introduces spaces after every colon. This won't cause any problems that I know of.

    Only one ai_config was included. My recommendation is that a copy of every ai_config file should be created with a postfixed name by the tool, with the default AI values being left in the master ai_config.
    EDIT: Actually having looked at the ais.json I like the idea of creating one version per ai_config.

    A server-script folder is in the mod directory, but obviously PAMM doesn't process this. It should therefore be created at the root along with the mod itself (I'm assuming the tool created the mod). Better yet would be if the tool simply modifies the existing file, making a copy of the original.

    The ai_unit_map file was Queller's. How does the tool handle this file?

    The only other adjustment I'd advise is renaming the Commanders to reflect their AI name. It makes it easier in-game to verify which AI you're seeing fight and check that you spawned the right AIs.

    How did you get the spelling of Queller wrong on every line except the path? :D

    I'm playing around with the tool now.
    Last edited: April 25, 2015
  12. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    I'm not sure what this means. I've seen in the past that introducing new AI personalities through a server mod requires an interface refresh.

    Also, I noticed that the mod is missing the AI personality for s03g. It should look out for, and copy over the ai.js and its folder structure. It's possible there could be multiple copies (one per AI), in which case it would need to merge them.
  13. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    I couldn't find the exact quote, but I know @sorian said something about gathering up all the files in some directory. The paths for the builds directories appear in the server binary, so I took at as all json files under the known directories, with the other files being standard name only.

    Only Custom1-Custom4 are defined for use with mods. I was afraid of triggering other Bot/Tank rules, especially as more AIs are added attributes get more specific.

    I'm not sure what you are referring to.

    JSON is supposed to be whitespace insensitive. Implementations may not be to spec, but I've been using the Node formatter for all my server mods.

    There would be no harm in included postfixed copies of them.

    I didn't want to mess with core files - I tend to use a separate copy of PA for this. Making a copy is certainly a good idea. I could set up a target media path.

    It merges all unit maps. This would only be an issue if there were conflicting definitions. In that case I'd have to postfix everything and then track down all the places unit references appear and adjust them appropriately.

    I was thinking of that, but mostly for the lobby where it's not so useful. Might still be handy in game though.

    Oh you know, move fast and break things. Except things don't always break in an obvious way.

    I used Instant Sandbox to set up a lobby, which set all the personalities to Absurd. I then had to exchange AIs to get the right commanders. The UI still said Absurd, but the observed behavior was more appropriate to Normal. First few times I thought the merge broke something (while I haven't spent much time with Queller, I couldn't believe it would float that bad), but it was a different AI derping out each time.

    Yes, merging is the tricky part. I can probably find a regexp for the table, parse it as JSON, and then look for unusual names.
  14. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    A note for your readme, it says to call grunt, but the npm install doesn't enter grunt as a global variable on Windows. I had to also run npm install grunt-cli -g.
    wondible likes this.
  15. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Got it all working like a charm. Apart from the suggestions made previously I'd add:
    1. grunt build should first delete the current pa folder to ensure changes to ais.json are properly reflected in the build
    2. grunt mod needs to check for an existing folder and delete it before copying
    Last edited: April 25, 2015
  16. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Well the easiest way is simply to take everything, stick - AI_NAME as a postfix, and put it all in one file.
  17. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Queller's fabber_defense_builds file

    Code:
                   {
                      "test_type":"PlanetThreatRatio",
                      "string0":"Land",
                      "string1":"Land",
                      "compare0":">",
                      "value0":1.0
                   },
    The merged version

    Code:
              {
                "test_type": "PlanetThreatRatio",
                "string0": "Land",
                "string1": "Land",
                "compare0": ">",
                "value0": 1
              },
  18. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Finally, the commanders used in the example file should be ones everyone has access to. There's no guarantee the individual using this will have the specs to run a local server.
    Last edited: April 25, 2015
    wondible likes this.
  19. Quitch

    Quitch Post Master General

    Messages:
    5,287
    Likes Received:
    5,991
    Ah yes, one little bug/feature. If you don't include the vanilla AI in your ais.json then it will merge its behaviour with the AIs you're testing because all of them postfix their files and so none override the vanilla AI's files.
    wondible likes this.
  20. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    Forgot to mention the clean task in the readme. I usually only run it as needed, but if you've run into issues already, the usage patterns may be different.

    All JS numbers are floating. The representations are equivalent. This is the system JSON lib output.
    Quitch likes this.

Share This Page