I thought I’d post this up guys, some of you may know I have been obsessed with studying RTS mechanics lately and just today I came across one of these most helpful and informative videos on not just AI theory but also bits of pseudo code that help you understand how to maybe implement this in Unity which I’m definitely going to look at for my game.
I consider this recommended viewing even for newbies who are wondering what actually goes into RTS AI as there are so few good tutorials on this topic. I also did a bit more research on the statements itself that he’s using in his code and I hadn’t realised that Unity uses shorthand symbols for the code that they’re using.
and = &&
or = ||
Suddenly when I looked that up their code made absolute sense lol, veteran programmers will know this obviously but I facepalmed. Also worth pointing out is that they have a script on github to show the full thing if people are interested in that.
Im kinda surprised how ‘hardcoded’ it is with simple event-style conditions, I wouldn’t approach this problem like this at all, but it’s interesting, and while making it less flexible I guess it’s also much simpler.
Also what’s up with almost 30k line script? Or is it just pseudo code for explaining logic?
I think it’s the actual code that they used for it and there seems to be a whole community that likes tinkering with the AI themselves and modding it. I just found it really interesting because people tend to avoid the topic of RTS’ on here as well as in tutorials so I thought I’d post it up.
The distance checks are very helpful for me because I was wondering how to do the AI building placement so it’s given me some ideas.
@frosted You say it’s higher level scripting but honestly it isn’t, I was actually surprised at how simple each bit of code is, it looks like for the most part exactly like the AI developer says in the video it’s really just if statements and so on. The only reason it looks high level is because of the sheer scale of it, the guy who worked on this is just making sure to take into account every factor or decision that an AI might need to make in the game and planned the code accordingly.
I’m actually doing the same with a villager script that I’ve done, it’s made up of nothing but booleans and if statements but if you’d look at it without breaking it down you’d think it was some amazing algorithm or something lol.
It seems like it is, for example - how is individual unit position selected during an attack?
From a player perspective, how the AI chooses what to build, etc, seems more interesting, but as a programmer, I’m more interested in how the details work.
Does the AI run off of influence maps (or similar)? How does it assess the map overall? Does it issue commands using the same api as player (for example, attack move or does it individually target)?
It seems like most of the output from the code is “set goal” or “build house” - but whats the logic for placement? How does it select the builder? Etc.
The scripting interface might have hooks for more of that (it mentions mill placement logic) but I’d like to know more about how all of those details work.
I dunno, that’s a bit beyond me, I think though if it’s mainly made up of if statements it could well be that the scout at least just randomly wonders and then there’s a trigger of some kind when an enemy building is discovered, that’s how I’d probably do it.
The video also goes into a lot of what I’ve been thinking about where we don’t have truly ‘learning’ AI yet, the AI in AOE2 really is just a set of values, some AI in other games definitely do cheat and they have an entire knowledge of the map and so on before hand which is why AOE2 is such an interesting game to study.
As for the builder itself, this is pure speculation on my part but the villager may well have it’s own logic when it is created and it searches out the buildings which is why the AI can micro-manage so well compared to a human being. As I’ve mentioned I’ve created a villager script and it they automatically search out building sites to build on, after that all you need to do is have the AI place buildings randomly and then it makes a pretty convincing enemy.
Selection and unit ordering is definitely going to be more tricky though, I haven’t yet wrapped my head around that. I also studied halo’s AI and found out from other people here that for that sort of thing they likely have raycasts shooting out constantly and maintaining a list of some kind of the players or enemies they pick up.
This obviously isn’t the case for AOE2 so I wonder how they handle decision making for that as well.
While video is highlighting on using if / then statement, this is very similar, as behavior trees.
Do A if condition are met, otherwise do B. If B is met, look into further options, etc.
It also appears, it has micromanagement, if individual agents and awareness of other units near, allowing manage nearby units, to act collectively, like killing boar for example, yet keeping units alive.
Using If is greater and / or smaller, when other conditions are met, this also mimics Utility AI, to trigger desired behavior.
Oh we have it, the truth is we don’t want it, people always think they want it, but then, when applied and it start doing exploit, they are like “nah, I need control, else gameplay become shitty”. SO what we do is we fake learning, by giving AI imperfect information with appropriate behavior to respond to “learnt” (gathered) data.
Expert Systems aren’t “terrible” by any means, they’ve just been dramatically superseded by other techniques that can leverage the fact that computers hardware has advanced significantly in the last two decade.
I don’t even think that expert systems have been ‘dramatically superseded’ really. The big problems with expert systems in game ai are:
You need to write the AI pre-release, and there aren’t any actual experts yet for competitive games.
It’s rare that developers actually want competent AI. People don’t generally like losing to AI, so you’re generally looking to fake the appearance of basic competence.
In RTS for example, pre-release you probably don’t know what the most competitive build orders are going to be, or what the counter builds are going to be, these need to develop post release.
Another example: you don’t really want an AI to micro their units, despite this being pretty easy to implement because the AI can perform super human micro that’s frustrating to play against. So if there’s unit micro, it always needs to be handicapped. This is especially important in high APM games like RTS, but also applies to shooters (do you want to play an FPS vs a bot with perfect aim?).
Game AI is a really weird art, and the only time you have the goal being to make a truly competitive AI is when doing ML research like alpha go.
Game ai is only weird because it’s badly name, it’s not meant to be intelligence but a performance, interactive choreography or digital acting would be better naming. The designer should always ask what type of experience is the goal, only then design it.
Yeah but the joke in ai is that when AI become practical it stop being called AI relational database was hot topic in AI, now if you call that AI you get laugh at!
NERD!
AI is when it’s magic and he does simili intelligent stuff we don’t understand yet, DNN is on the verge of not being “AI” anymore, as soon as we realize how it’s a soft statistical database, and can actually read and write directly to it.
And that’s true for all new tech, there is the mystical phases full of over inflated expectation, waking up to the limit, and the absolute rebranding to meet stoic standard of professionalism … Like we renamed promptly blockchain to DLT as soon as serious business get a hold of it …
I take the stance that when talking to laymen, to streer away discussion of game ai from intelligence to give a sense of what the craft really is about. Especially for onlooker you don’t know better.