• Register
Post news RSS Dev-Blog #6 - Skynets Little Brother

Okay, the AI in Timeless War will not be as smart as Skynet you know from the Terminator movies, but this article explains the current development of AI players and a brief preview of what you can expect in later states of the game.

Posted by on

Hey Guys,

Have you ever wondered how the AI of a RTS game works? After more than one month of hard work, reading several articles and days of work trough trial and error method, I have a slight idea what professional programmers are going through. I promised to make a dynamic and challenging artificial intelligence... And now I am confident that I can reach this goal. To this point, the AI is capable of analyzing all its buidling options, create a decent economy, react to missing energy, follows a build order in which it can skip certain points if priority changes, build troops and attack proper targets. I recommend watching the new gameplay demonstration down below. ;)

For this Gameplay Demonstration I reduced the cargo of the Midas Miner to 1000 so the resource income is more frequently. Before the gameplay stumbled for up to a minute because of the lack of resources which was anoying to say the least. The most noticable change however would be my test-map redesign.

You and the Machine vs the Machine:
Even thogh the AI currently is incapable of team play, it is exactly what I will aim for in the future. An AI player will as close to behave as a logical human player, maybe with some intended errors caused by randomized variables, as possible. Since multiplayer is currently far away, it is the best choice for now. Overall I think the teamplay interaction between human and artificial intelligence in Timeless War will be outstanding. The player can give commands to the AI via chat (once the chat is enabled) like this: "Bob I need res!". Bob would be the AI teammates name, most likely you will be able the AI however you want in the lobby. First of all it would split the message into bits, before analyzing it. After that it would search for its name, in that case its "Bob". Then it would try to understand what you want. "I", "me" or simply none of those two would always refer to the one who sent the message, in this case its the player. To this point it recognizes that the player talks to the AI player named Bob. After that it could find keywords like "need" or "defend", "attack" ect. to determine what should be done next. In case of "resources" or the short form "res" would then mean what the player needs and the AI would respond accordingly - if it has enough resources to offer, it will send maybe 5000 units of Ore. Either way it will send a message as feedback. The fastest way could be like "need res" in which any AI teammate could send Ore if possible.;)
This stuff is easy to code. However a complex conservation will not be included of course. ;)

How the AI works:
Some of you might be AI programmers themselves for your own project. If you have no experience, you will face the same issues as I did. Where to start? For my setup I used the regular player component which I called PlayerInfo. So normal player is the base for an AI player which can come handy if you have a coop mode in your RTS game where a friend can jump in any time. Then the hierarchy starts with a component called AIInfo. It controls input and output. For the input I use several components, derrived from the AIManager:
AIInputManager: This is the most important class as it preparing the AI for the game. It will first analyze its tech tree based on the starting build or units and registers all possible upgrades, construction options and finally categorizes them for easier as well as to minimize computing efforts. Then it searchs for an appropiate strategy that was either set in the lobby before or it will pick the next best at random. After that it is setting up the output managers. During the game this component will also be responsible for chat communication with human players.
AIResourceManager: Resource management is always a critical part of programming an Artificial Intelligence, especially in complex games like this. In Timeless War this component keeps track of the resources and calculates the priorities for economy, power and determines what harvester should be assigned to which refinery or resource field.
AIProductionManager: The AI was designed to later build new outposts and bases, given the circumstances. Since each base, outpost of group of units (squads) is controlled by a smaller output script, it was neccessary to coordinate the use of factories before everything ends in total chaos. So this compnent keeps an eye on the production queues while assigning units to their squads, structures to their base or outposts and aborts construction orders if a vital object is missing and not enough money available to complete it.
AIEnemyManager: While fighting against AI players, it will constantly watches you and look onto your threat level. The threat level increases depending on what the opponent builds. If you build up a large army, the AI tries to counter it, if your base is getting bigger and bigger, the AI tries to rush for higher technologies and economy as well to successful engage you. But this script also assignes targets to squads which will then carry out orders. Later, once super weapons and player powers are introduced to the game, it will also manage their usage.


After the AI gathered information abouts its surroundings, it tries to make decisions accordingly. For this purpose I use output components that are also derrived from the AIManager class. But unlike the input scripts above, the output is used in seperate game objects.
AIBaseManager: The most important output is this component. When an iteration is triggered, it uses the inputs data to calculate the priority to either build up the base from a preset build order or by the most needed, builds power plants which are not part of the build order or refineries. In addition it is also responsible for placing structures that are complete. Later its purpose will be extended since base building is different for every faction and it needs to deal with builders just as well as it does with a construction yard. Also placing defense structures is not implemented yet, as you can see in the video above.
AIOutpostManager: Currently this component is not implemented yet, but in theory it works like an extension of the AIBaseManager. It will control the units that later contruct the outpost. The primary purpose of an outpost might be for gathereing resources in a location that is not suited for building up an entire base. Or it the AI will create one to siege a defense player or launching sneak attack.
AISquadManager: The AI groups units into squads. Each squad has a primary, secondary or tertiary purpose depending on the units that are assigned to it. For example the AI uses a bunch of aircraft to attack careless harvester of you, but if you have a few anti air units to guard them, it might switch to attack silos or power plants instead. Why it switches Target? It uses the units sight range to determine if threatening forces are in sight of this squad. If thats the case the squad AI will probably choose another more lucrative target, or find a way around, or simply retreats. The latter can happen if the AI player decides to use hit-n-run tactics to lure you into a trap. But if the AI is put in defense, the squads can be assigned to guard harvesters or the base. All of this possibilities are making the AI player less predictible and therefor more challenging to even more advanced players.


Base Building for AI and Humans:
Since the last update I made a major change to the structure placement system. Before you were able to place it anywhere you want unless the construction site was blocked by other structures or obstactles. Now the position is clamped in 10 meter steps. It makes a big difference for the AI as it checks is construction site around nodes stored in the AIBaseManager and it would be easier to check int instead of floats. Besides that, it is an easier way of checking if the players cursor is close the build area or not and the creationg of visual effect for the spoken area would be simpler as well. Just the 2 cent from the programmers perspective. Other than that, it probably makes no real difference for human players.

Thats it for now. Thank you guys for reading this wall of text. There will be more about the AI published in later dev blogs, like its tactics and difficult levels. But for now the AI is suitable enough which brings us closer to the first pre-alpha release. I would like to know what you think and some feedback. ;)

Timeless War on Facebook
Timeless War on Steam


Informative article, definitely will help future modders in need. :D

Reply Good karma Bad karma+3 votes
Medusa_Zenovka Author

Thanks. The system was designed to make it easy for modders to modify the AI for their mods. In most cases a modder doesnt even need to tough the AI at all, unless the the mod-dev decides to heavily twist the gameplay. :D

Reply Good karma+2 votes
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.