AI Development Guide and M27AI v74 Devlog

v54 summary of changes
Small update mainly to fix the bug with M27 taking control of non-M27 allied naval units

  • 3 bugfixes, including bug with initial land factory build location and controlling non-M27 naval units
  • 2 Misc changes (reducing the amount of AA structures that get built, and no longer targeting underwater mexes with TML)
  • Temporary eco strategy - very niche strategy that will be most relevant probably in AI vs AI games - M27 will eco temporarily even if it lacks map control if it has a firebase protecting most of its units and its core mexes are behind the opponent's

Acknowledgements:

  • Relent0r - screenshot highlighting the factory build location issue was a more widespread isuse than I'd thought
  • Teralitha - Confirming the naval control bug was still present in many cases

Feedback: AI defending against yotha(seraphim chicken experimental) I watched as a single yotha casually strolled through 2 of my allied M27 team mates wiping them out entirely with barely a scatch. One of the defending AI had a sizable group of T3 tanks that they brought to deal with the chicken. Only they didnt. They would approach the chicken at the very edge of the chickens range, and never even try to get in range of their own weapons. They kept retreating out of their weapon range and all got destroyed while doing no damage whatsover to the chicken. My 2 AI teammates were doing better than me in this battle. I had been nuked and was struggling to make any progress. When i saw the chicken coming, and I saw my teammate with a group of 20-30 T3 tanks along with some turrets in the base, I figured they could handle it no prob. But not so. The above happened and the chicken wiped them out easily then moved on to wipe my next teammate in the same fashion.

My assumption here is that the AI are programmed to be a bit too cowardly. Maybe in general, or maybe when on defense. they should have had little trouble dealing with the chicken. Its rather strange how the AI behaves when its my team vs their team.

For example, if I send a monkeylord to an enemy base, the AI will respond by quickly making a huge swarm of t1 bombers. The AI on my team didnt do that. Maybe the AI responds differently to different threats? I dunno. But I have seen the AI on my team get wiped out by a single monkeylord before too. The more I play with this AI the more It seems like the AI on my team plays dumb while the enemy plays smart. I had one team mate that far exceeded me in eco and everything, I thought for sure we were gonna win. But when I look at their base... no artillery... no nukes... no experimentals.. Yet the enemy team will be droppin nukes and marching experimentals, dropping arty on all of us.

As I said, its feels like when the AI is on my team, they dont play very smart or do much, but the enemy AI always seems to be geniuses and gets way ahead of my team on everything. I will say this, my team loses alot. I have won sometimes, but its hard, usually because my team never does very well compared to the enemy team. Its as like, if I dont carry my team, Im pretty much guaranteed to lose with this AI on my team. It gets a little frustrating.

I also want to mention, of all the games ive been playing with M27, I dont believe Ive ever seen them build a GC before. I see monkeylords often, chickens less often. Dont think ive ever seen a crab either. Or a czar. I did once see asswasher. Nukes are pretty uncommon as well. I am seeing the AI build multiple nuke defenses, which is quite inefficient. Thats alot of their mass being wasted.

Anyway, to sum up

  1. AI plays too cowardly with ground units, and as a result gets decimated without doing much. If I had to guess, Id say the AI treats all T3 ground units as a spiderbot regardless of their actual weapon ranges, and as a result, will get killed by units that outrange them without actually closing the distance and engaging.
  2. Builds too many nuke defenses, essentially wasting a ton of mass.

I have always been playing with random factions, but Im gonna be testing with all one faction vs all one faction to see how the AI handles such matchups. And really to see what they build compared to others.

@teralitha Thanks for the feedback, in terms of your points:
-Experimental defence - Ive recently finished drafting specific logic for this in my current WIP version which sounds like it should address your main concern here, although monkeylord may still cause issues if the AI doesnt have omni up by that stage
-t3 units not engaging experimental - have you got a replay? Theyre not meant to engage if they think theyll lose the fight but it sounds like they might be a bit too cautious, or (if it’s their base under attack) should just try attacking anyway
-too many smd being built - I was hoping to fix this in the current WIP but a replay where I came across the issue is desynced; have you got a replay example of this? Ideally where 3+ smd are built near to each other when the enemy has just 1 nuke launcher
-No GC being built - I expect if you only play Aeon vs Aeon you’ll see some being built, Ive seen them and Czars built numerous times where the only faction on the team is Aeon
-Poor M27 teammates - one possibility is that the teammates lack air control so focus on regaining it while the opposing team has air control so focuses on other areas, which would also account for the poor response to attacking experimentals. m27 only considers friendly M27 air units when deciding if it has air control so it’d be eg 3 m27 trying to outproduce 4 m27 at air (and likely almost always being behind as a result)

When it comes to air control, I usually dont focus on making air units myself, but instead I send out SACU's to my allies to build SAMS and Shields around their bases since they dont do much of that themselves. M27 tends to focus only on offence. But I only do this if I am able. In games where I cant support them in time they will tend to die a slow death from air attacks or novax picking on their shields. They would do much better if they would build more shields and sams since M27 heavily builds air. I hardly ever need to build anything to defend against a ground assault. I usually get away with building one experimental and just have it at the front line with some sams and some other static defenses. Even if my base is in the front, my main worry is defending against a ground experimental, nukes and t3 artillery. I never get assaulted by waves of ground units with M27. But perhaps that is just reactionary. its usually waves of engineers trying to steal all the mass points.

Unfortunately, my recent game where I saw multiple smd, the replay didnt record the latter part of the game where this was happening. The replay ends halfway into the match. If I find a replay where it happens Ill post one later. Also, the AI is still transferring control of Pgens over to me. This is kind of an issue because whatever gets transferred, either to me or another AI, which is usually T1 or T2 Pgen, never gets reclaimed. They usually reclaim lesser PGens later on, but they wont do it for ones that are transferred, whcih then clutters up their base. It might be better if the AI never transferred any structures at all. Resources are generally shared anyway, so its not necessary. Ive watched the AI transfer power over to me (The resource, not the structures) SO them gifting Pgens really is not necessary at all.

Just as an aside Maudlin. You can leverage the brain:TakeResource and brain:GiveResource as well to transfer energy directly should you want to implement more restrictive pgen gifting but still want to be able to quickly help allies if they have crashed power. I do it on mine though I don't play with AI on my team so never really done much validation on it.

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