What is it?
Our AI for Games course ended with a C# Robocode competition. We had to create individual robots to win consistently against a benchmark robot and work in a team of robots without communicating any of our robot source except for protocols for communication.
What I did:
Blanch Bot is an aggressive robot that aims to close in on enemies. Blanch Bot, in its default state (Commando), will aggressively hunt for an enemy and try to predict movements with linear targeting. When Blanch Bot is low on health, it will enter a defensive state (Coward) where it will try to avoid attacks. If Blanch Bot is successful at evading attacks and is able to recover health, it will return to its Commando State.
Technical Approach:
Blanch Bot uses a state Machine to make decisions. This allows for the quick development of states which allows Blanch bot to change behavior depending on its health. States are implemented as an interface and there is a Base State for default behavior that all states inherit. Blanch Bot will always want to damage robots that it runs into and avoid staying in one place. More Developed States, such as Commando and Coward, can be made that can override this default behavior and elaborate on it.
Shooting:
Blanch Bot takes into account its health and the distance from its target when shooting. Since Blanch Bot is aggressive, it weighs the distance to it’s enemy as a more important heuristic than its own energy reserves.
Blanch Bot will also calculate where to aim based on how far away an enemy is, how long it will take an bullet to arrive, and make predictions using its velocity to calculate where it will be next. At one point, Blanch Bot used Circular Targeting, which also took into account where an enemy will be when a bullet will hit along with its angular and linear velocity, but this technique proved less effective against enemies that would quickly change their movement patterns. Closing in:
Blanch Bot will move towards an enemy and rotate to be orthogonal to it. Blanch Bot will also strafe by a random distance to confuse the enemy while still keeping it near its field of view for scanning and targeting. Blanch Bot will then turn away when too close to confuse the enemy and make hitting it more difficult.
Dodging:
As a last resort, when health is low, Blanch bot will drastically change its behavior and enter its Coward State to attempt to buy time and dodge attacks. Blanch Bot assumes that minute changes in energy represent the enemy firing bullets and will attempt to strafe in a random direction to avoid them. Blanch Bot is not too good at dodging as it dodges as soon as it receives a scan, so this is only used as a last resort. If it can recover enough health it will enter its Commando state again.
Teamwork with Blanchy Boid
Both Blanch Bot and Blanchy Boid started out as defensive robots, however Blanch Bot’s dodging algorithm wasn’t robust enough to consistently counter more robust robots. Blanch Bot then became an aggressive robot that would aim to confuse enemies and dodge as a last result. Each robot grew with their individual strengths and compensated each other’s weaknesses.
Communication
Blanch Bot and Blanchy Boid send and receive information about the state of the world to each other including Enemies, and their properties along with what has changed since the previous scan such as heading and energy. On top of sending enemy information, they also send information regarding their own properties such as position each run loop to help them to avoid running into each other.
|
Emergence
Since Blanchy Boid prefers to keep its distance, it mostly stays out of Blanch Bots' way and the two may often target the same enemy in a pincer formation or spread out the pain across different robots.
When Blanch Bot is low on health, it abandons its aggressive behavior to take a defensive approach until it can heal energy. This leads to emergent behavior as Blanchy Boid will become more aggressive when it fires less shots which will help Blanch Bot Evade, which draws enemy attention due to its strafing technique, and recover. Lessons Learned
Putting the bots together and watching them act as a team was very gratifying, especially after the individual struggle to get the bots at a high enough level to outperform Failbot. With the exception of one small communications hiccup, the bots worked beautifully in their assigned roles on the first try and required very little tweaking.
Being very different styles of bots, with different targeting styles, Finite State Machine states, and “knobs” to adjust, it was difficult to know how to help each other, especially as so much of the wins came as a result of simple tweaks to weights or parameters and not as a result of a sweeping algorithmic change. In a way, by tweaking values slightly, testing them for its ‘fitness’ and keeping the changes that worked, our design process was very similar to a slow, manual version of a genetic algorithm. Overall, despite some wasted work, and struggles polishing the bots, our team was able to make a set of robots we could be proud of, and despite being excellent fighters alone, they combine to be a great team. |