CRustAIcean & SpringAI Release (0.1.0)
CRustAIcean is an AI for Beyond all Reason’s Recoil engine, and more generally for the SpringRTS engine. It uses the engine’s provided C bindings, generating the proper calls via Bindgen
. SpringAI-rs
then takes these bindings and turns them into an easier to use interface for the implementing AI’s. SpringAI-rs-macro
works magic, allowing a programmer to bind to various events like update
or enemy-created
via a very easy macro call like:
|
|
At the moment CRustAIcean is a reimplementation of SimpleAI. Below is an explanation of what it does and how it implements these actions, and concludes with future goals.
If you want to try it out then download and run the installer above (FYI: This is for Windows only currently), or you can copy the SpringAI example source and bash together your own AI! Warning: it is still a work in progress, so there isn’t much documentation or organization yet.
AI Init
CRustAIcean starts at the init phase. As the engine loads the game it calls init on each AI to allow it to perform any intensive initialization tasks before the more time-sensitive playtime begins. CRustAIcean uses this time to create organized lists of the various units it knows how to build. These lists include factories, constructors, extractors, generators, and turrets. Everything else is either stored as an unknown building or an unknown army unit.
Starting Build Order
Once the game starts and the command is available to give orders to, CRustAIcean gives the command to build 3 extractors in order to begin building a good economy.
Once this is done we fall into a standardized build order for the rest of the game is as follows:
- If energy is less than 75% of the maximum, build a random generator
- If metal is less than 30% of the maximum, build a random extractor with defenses (the commander does not do this to avoid running out into enemy territory for a quick loss)
- If supplies are higher than that:
- 20% of the time, build random turrets
- If metal and energy are above 75% of maximum, build a random factory
- 10% of the time reclaim and repair
- 40% of the time build random buildings that are unknown
Each building is built around already existing units & buildings to keep from spreading too far too quickly. The only exception are extractors, as those need to be built on specific spots around the map. Instead the nearest extraction spot is selected.
Factories
Factories are extremely simple; they have 2 states:
If metal is greater than 90% of the maximum:
- Build constructors
Otherwise:
- Build constructors 20% of the time
- Build random army units 80% of the time
In theory this should give you a sizeable army most of the time, and when resources are near to overflowing the additional constructors allow you to expand your reach and use up your resources a little faster. Currently this doesn’t quite work however, and I’m sure it’s something I’ve mistyped. The AI almost always is overflowing resources, and as such it always build constructors. There is still work to be done balancing the build order for sure
Army Units
Army units are set to move between all team units to be available in case of enemy attacks, leading to a very decentralized military.
Combat
There are 3 different responses to combat situations for mobile units.
Commander:
- If the commander’s health is above 30%, then the commander will D-Gun any nearby enemies
- Otherwise the commander will run away towards nearby friendly units
This means that the commander will usually be building various things, but if it happens to run into enemies it will blast them into a million pieces. Only if the commander begins to be overwhelmed will it retreat.
Constructor:
- If the constructor’s health is above 90%, then it will reclaim any nearby enemies
- Otherwise the constructor will run away towards nearby friendly units
With this set up individual constructors will retreat from combat in the hopes of survival. However, if the constructor is not the one being targeted, or if there are multiple constructors nearby all repairing each other then it will not retreat because it is more useful assisting the combat effort.
Army units:
- If an enemy comes near a roaming army unit, then the army unit will attack
- Every so often all army units will attack any enemies within sight on the map
In practice this means army units will collectively protect everything, but only attack directly towards the enemy when a critical mass of military units has been built.
Errors
There are, however, some ongoing issues with this current iteration of the Ai, some inherent to SimpleAI’s implicity, and some that I think are my own fault.
Firstly, turret types can be completely overbuilt because of the random selection, as in this video where an excessive number of missile turrets are built and almost no other defenses.
Even if a variety of turrets are built, they are regularly built in improper places, as exemplified by this coastal turret built in the middle of the landmass with no sea target access, so it cannot even fire.
And sometimes constructors cannot build at all because they can’t access the build location of the target, as shown by these vehicle constructors trying to build a water mex.
Goals
Now that the basic SimpleAI reimplementation is (basically) complete, the future of CRustAIcean is machine learning. The SimpleAI base uses a lot of random choice for movement, decision making, and build orders. This provides a perfect opportunity to replace the randomness with machine learning decision making. I plan to implement reinforcement learning to make a base AI that behaves similarly to SimpleAI, and then transition to an evolutionary learning style to improve it’s performance. My end goal is to make an AI that is able to not only challenging, but also fun to play against. By taking final results at different points in the learning sequence, weighting longer games and buildup similar to what a player at that level would do, and trying to win 50% of the time instead of 100% of the time I hope to improve the current selection of AI opponents available to Beyond All Reason and SpringRTS players.