AI Development Guide and M27AI v74 Devlog

Here is a new replay where the AI is seen having built 2 SMD nearly next to each other, both of which have nothing loaded, and that AI got destroyed by a nuke... https://replay.faforever.com/18075538

I only saw what was current on my team while playing. The dark red colored AI in the south is the one in question. Others may also have built multiple smd but I didnt watch the replay.

@teralitha Thanks, I'll have a look to figure it out (from an initial glance it looks likely to be an overlap between my firebase SMD logic and my main base logic but I'll test to confirm).

Re the T1 power gifting they're meant to transfer back to the original owner who then reclaims them once all teammates have sufficient power, so if this isn't happening if you send me a replay I can see why. Broadly, if all M27 teammates have a T3 PGen (the actual threshold is earlier than this) and the M27 gifted the PGens also has surplus energy (of 100 per second) then they should be gifted back.

Meanwhile they should only gift T1 PGens to a non-M27 teammate if that player has less than 10% energy stored (as well as less than 750 energy income per second)

Re its attacks I did see one (ai vs ai) game recently where 3 ythotha got sent to attack an enemy base at the same time but it's more likely to attack with 1-2 experimentals, while waves of units are more likely at lower tech levels (but if you're turtling up then it's far less likely)

@relentless Already implemented :), I like to share PGens as well since a lot of my build conditions are based on the AI's gross and net energy so giving the T1 PGens over makes those more reliable/accurate than estimating the overflow available to it.

Well, if it is intended that they gift Pgens back, I have never see it happen. All ive seen is once they have been gifted to someone, its permanent. I think the replay I just gave you should show this. And if they are gifting them to me, I am unable to gift them back. I believe that is something you would have coded into the AI, to not allow a player to gift them anything. If I notice they have given me something, I will usually control K them. I still think you should remove PGEN gifting at all.

I watched that replay back today and I saw that the red AI actually built 3 smd's(EDIT: Actually they built 5 of them which were all destroyed by artillery and then they promptly built 3 more! After which they got hit by a nuke and died...) and they were turning them on and off repeatedly. Definitely needs a change.

