Following the recent Supreme Computer Cup I was inspired to have a go at developing a basic AI for FAF. As I had zero experience of coding in Lua, I thought at the same time I would write down things as I learnt them to have both a guide for other people interested in getting started in developing an AI, and a dev log for the creation of my AI.
See below for a link to the current AI development guide and devlog:
The current AI has been uploaded as a mod, and the files can also be accessed from the below:
I've copied the current overview from the guide below:
This document is intended to do 3 things at once (meaning it does none of them very well!):
• Act as a guide to people new to FAF AI development, including collating any other useful resources out there on AI development
• Be a sort of dev log of my thought process and development steps for creating my first FAF AI, with extracts of code thrown in
• Form my main ‘todo’ list for further developments of my AI
If you see any errors, or have any comments or suggestions (in particular any AI developers who read this since you’ll probably know better/easier ways of doing things than the methods I’ve chosen) let me know and I can update the guide where relevant.
If you’re here for useful resources and/or details of how to write AI and don’t care about the dev log aspect then just skip to section 2) Setup and background and section 4) Index of useful functions, and/or browse the index for points that may be of interest.
In terms of the dev log section, if you start seeing lots of yellow highlighting/square brackets you’ve reached the end of the dev log part and the start of my todo list of things I’m planning on working on next.
Latest changes (v5) summary:
v5 changes - these were mostly about the ACU, making it more aggressive and less suicidal
Having only started following the FAF forums and news the start of this year I'd not come across the PC election before, but one thing that's surprised me is just how long the process has gone on for. To summarise the timings for the PC election that's almost now finished:
So essentially, 3 months taken up with the PC election.
Regardless of whoever wins the current election, I'd suggest shortening this period significantly, as 1/4 of the PC's time will potentially be in 'election mode'.
I'd therefore suggest allowing 3 weeks for candidates, and then 3 weeks for voting, to halve the time involved overall, for next year's election, while still giving enough of a period to allow most people who might be on holiday at some point in that time to be able to stand and/or vote, without having the election go on for so long.
I'd also be curious if anyone has stats on the timeframe of when votes were cast, as I suspect they will be weighted significantly towards the start of the voting period (which would give further support for there not being a need for a whole month to vote). If this isn't the case and votes tend to be evenly spread over the time period (or even weighted more towards the end of the voting period) then it may still be worth retaining 4 weeks for voting.
I’d suggest highlighting the point about being able to join multiple queues in the news post when its released (and possibly even the game loading tooltips)-I doubt I’m the only one who assumed you could only be in one queue at a time.
I fail to see how anyone could argue astro craters is like sim city with a straight face, even allowing for the way in which many people here (as shown on this thread amongst others) seem to look down with disdain on those of us that play such maps (even though they appear to be the most popular types of maps on FAF, at least for custom games). There's more variety in the gameplay on astro than the majority of 1v1 maps on ladder for those not in the highest ratings , where in most cases for ladder it's a case of 'T1 land spam or die' (with having a good APM being far more significant than making good strategic decisions). Perhaps you've just not played enough astro games to appreciate the range of strategies on it (since if you're using your main profile you don't appear to have any games on the map).
I'd have also thought a focus on "the kind of players that faf wants to attract" (in the context of not wanting to attract people who don't like high APM play) very shortsighted. The more people who play faf (in a non-toxic way) the better its longevity/future prospects. Just using myself as an example, while I may play mostly astro I also sometimes play some 1v1 ladder. I doubt I'm the only person who has a favourite style of map such as astro/gap/setons but who also likes to sometimes play other maps or game modes. If all such players were to leave faf because we're 'not the kind of players that faf wants to attract' you get fewer people playing those maps/game mods you approve of such as 1v1 matchmaker.
I also don't understand the logic proposed both here and in the PC election thread for removing the global ranking system. If you had a team of rank 1500s on astro or dual gap against a team of rank 500s (global rating), almost every time the 1500 ranks would crush the 500 ranks. While you may have a greater variance in ability (especially at lower ratings) than with a 1v1 rating, the rating is still a far far better guide to how well someone will play than having no rating at all. Removing the rating just seems like a way of punishing people who are playing maps that don't meet the personal preferences of those suggesting its removal, especially given how bad opti-balance is at balancing a game when you have newer players. As for manually balancing based on knowledge of players, the majority of my games have been from where I've hosted an all welcome lobby, but on average I won't recognise the names of the majority of people who join, and even of those whose names I recognise I'll only know how well some of them play/favoured strategies (there's probably only 4-5 people I could think of off the top of my head where I know how they tend to play and how good that style of play is).
Going back to the OP, while I'd like the idea of an option to play 'lower APM' 1v1 maps (as opposed to currently where I can be given a 1v1 map on a map that's normally seen in the custom lobby as a 3v3 or 4v4 map), and think it would be a more gentle introduction to newer players, if implemented it'd need to be as an option on the existing matchmaker (e.g. you check the box for if you want to play 'new player friendly only' maps, and/or if you're open to playing the full map pool), or else you dilute the number of people on matchmaker even further.
Since as I understand it something a bit like this is meant to happen (I don't think it's working well if it is though), it may be easier to just improve the current system of starting with a small map pool and then adding more complex maps as rating rises.
The 'stone age' mode also sounds like an interesting idea for teaching the gameplay style that's required for 1v1, although I'm not sure how best it would be implemented (if as an option, people may just not choose it and/or it splits the pool of people queuing too much and makes finding games harder; if its as a tutorial mode with AI then people may not be aware of it and/or the AI may not offer enough of a challenge; if it's forced for the first x games then it could put off people who want to experience the full range of options and not be limited to the first tier).
After the recent AI tournament I was inspired to have a go at experimenting with AI development to see if I could come up with anything remotely functional, and figured I'd also document some of the steps in doing it to help anyone else who is interested in starting out (assuming I make enough progress for such documentation to be of any use).
Unfortunately I feel I've failed already at a basic first hurdle, and wondered if any of the AI developers might take pity and help me out?
I thought I'd start simple, and just try and adapt an AI's initial build order. I used the MicroAI as a starting point since I understand it's intended for public use for such a purpose:
My presumption with how the AI relating to the intial build order worked from looking through the files is as follows:
So, as a simple test to check if I was right, I changed it so the first item listed was 'T1EnergyProduction', followed by 'T1AirFactory'. However, on loading up the AI on an (offline) custom game, it would still start by building a T1 land factory.
Other changes I made seemed to have some sort of impact (e.g. to try and change the attacks the AI was sending I started messing around with the "MicroAILandBuilder" part of this file, along with the PlatoonTemplates\MicroAITemplates/lua file, which resulted in the AI massing an army of land scouts to attack with - not quite what I was after but at least a noticeable change! So I don't think the issue is with the changes I'm making failing to be reflected in the mod I then load in the offline FAF skirmish)
Searching for articles that might give some basics of how the AI works I found the below which has a section on AI scripting (in the context of custom missions) and a separate guide which gives an overview/diagram of how the AI works:
I've also been able to locate the core game files that are part of FAF (i.e. the Lua file within Supreme Commander Forged Alliance\gamedata), but I couldn't find anything else from a skim of these forums and Discord.
Is anyone able to help either with my query, or alternatively if there's any material aimed at beginners getting into FAF AI development that might explain some of the basics?
Edit: Thanks for the help everyone - now resolved the issue
Edit2: See my more recent forum post for a link to the current version of the guide:
I thought it was a valid tactic to ctrl k to kill the enemy com-it stops them gaining vet from killing you and surviving, and from being able to run away from you if they have some spam to block you. I’ve done it myself a number of times and would feel very aggrieved to be banned for it (until now id presumed it would count as a draw). If the actual issue can be fixed then great, but if not it shouldn’t be punishable because it should be a legitimate tactic to obtain a draw instead of a loss. Id be happy with a punishment that just involved a manual rating change as well since that would just be an awkward way of fixing the issue.
One query though-some have suggested pausing and offering a draw. how do you get a draw? One game my opponent had to leave so we agreed to have our coms shoot each other to death to draw; is there a better/easier way?
With a larger player base I'd be in favour of such a matchmaking idea. My concern though is that you'll only end up with a small number of people queuing at a time (except for very busy periods) similar to the existing matchmakers, and you'll inevitably have some people who are very good at whatever custom mode is highlighted compared to a new player.
That said, one of the biggest issues I have with both the 1v1 and 2v2 matchmakers is that the maps are too much like hard work. That is, if I get a 1v1 map there's a good chance it's some large sprawling map with mexes everywhere that requires me to do a crazy amount of actions a minute to keep up with t1 land spam being mandatory (except on huge maps or naval ones), which ends up being stressful not fun. In 2v2 from what little I've played it's similar, but with the added pressure of a teammate who will be angry that I don't perform as well as they'd like.
I think this is a large part of the reason games like gap, astro, dual gap, pass etc. are popular - you dont have to focus on as many areas of the map at once, and so there's more chance to just have fun, and it's alot easier to get into as a new player. Even setons and isis mirror this to a large extent (ignoring the players who will make your life miserable if you don't conform to the expected way of doing things when starting in a particular slot).
Therefore I like the idea of having lots of different 'fun'/different types of modes that will make a change in gamestyle from the standard 1v1, especially if they include vs AI challenges, I'm just not sure how to solve the issue of too few new players wanting to do it leading to those that do try getting crushed by pros. One possibility might be to showcase it on the news page (e.g. you have a different mode each week, and the news page features it prominently).
I’d suggest taking a screenshot and making a report whenever you come across this so they can be banned/suspended.
On a related note I’m happy to volunteer to go through reports if it would help such issues (and other breaches of faf rules) be dealt with quicker/if you (faf moderation team) need more resource to deal with reports.
Thanks, I'll reflect the correct case usage of Lua in the next version of the guide (I'll probably update it whenever I release an AI update so the two are in sync)
I only just realised that when a new version of the FAF client is released, there's no obvious notification of this, other than a strange icon in the top right that doesn't seem to bear much relation to the point. Since others have also posted (e.g. in the thread asking for feedback from new players) of not being aware of this, my suggestion is simple:
Until I saw a post from someone mentioning about some icon in the top right that you had to click to update your version I was left puzzled by the news that a 2v2 team matchmaker had been released yet no 2v2 option was showing up as an alternative to the 1v1 and custom tabs, and I doubt I'm the only one.
Summary of points I'd written before since I don't want to retype:
I joined a few months ago, some of the things that almost made me quit and things that could be done to improve things:
-Toxic players - not much you can do, every multiplayer game has them
-Specific map expectations - having a high level summary/guide of expectations for some of the most popular maps and expectations of what you do if you start somewhere could help
-1v1 - initial matchups were horrible, start new players out against low rank players instead of high rank players
-Being kicked for being grey - Rank/game quality should be based on the displayed rank, not the 'trueskill' value. E.g. a rank 0 with 4 games in multiplayer is seen as similar quality to a rank 1000 with 200 games. Maybe if it was based on the displayed rank (e.g. rank 0 is treated as rank 0 not 1000 or so) then people would be less likely to kick newer players
v4 changes (in reality v2, but when I uploaded the mod on its first release I had to rush out a couple of hotfixes where I'd forgotten to remove debug logic and accidently introduced a bug that affected all games!)
I've also updated the guide to reflect speed2's comments (as well as a couple of other minor points/sections, such as a bit on uploading a mod and some tests that I now run before uploading)
@FtXCommando Your example is actually a difference in tactics that 1v1 doesn't have available though :p.
I thought I'd have a look at my recent astro and 1v1 ladder games to check I'm not going off faulty memory to illustrate what I mean when playing at my rank (around 800 in 1v1 ladder; 1400 global although opponents ranks will vary wildly due to being all welcome games):
Astro last 5 games - notable tactics used by winning team:
1v1 last 5 games (winning player):
I had to go back 8 games to find one where initial T1 land spam wasnt a winning tactic in 1v1, and it's only if T1 land spam isn't enough to win the game outright that the game opens up enough to allow other tactics. My memory of being a new player to 1v1 was also similar (although then the games would end before T2 because I'd usually be the one dying to t1 land spam)
Probably veering a bit off-topic now though. My initial experience of looking for games I wanted to play was also similar to that of Ask-a-holic's - I wanted to play a game, and was tired of waiting (although I was also getting tired of t1 spam), so joined custom games that seemed popular. Initially that was Setons, but I found I didn't like how games would typically go on for a long time, and could be decided a while before actually ending; I tried dual gap briefly, but struggled both due to not having a great CPU at the time and not liking how the large number of players meant what I did had far less of an impact; Then although put off by the look of the astro map I eventually gave it a try.
However, I'm not sure I'd see the 2v2 matchmaker as a good option for a new player wanting to learn the game. From my own experience it involves very long waits (much longer than 1v1), plays very similarly to 1v1, but you've got the added worry of a teammate being more likely to get mad at you for not playing well. By contrast, dual gap shields you from this due to the large number of players, while astro does to a lesser extent by allowing your teammates to easily take over your old base.
I think the casual party game matchmaker idea (linked by harzer earlier in the thread) has more potential for working, even if it wouldn't be the best way of teaching a new player how to play 1v1 ladder, since it could (if it proves popular enough to allow quick matching games) allow variety in game styles, access to a game where people are more likely to be inexperienced (and hence people may be more forgiving of mistakes/learning the game), and sounds like it'd be marketed as a casual option (so again more relaxed/about having fun).
I'd also favour making 1v1 matchmaking more friendly to new players by increasing the extent to which rank determines the maps available. E.g. players with fewer than a certain numbrer of games and/or below a certain rank (not sure on the best thresholds, e.g. 10 games and <=400 rank?) only get 5v5 maps, and those maps are weighted towards ones with fewer lines of attack/more choke points, lower levels of reclaim, and lower levels of expansion (i.e. lower APM maps).
Then as the rank and games goes up, the larger and harder maps start getting added to the pool (more open style maps; more reclaim; more expansion points; navy based maps; larger sized maps, etc.).
That way, new players should have an easier introduction to the play style, and will still need to get to grips with the basics of using t1 land to do well, without being as overwhelmed.
Another point as well to helping the new player experience - at the moment there are tutorials with build orders for specific maps intended presumably to help newer players learn how to play. However, those maps aren't in the ladder pool, meaning they're of significantly less help to a new player starting out (potential solutions being to include the maps in the ladder pool even if just for lower ranks, and/or pick a couple of maps that will always be in the ladder pool and refresh the tutorials for them, although that would involve more work).
Tried getting games on the2v2 matchmaker yesterday (party of 2) but it involved long waits - at one point there were 12 people queuing at the end of the countdown so I thought we should get a game but it ended with all but 4 of us getting a game (me and my teammate were negative rank so I presume everyone else was very high rank). The couple of games we did manage we were completely crushed though, so it could just be the issue with too few people queuing meaning it's not possible to find balanced games. However, after waiting through several cycles of matching with no game I'd prefer any game to no game - is it possible to increase the range allowed for a valid match each time you fail to be allocated a game?
Also updated the guide slightly to add details of the AI development discord channel in FAF (separate to the main AI development discord), and a couple of common hard crash errors
Agreed that custom campaigns to teach specific lessons with each mission would be the best way of learning, but it'd also presumably require a hefty amount of investment by someone to set up.
In the event that something like that was considered though, a couple of ideas I'd have of lessons to be imparted via this to add to the list:
-Player given land factories, a few mexes, access to only T1 land, and told to break a turtle who has lots of T1 pd and a couple of T2 pd (i.e. learn that in large numbers T1 arti can overwhelm a couple of T2 pd and is a good counter to T1 pd, to encourage the use of aggressive land)
-I'd adapt the 'overflow to ally to let them build experimental' idea to one where you get to build the experimental (mainly to avoid teaching players to overflow which is a bad habit while still getting the 'experimental payoff' benefit to make things interesting) - e.g. you have access to engineers, power, mass extractors, mass storage, and a land experimental blueprint only, and just have to break a turtle base with the experimental before the enemy constructs a T3 artillary (to put a timer on things). It's on a fairly small map, and you're told the enemy won't expand. The time is set such that you have to upgrade your eco optimally (T1 mexes, T2, storage, T3), manage your power to avoid power stalls, and make use of available reclaim, to complete the experimental fast enough to stop their artillery.
i5 11600k (no overclocking) with 16gb 3200mhz RAM took about 13m7s to run the replay (pausing the game at the start, setting +10 sim speed, then starting timer and unpausing)
I'd be ok with a small health drop (e.g. 100 or 200) or stealth energy cost increase (e.g. -150 instead of -60), or a very small damage nerf (so it stays above 2.5k). However nerfing the damage so that it can't take out a UEF T2 mex would be too much.
Either way IMO Aeon is more deserving of a change (small boost) than cybran a nerf.
What about having these guides linked to in the Tutorials section of the client? (in addition to the current build order tutorials and link to heaven videos)?