M28AI Devlog (v144)
-
What is M28AI
M28AI is an adaptive AI for Supreme Commander: Forged Alliance, intended to provide a challenging experience for players, making extensive use of microing skills coupled with strong macro capabilities to defeat opponents.Competent at both 1v1 and team based games, M28AI adopts an aggressive approach to the game, utilising a wide variety of tactics that will adapt based on what the player does.
A variant of M28AI, M28Easy, disables M28AI's micro capabilities, while other variants include land, air, and turtle options. There are also various configuration options to allow players to further refine how it plays:
- Hybrid AI option - if enabled, you can enable M28AI logic on selected units you control (note that this option should only be enabled if you intend to use the feature, as it will result in all normal M28AI calculations being applied to your own units which may impact on the sim speed with high unit counts)
- AIx overwhelm option - allows you to increase or decrease the AIx modifier over time to make it harder/weaker
- Micro level - In addition to the option to disable all microing with the M28Easy option, a 'M28 time between orders' option allows you to adjust M28's general responsiveness level for most units. By default units consider new orders every second, but this allows you to increase the delay up to 10 seconds (which, for example, will make M28's kiting behaviour much weaker, as well as making M28 run faster)
M28AI is highly compatible with mods and unusual map settings, including (but not limited to) popular mods such as BrewLAN, BlackOPs and Nomads. It can also handle a wide array of unit restrictions in FAF (e.g. it is capable of completing the original supcom campaign which in early missions can involve restrictions such as only building t1 air units).
It also supports campaign missions, both as an AI teammate; or as a replacement for the campaign AI (whether for AI allies such as the rebels in the FA Mission 2 Dawn campaign or for the enemy AI), with further configuration options relating to this to adjust your experience set out in the FAF wiki for co-op missions.
M28AI was originally developed for FAF, and this is recommended for the most competitive experience. However, it also now supports both LOUD and steam (see the installation.txt file for details of how to setup M28AI on LOUD and/or Steam; for FAF setup you can either refer to this same file or the FAF wiki which details how to play with custom AIs).
Why should you use M28AI
- Arguably the most competitive (non-cheating) AI available
- Runs significantly faster than M27AI in larger teamgame scenarios
- Chance to see the AI improve and influence it's development via feedback
- Different playstyle to M27AI and other AIs
- Greater compatibility with mods and unusual game settings
- Compatible with campaign missions (FA, SC and custom campaigns) as an AI teammate (in co-op), and/or as a hostile campaign AI.
Background
M28AI was intended as a long term potential successor to M27AI, involving a complete rewriting of the AI framework to run significantly faster in large teamgame scenarios and provide greater tools for the AI to make use of. As of February 2024 it was able to outperform M27 on most maps and settings, and has improved further since then.As with M27 it makes extensive use of microing and its focus is in trying to win games, with an estimated global rating of around 900-1200. An M28Easy option is available that disables most micro (along with a setting to effectively set the level of micro used for the normal M28AI), and an AIx overwhelm option is available for people wanting to customise the difficulty more (by increasing / decreasing it over time).
Find out more information
- This forum thread contains summary information of M28AI updates
- A detailed devlog is available where I've noted my progress with M28AI and include far more details on updates made (e.g. the devlog relating to the v1 release of M28AI is more than 100 pages!). Due to file size issues, this is split between
a devlog covering pre-release to v103 and a devlog covering v104 onwards and a list of possible future changes.
Provide feedback
- Send me a message on discord (maudlin27), either via direct message, the AI development discord (https://discord.gg/jTvFqGKC) or alternatively there's a general AI feedback channel in FAF.
- You can also post in this thread
Where providing suggestions or highlighting bugs it'd be helpful if you would describe the issue, include the replay ID, and the time in the replay where the issue occurs.
Playing offline
If you want to play against M28 offline and can't access the FAF client (e.g. due to DDoS attacks), you can download the mod from Github and ensure the M28AI folder is saved to:
C:\ProgramData\FAForever\user\My Games\Gas Powered Games\Supreme Commander Forged Alliance\mods\M28AIThe mod files can be obtained from Github by downloading a ZIP of the code (and then extracting these):
https://github.com/maudlin27/M28AIWhile the game can be run offline either by clicking the offline mode from the FAF client, or running the shortcut C:\ProgramData\FAForever\bin\ForgedAlliance.exe /init init_faf.lua
Trophy holders
Introduced from v54, this recognises the person to complete a challenge with the latest version of M28, going to the first person to beat the highest M28 cheat modifier above a minimum level.-
Radde trophy - awarded for beating a 1.4+ resource (1.0 resource) M28 on a 15km+ mapgen
Current holder - DillyDally (for beating v101 at 1.4 resource on a 15km mapgen) -
Sladow trophy - awarded for beating a 1.5+ AIx (i.e. resource and build rate) M28 on any 5km or larger map (i.e. 256 x 256 or larger)
Current holder - Radde (v81, 1.5 AIx on a 10km map)
-
(Original post prior to M28's release):
It's very early days but I've started work on a new AI, with the highly original and inventive name M28AI. The hope is for M28 to become a more performant team focused AI (compared to M27 which was originally built as a 1v1 5km land map specialist before it had its functionality expanded bit by bit to handle teamgames and larger maps).M28 isn't released yet, but I figured I'd do a devlog for it similar to the one I did for M27 to record progress. In case anyone's interested in following its progress in more detail, the link to the devlog is below:
There's a lot of basic functionality that it needs to have introduced before it'd be in a state where I'd want to consider a release - my hope is that it'll be in a good enough state to warrant a release in 3-6 months.
See the below posts for updates on what has been implemented.
The first update implemented the following:- Land zone logic implementation (essentially the ability to read the map by dividing it into areas or 'land zones')
- Initial build order (hydro and non-hydro variants)
- Engineer expansion logic (i.e. building mexes and hydros on the map)
-
-
Awesome! Very cool if we're going to have two specialized M27/28 AIs, one focused on 1v1 and one on team battles. I assume since this is going to be team focused, it will also focus on larger maps than the first M27 AI?
-
@saintsaturday It'll probably have a similar focus of 5km-20km maps, but my hope is it ends up running faster meaning it won't slow down the game as much on the larger maps (and so can support them a bit better). I'm also hoping it will end up playing slightly better on 20km maps (or at least have the potential to) as some of the downsides of M27's approach to managing threats to its base become more apparent on larger maps, particularly where it ends up receiving a teammate's base on full share.
FAF balance isn't really setup for 40km+ sized maps though so I can't see myself doing much testing on these (since the optimal strategy is usually to get a game-ender which M27 should already try and do).
-
Brief progress update:
- Added ecoing logic, covering upgrading mexes and land factories to T3, building T2 and T3 PGens, and mass storage
- Added reclaim logic for engineers
- Added land scout logic, to provide a basic level of intel
- Optimised engineer logic that managed to achieve negative game speeds on maps like point of reach despite there being no land, air or naval logic yet
-
@maudlin27 could you point us to the commit that optimized the logic? I'd love to see what happened
-
@jip See below for a link to the commit:
https://github.com/maudlin27/M28AI/commit/82fbcfff116a59da09d39b653a1fb8b0d93bd4dc#diff-aacec693b8e05ca3fb26c9a47a43372cb938685e86dbf5604c3a50b1f4001d77My Devlog talks through the issue (section 2.11) but in short I've divided the map into 'land zones' (basically areas around mexes) and my engineer logic had a section for each zone where it would look for other zones that needed engineers and send any spare engineers they had to the other zones.
To make sure they didnt suicide by sending engineers along a path that would e.g. take them through an enemy base, they would check before sending the engineer that all of the land zones they would travel through appeared safe by getting the path to get to that zone, and then checking a pre-recorded flag for if that zone had enemies in it.
The performance improvement was to calculate at the start of the game the paths that would be taken from each land zone to each other land zone (rather than calculating on the fly), along with a slight limitation on the range of the logic, which resulted in a more than 99% decrease in the time taken.
-
Progress update:
- M28 can now manage tanks, skirmishers, and indirect fire units
- Expanded engineer logic to cover radar construction and tracking queued buildings
- MAA will be constructed and utilised
- Mobile shield logic incorporated
The M28 Devlog has been updated with more detail on the various changes.
As a reference point, on forbidden pass M28 has a c.75% win rate against DilliDalli, a 50% win rate against RNG, and a 0% win rate against M27, so its performance is slightly below that of v41 M27 on that map (although it's managing to do it without using PD, air, or its ACU, all three of which M27 typically needs to beat DilliDalli).
-
Can't wait for new DG meta where you give 6 players worth of units and eco to each M28 and see who wins
-
Progress update: Added the following:
- ACU combat logic
- Mobile stealth
- Enemy firebase avoidance (although still needs some work)
- TMD
I'll probably pause work on M28 for a bit to tackle a backlog of minor but time consuming to fix bugs on M27.
If anyone had wanted to try it out pre-release, it should be in a playable state on land maps and can be played by downloading from Git and coyping the M28AI folder into the FAF mods folder:
https://github.com/maudlin27/M28AIIt currently can beat M27 on theta passage but is outclassed on every other map I've tried, and performs marginally better than DilliDalli and RNG on the maps tried (a small selection of 5km and 10km land focused maps).
-
-
-
-
-
-
-
Progress update:
Most of my work (when I wasn't updating M27 for the rainbow cup) has been focused on having M28 function on maps with water - for now, without building a single naval or air unit. This took far longer than I expected despite using a very similar approach to how M28 handles land units, and I expect there will still be a number of issues to work through once I have M28 able to build naval units (although most of the hard work should be done now).- Shields should be built to defend against enemy T3 arti/novax
- SAMs should be built across the map if lacking in air control (which M28 will since it doesnt built any air units!)
- Added logic to consider locations on an island by island basis, so engineers can move from one island to another, and establish a beachhead on an island to try and take control of it
- Put in place framework for 'water zones', which divide the map up into areas similar to what M28 does for land zones, so that naval forces can be handled on a localised manner. These zones are much larger than land zones in size, and for now use simplistic pathing which I expect I'll need to revisit at some point if I can speed up the logic for this.
- Combat units in water are now managed, and will consider fighting other water based threats or to move onshore (if amphibious) to fight for an island
- Engineers can now reclaim and build underwater mexes
I'm also going to start using branches for future updates (so if anyone's running the AI off github, the main release version is likely to be more stable as sometimes when I'm in the middle of a major update Ill post the changes to backup them, which could lead to the logic breaking if trying out the latest branch)
-
Progress update:
Introduced most aspects of air based logic (main exception are bombers):- Torpedo bombers
- Air scouting
- Gunships
- Asf/inties
- Transports (and engi drops)
Have merged the air logic branch as it should be relatively stable. Asf/intie logic will need some refinement as M28 has a tendency to suicide them, but other aspects such as the gunship logic from initial results looks like it is performing slightly better than M27's version.
-
-
-
-
Progress update: The end of the beginning? or the beginning of the end?
A lot has happened with M28 in just 2 weeks, such that I'm hopeful that it's release date could be in a matter of weeks rather than months. To summarise what's been implemented:
- Naval logic, including building and upgrading naval factories, building naval units, and using naval units
- Novax
- Nukes
- TML
- T2 PD (although in a very limited/niche way comapred to M27)
- Ahwassa
- T3 arti
- Various small changes to improve its performance slightly (e.g. less likely to overflow mass, doing better on maps where it can only reach the enemy with air, logic for engineer order reprioritisation)
M28 now has all the core features that I'd set out to implement ahead of the release (some original points such as T3 bombers were pushed to be post-release but others like T3 arti and T2 PD that were planned for post-release have already been implemented). The main areas it needs work on are compatibility (making sure various niche scenarios work), and a new set of 'competitiveness' related goals I recently added - in short, making sure that while it may not be as good as M27 it should perform similar or better to the other custom AI when released.
The most exciting point for me personally though is the performance gains M28 is still suggesting it will provide compared with M27. When I'd previously ran it on the scenario I used for M27 for benchmarking (4v4 UEF on Africa) it was significantly faster, but that was before air and naval logic were added, and there was always the danger that I could spend half a year building an AI hoping it would run faster, only to find out it was slower. Now though it has almost all core features, and is still much faster (more than double the speed).
- For example, taking M27's 'benchmark' map of a 4v4 UEF mirror on Africa, M27 v67 took 167s to run the first 10m, and encountered stuttering for 20.8 seconds cumulatively.
- By contrast, M28 took 67s, and the cumulative time of freezes was just 0.4 seconds. The only main caveat to this is it freezes the game for a while (probably at least 1 minute) at the start of the game which is much longer than M27, but overall it should still be faster for games running 10+ minutes even after factoring this into account.
- Although not tested (as it's hard to produce an easily comparable scenario), I'm also confident that logic for T3 arti should be far lighter on the CPU than M27's approach which should help late game (as I suspect this was a likely culprit of some of the slowdown, along with M27's preference for swarms of T1 bombers).
-
That is great progress
-
M28AI's release day has arrived!
The main changes made from before were focused on compatibilty, (cpu) optimisation, and increasing its difficulty.
Compatibility
Tested M28AI with the following mods and map settings (usually this just consisted of a single game, so please let me know if you come across any issues):- Maps with water starts (including all-water maps such as Dreadnought Chasm)
- Survival maps
- AI Wave survival mod
- Flying engineers mod
- Norush game setting
- Low unit caps
- Crazy rush
- Nomads
- BlackOps
- BrewLAN
- Max AiX modifier (IIRC 5.9)
Optimisation
Big thanks to @Jip who helped me achieve a significant reduction in the time taken by M28AI to analyse the map at the start of the game. Previously M28AI was taking more than 2 minutes on 10km maps such as polar depression, with one of the functions being run taking c.102 seconds. With Jip's help this function's time was reduced to roughly 0.2 seconds, with M28AI completing its analysis in most cases in 30s or less (slower CPUs will take longer). The devlog contains more information and profiling for this.This also allowed me to make use of more accurate water zone generation (without increasing the analysis time).
Jip also helpfully provided code to allow M28AI to get the navmesh label (broadly, whether a particular part of the map is pathable by particular units) for a particular point on the map (which was needed for the optimised code mentioned above to work properly).
Competitveness
Various tweaks and improvements were made to make M28AI provide a harder challenge. As part of this I made sure that M28 was capable of beating RNGAI and/or DilliDalli AI on a number of maps (including those maps I'm aware of where they're capable of beating M27AI some of the time).Rather than try and achieve >50% win rate on all these maps, I instead just aimed for a single win, and did the AI version of 'save scumming' with replays until M28AI either won the replay, or creating a new game on the map resulted in it winning. Outside of Astro Crater (where M28AI is able to beat M27AI a majority of the time) I didn't test M28AI against M27AI. This is because I realised early in the development of M28AI it was too demotivating to watch it get crushed by M27AI (wheras against RNGAI and DilliDalli AI even if it loses often it's a close fought game, providing me with motivation to try and improve M28AI as opposed to giving up).
As a rough count this process involved 109 tweaks and improvements to M28AI (examples of more impactful changes within this include T2 artillery construction, destroying obsolete radar, and basic logic for building and managing bombers).
Since I've played a grand total of 1 game against M28AI (just to make sure M28 didnt take control of my units when it was my ally against 2 enemy M28AI), I expect it will need a lot more changes to improve its performance against players and become 'cheese resistant'. Almost all games were 1v1s (since they're faster to test) so although the code was all written with the aim of working in team game scenarios, I expect these aspects of it logic will be a bit rougher around the edges.
Please let me know if you have any feedback, suggestions, or encounter bugs.
-
After my record for the longest version (in development and code length) ever comes my record for the shortest version ever (a 1 line change)! Big thanks to Relent0r who mentioned M28 wasn't building any tanks, which was due to a bug that arose when one of the common debug options I use (showing unit names) was disabled.
-
v3 - Starting a new campaign
- Added preliminary support for campaign maps - currently I've only tested on the first FAF mission (Black Day), and I expect on many maps it won't work properly (due to one of the bugs identified below potentially completely breaking M28 I decided to release earlier than planned as a part-hotfix update). My aim will be to improve M28's performance over time (e.g. currently 1.5 AiX M28 struggles on easy on black day if the human player does nothing). As part of this, M28 allows an AiX on campaign maps of up to 10.0 AiX for the M28 teammate, and will take its share of initial units at the start of a game (since it's not possible to gift units to an AI ally in the campaign)
Note - if playing with M28 as a teammate, a higher unit cap is recommended. - Improved the basic bomber management logic (idle bombers should return to a safe location, large numbers of bombers should search further away for enemies)
- Improved build order on certain maps (e.g. on maps where the only mex adjacent factory build locations are blocked by reclaim, M28 should now try and just build the factory in a 'clear' area so it starts construction sooner)
Fixed a few bugs, including:
- M28 potentially not working on some maps with water
- PD being way too far away from the base (more an issue on 5km maps)
- Added preliminary support for campaign maps - currently I've only tested on the first FAF mission (Black Day), and I expect on many maps it won't work properly (due to one of the bugs identified below potentially completely breaking M28 I decided to release earlier than planned as a part-hotfix update). My aim will be to improve M28's performance over time (e.g. currently 1.5 AiX M28 struggles on easy on black day if the human player does nothing). As part of this, M28 allows an AiX on campaign maps of up to 10.0 AiX for the M28 teammate, and will take its share of initial units at the start of a game (since it's not possible to gift units to an AI ally in the campaign)
-
v4 - Campaign and other enhancements
A bunch of bugfixes, tweaks, and some improvements specifically for campaign maps:- 24 bugfixes. The more generally impactful of which relates to the mass/energy stall logic which should now be much more likely to only pause some things rather than everything when stalling
- Quantum gateways and RAS should be built for campaign maps and AiX modifiers (not 1.0 M28 though since I see RAS as too inefficient at that level)
- Reworking of how buildable locations are tracked - originally intended as an optimisation it ended up taking far longer than the previous approach, but I decided to leave it in since it is more accurate and my hope is that it makes late-game major slowdowns less likely than the previous approach.
- Optimisation of nuke targeting logic to reduce how long it can take (at the cost of being less likely to edge-nuke targets), and a number of other functions
- M28 can now capture campaign objective targets. So for example it is now capable (without any AiX boost) of completing FAF mission 2 on easy on its own unaided (i.e. with the human player afk for the entire game).
- Roughly 32 other tweaks/improvements, a number of which are aimed at having M28 better handle very high mass scenarios.
Acknowledgements
- Hdt80bro – helping me find a better way to confirm if a map is a campaign map, and clarifying how to hook orders such as IssueGuard
- Grandpa Sawyer – helping me debug an issue with the base AI taking control of my units (including the IssueFactoryAssist() order being the one I needed to hook)
- Jip – Helping with the same bug as the above, highlighting I was hooking a file that only existed on FAF develop (hence why it wasn’t doing anything for non-FAF develop games)
- Fearghal – replay highlighting major late game slowdown for M28 on Astro Craters Rich
- Wingflier - replay showing M28 losing at 1.5 AiX
-
The campaign AI works pretty nicely, the biggest issues I've run into so far is the AI suiciding to the PD on "Golden Crystal". It happens everytime I tried to play the map, so I think it should be fairly easy to reproduce.
The AI would send their com to the bottom left of top left, tank PD fire then eventully retreat. Then after will they would go back this will repeat. The com normally dying trying to overcharge the PD.
-
@savinguptobebrok Thanks for flagging, I'll have a look for the next version (v7)