@teralitha Found the issue with the SMD (and why I've not come across it before) - Seraphim battleships can build nukes, so the AI was (correctly) seeing them as a nuke capable unit and trying to build enough SMD to prevent being overwhelmed by nukes if they were all building them.

I'll probably tweak it for the next version so limit the amount of SMD being built where the nuke launchers are battleships.

Also not seeing any 'left over'/isolated T1 PGens on the replay (about 45m in) - the only PGens out of place are where an ally whose base (and all their power) got mostly destroyed and so was gifted the PGens

Yea it wasnt the best example in that replay. Ive seen it happen more prominently on different maps.

So.. my cybran submarine can build nukes too. Does the AI react to that by building more SMD? perhaps I can trick the AI into wasting more resources into SMD then by building a bunch of subs...

@teralitha yes and yes (assuming it sees the subs), but you’ll be wasting mass on the nuke subs yourself since theyre not worth the mass for the tml effect, so it’s only likely to be viable on larger team games where every player has to build smd to protect from a nuke

The thing is... a single SMD can shoot down multiple nukes if it has enough loaded. Nukes travel slowly, so it would take like 3-4 nukes dropped at the same time to get past a single smd that is loaded with enough to stop them all. Anyway, I hope you can make an adjustment so the AI isnt over reacting to a nuke possibility and wasting resources. And seriously consider getting rid of the gifting, except in very extreme cases.

Those are all the main issues I see with the AI currently in my opinion.

Major:

  1. Too much gifting(and possibly not returning to owner)
  2. Too many SMD

Minor:

  1. Producing way too many T3 engineers for their eco level.
  2. Not protecting base well enough with shielding and AA vs other M27AI that are going heavy on Air.(Pretty much every match i use M27 in, they all go berzerk with air units and spider bots)

Oh yea one other minor issue I forgot about, If the AI builds a naval factory, every AI team member will send some engineers over to aid it. Looks like the factory is surrounded by a rainbow. (And they only ever build one factory even when I set the options to be able to build more than one) I mean, that part makes sense, but they never aid my naval factory 😞 But really, they should be using their mass on their own production, because usually those AI are not doing so well on eco themselves.

@teralitha I'll see if I can fix the power gifting back when I next work through some minor changes (no time for current release though as it needed releasing today due to the upcoming rainbow cup but I did notice in a couple of the testing replays that the conditions were met for power to be gifted back yet it wasnt). It's not a big priority though as it just means the AI misses out on a small amount of reclaim.

Hopefully you should notice a difference with protecting the base against experimentals (it's probably still not enough to actually stop the experimental, but is more noticeable than before where sometimes almost nothing would be done)

Re navy it's working as intended - M27 will work with other M27 for navy, but not with non-M27 (since it has no control over how the non-M27 navy is used). How effective the 'coordination' approach is varies depending on the map (basically it's worse if the M27 start positions are far away from each other/closer to the enemy than each other). As the navy's still in it's early days it also doesnt have much logic re when it's better to stop building navy and focus on ecoing up, but I may not add that anyway (due to the risk of stopping naval production and losing navy, allowing the enemy to then destroy all of your eco with ships)

v55 Summary of changes
Smaller update due to the need to release by today (to avoid releasing a version just before a game is played with it in the rainbow cup tournament that starts tomorrow)

  • Added logic specifically to try and defend against an incoming experimental attack
  • 6 bugfixes, including pathing fixes on Dark Liver Mirrored map, and an issue that could cause platoons to get stuck for ages/ignore new commands they were given
  • 13 Misc changes, including limiting the amount of SMD built slightly, certain ecoing decisions, and improvements to the mass stall logic.

Acknowledgements:

  • Fearghal – highlighting issues with M27 on Dark Liver Mirrored map
  • Teralitha – Replay with M27 building too many SMD

Latest changes (v56-57 summary)

  • New unit added - Stealth boat
  • 10 Bug fixes, including a rare naval bug that meant naval units didnt move, gifted PGens not being returned to their owner, and a bug causing the ACU to not move (leading to M27's ACU chilling underwater in the last rainbow cup round while its base got torn to pieces nearby)
  • 13 misc changes, including an expansion to dodging micro to work in an area (primarily to help naval units which for the AI end up stacking units ontop of each other making them highly vulnerable to any aoe), tweaks to queued torpedo bomber orders, and having naval factories build a greater variety of units at T3 (instead of only T3 units)

v57 update
I revisited the approach to pathfinding thanks to Jip detailing the appraoch used by Balthazar for determining pathability which was much more accurate than M27's approach (broadly, M27 was checking how much the height changed at 0.5 intervals to determine if you could path there, but counterintuitively you get a more accurate result if you check the distance every 1 block, i.e. less frequently). As the changes took far less time than I was expecting I figured I'd release ahead of the upcoming rainbow cup games (as it should hopefully reduce the risk of strange results and also slightly improve game speed).

v58 Update
This update was mostly about making changes from some prominent issues I noticed from the recent Rainbow Cup tournament casts, including:

  • On Dark Liver its ACU ignored lots of reclaim by it to advance on a land factory relatively far away. Meanwhile there was very noticeable stuttering when running the replay at increased speed
  • On Carrius it started a T3 pgen with almost no mass income and while mass stalling, and paused a land factory with a T3 mobile artillery 99% complete
  • On Air wars it was slow getting a transport and then sent it to the other side of the map
  • On Exo 50-T testing ground it eventually got a soulripper and suicided it into the enemy base when it didnt have air control
  • On Citadel M27 built a massive army of inties (more than 100) which often suffered heavy casualties when traveling over enemy flak
  • On one of the replays the casters commented on lack of variety in M27's taunts
    I've also made some refinements to some other aspects noticed from pre-release testing replays.

Changes made

  • 10 bug fixes, including one with transports causing them to try and target the furthest plateau from them instead of the closest (per the air wars replay)
    34 misc changes, including:
  • ACU adjustments to make it more likely to run from large threats and reclaim in preference to attacking out of range units
  • Increased taunt variety
  • Ecoing enhancements, including assisting mex upgrades, not pausing near-complete factories, and having a basic mass limit before starting a T3 factory upgrade
  • Added caps on certain units (inties, gattling bots, hoplites)
  • Reduced pathing limit from 1024x1024 to 512x512 to improve stuttering at faster game speeds
  • Various adjustments to plateau logic so transports are built sooner and prioroitise nearby plateaus, while factories built at those plateaus should build units even if M27 is trying to eco
  • Adjustments to naval bombardment logic (so e.g. Aeon missile ships shouldnt waste their time firing at moving T1 tanks when the enemy base is nearby)

Acknowledgements

  • Fearghal for organising the Rainbow Cup tournament, and the casting team for providing an entertaining stream of it (in particular Endranii, Spikey Noob and Swokoll who casted M27's games)

The latest updates seem to work well. I've had some good games on maps like Flooded Strip Mine when the AI navy seems to work pretty well. One weakness I found in recent games is that the AI is sending their commanders forward fairly far into the game and they're relatively poorly defended in general and definitely poorly defended against air. If you try to go air too early the AI seems to adapt and defend fairly well but if I don't go air at all early game and then when their commanders cross that map towards me, spam a whole lot of T1 bombers very quickly I can almost always snipe the commander/s. Other than that it's really challenging though as it is still beating us quite frequently with either nukes, artillery or experimentals. Here's an example replay of sniping the commanders with T1 bombers: https://replay.faforever.com/18219133

Possible bug causing crash: hi there we just had a game crash and I am not sure if it was possible an AI bug with M27AI. The log has some lines that mention M27.

I've pasted a few of the lines below but I can sent the full log if you want:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at address 0x009272e4
attempted to write memory at 0x50895010

Program : C:\ProgramData\FAForever\bin\ForgedAlliance.exe
Cmd line arguments : /init init.lua /nobugreport /log C:\Users\tyne1\AppData\Roaming\Forged Alliance Forever\logs\game_18231596.log /gpgnet 127.0.0.1:22751 /mean 1149.82 /deviation 311.527 /savereplay gpgnet://127.0.0.1:51135/18231596/tyne141.SCFAreplay /country NZ /numgames 8 /numgames 6

Callstack:
Unknown symbol (address 0x009272e4)

Last 100 lines of log...

warning: [C]: in function assert' warning: [C]: in function pcall'
warning: ...nder forged alliance\mods\m27ai\lua\m27utilities.lua(79): in function ErrorHandler' warning: ...nder forged alliance\mods\m27ai\lua\m27utilities.lua(1023): in function GetACU'
warning: ...forged alliance\mods\m27ai\lua\ai\m27airoverseer.lua(6851): in function <...forged alliance\mods\m27ai\lua\ai\m27airoverseer.lua:6716>
info: Warning - no valid units in tNewUnits
info: Warning - no valid units in tNewUnits
info: Warning - no valid units in tNewUnits
warning: false\000M27ERROR Count=1: GameTime 1018: Cant find any ACUs that we own for brain2, and in assassination game mode, so will treat us as being defeated
warning: stack traceback:...

@tyne141 Have you got the replay ID? Those error messages are expected with M27 if an ACU has just died (and sometimes happen at the point a game is closed down), although it's still possible that M27 is connected to the crash

v59 - Gunships

  • Unlocked gunship usage for M27 and incorporated special micro logic to improve their survivability
  • Various changes aimed at slightly decreasing vulnerability to T1 bomber snipes
  • Improvements to logic for killing underwater ACUs
  • Various improvements to make M27 respond better to nearby enemy firebases (i.e. if the enemy gets a firebase in range of M27's core base)
  • 8 other misc changes and 6 bugfixes, including improvements to M27's T1 bomber defence when faced with lightning tanks

Acknowledgements

  • Tyne141 – Replay highlighting ACU’s vulnerability to a T1 bomber snipe
  • Azraeelian Angel – lots of replays which prompted many of the changes this version (in particular the logic for killing underwater ACUs, better T3 MAA defence, and dealing with an enemy ACU that builds a firebase to kill M27’s core base)

v60 - Naval enhancements
The main focus was improvements to M27's naval logic:

  • Navy should now respond to torpedo bombers (Cruisers trying to attack them, other navy retreating)
  • Battleships can make use of ground fire in some scenarios to hit underwater targets
  • Naval response will be based on the size of the enemy threat - no longer should M27 send its entire fleet to intercept a single T1 engineer
  • 7 other naval related chantes, including Seraphim sub hunters temporarily surfacing to fire at torpedo bombers
  • Improved skirmisher avoidance logic so they're a bit harder to kill with a guncom
  • 6 bugfixes and 8 other misc changes, including rewriting weapon prioritisation logic to fix some scenarios where it wasn't working, and adjustments to gunship logic to increase their area of operations

Acknowledgements:

  • Relent0r noting M27 struggled against RNG on naval maps due to its tendency to chase down lone enemy units with its entire navy

v61 - Stats
A couple of significant changes in this update, neither of which has any impact on how M27 plays:

  • Added detailed stats profiling which can be accessed regardless of whether an M27 AI is playing in the game (i.e. the mod just needs to be enabled and the configuration option set in the code to enable the stats) - as featured in the recent AI tournament
  • Created a separate AI mod! (However this mod just uses the AI as a means of spawning ACUs for human players at different start points). It hopefully provides an extra option for people wanting to fight the AI where a single AI is too easy but multiple too hard (in addition to the more mainstream use for PVP games)

In terms of other changes (that will impact how M27 plays):

  • Added naval factory land defence logic (so enemy land units that try and attack the factory should no longer be ignored)
  • Implemented and then promptly removed IMAP functionality, and instead created my own 'M27 IMAP' logic to help strat bombers be less likely to choose a target that sends them into a cloud of enemy interceptors
  • Various improvements to naval logic (13 changes)
  • Various improvements to air logic, particularly focused on when M27 is behind on air (8 changes)
  • 6 misc changes, including a greater focus on reclaim
  • 15 bugfixes

Acknowledgements:

  • Thacon – replay highlighting M27’s vulnerability when the entire enemy team focuses solely on air.

Latest changes (v62 summary)
Introduced a new land rush mode for the AI which it will sometimes (but not always) use on smaller maps to favour t1 tank spam over its more conservative/ecoing approach.

During testing overall it feels marginally weaker for M27 than its normal approach, but it managed to pull off wins in some scenarios that the normal M27 would lose to.

Other changes:

  • Various changes meant to further improve M27's response when far behind on air along with other misc changes (11 changes to air), including significantly increasing production of both asfs and MAA, and being more cautious with use of asfs
  • 4 Misc changes to naval logic, including adjusting the unit mix and focusing down mexes
  • 6 bugfixes, and 13 other misc changes, including adjustments to early game building logic for the ACU and engineers and reducing ACU's tendency to dodge (which could lead them to taking more damage since they won't overcharge when dodging)

Acknowledgements

  • Azraeelian Angel - Several replays highlighting M27's vulnerability when losing air control (and the speed with which it needs to build SMD to stop humans)
  • RottenBanana - 1v1 replays highlighting M27's vulnerability to raids and a bug with trying to raid underwater mexes
  • Deribus - replay highlighting the delayed response to building TMD at a firebase when being attacked by TML

Latest changes (v63 summary)
Various changes based on replays received, including:

  • Less likely to overflow mass at T3 stage, with a significantly faster scaling up of build power (6 changes)
  • T3 fixed arti prioritisation coupled with target variation (to avoid firing at the same heavily shielded position forever) (9 changes)
  • Air less suicidal and also better at defending high value friendly air units (18 changes)
  • Chokepoint maps - M27 will now abandon a chokepoint and revert to default logic rather than staying in turtling mode if it's chokepoint is overrun and it somehow survives, along with several other small adjustments (3 changes)
  • SAM creep logic - Basic code to have M27 try and protect mexes with SAMs if it's behind on air
  • 14 bugfixes and 19 misc changes

Acknowledgements

  • Radde - various replays, highlighting M27’s poor ability to cope with lots of mass, flaws with the turtle logic, and tendencies to suicide its air (including air experimentals).
  • Azraeelian Angel – Loads of team game replays (so many I had to defer analysing some of them for the next release!), highlighting amongst other issues the need for better T3 arti building logic
  • Spikey Noob – A number of 1v1s at increasing difficulties on badlands highlighting the ease with which M27's ACU can be killed with T1 land
  • Jip – 2v2 replay against M27
  • Relent0r – Flagging a bug in M27 that causes it to break default AI from building on mexes that are covered by reclaim.

Smaller update fixing a few bugs and adding in mass fabs:

  • Unlocked ability to build T2 mass fabs (I've not checked how it handles reaching the unit cap though, here's hoping it doesn't ctrl-K them!)

6 bugfixes, including

  • Bug resulting from the latest FAF patch that caused the Ythotha death ball/energy signature to be controlled by the AI (at the same time I've improved M27's response speed to the death ball from before)
  • Shield boats should no longer remain at the naval factory if they had lost shield at any point in the past
  • The Bjarg map should now be playable by M27 in the bottom-right start position (previously it would break)
    14 Misc changes, including:
  • MML should be far less likely to walk into range of T2 PD
  • Added new 'experimental prioritisation' builder logic for late-game (where land factories are less likely to build units to conserve mass for experimentals)
  • Slight improvements to M27's response when an enemy tries to get a firebase near M27's base
  • Slight reduction in the bomber defence range to make them less likely to suicide into enemy air

Note that updates may be smaller and/or less frequent for a bit as I mull over creating an entirely new AI, and/or testing out changes in a basic alternative AI that might then be incorporated into M27 at some future point.

Acknowledgements

  • Jip – Highlighting error on the Bjarg map where if M27 started in the bottom right position it wouldn’t work
  • Azraeelian Angel - A number of team game replays
  • Radde - Several teamgame replays