Tuesday, September 15, 2009

Imitation is the Sincerest Form of Flattery

Our simple Robocode robots last week gave us an introduction into Robocode. Our last step before creating a competitive robot is to review some of the sample robots to give us some ideas for movement, tracking, and firing strategies.

The movement for walls is very simple. It turns to one of the cardinal directions (0, 90, 180, or 270 degrees) and moves all the way to the wall. Once there, it moves around the battlefield along the walls. What's unique is the use of the "peek" variable that stops the robot from moving if it finds an enemy. Otherwise, targeting and firing is pretty straightforward. The gun always points into the field as the robot moves around.

RamFire has an interesting strategy. As far as the run loop goes, it simply turns around looking for an enemy. Once it finds a robot though, RamFire attempts to hit the robot by moving in a straight line 5 pixels past the event's location and then scans the field if it misses. The neat thing it does is that it scales the power of the bullet based on the remaining life of the robot. The purpose is that there are bonus points for destroying the robot by ramming into it. Thus, it wants to weaken the enemy to the point where ramming into it kills it.

SpinBot moves in a circle a lot. What's interesting to me is that it does so without any complicated equations. In my simple robot implementation, I calculated the points along the circle and moved to those points. What this does is it sets up its turn to some value, sets a max velocity, and moves. The robot does extend AdvancedRobot, so that's why I didn't see the setTurnRight() and setMaxVelocity() in the Robot API. Targeting and firing are really basic. The radar turns with the robot and the robot fires if it finds an enemy.

After using Crazy as a test robot for a while, I was surprised by its implementation. You'd think that it's very random, but it isn't. It moves in arcs, first a 90 degree arc to the right, then a 180 degree arc to the left, and finally another 180 degree arc to the right. The robot simply reverses direction if it hits a wall. If you slow it down, you see the arcs that Crazy moves in. These arc movements are something to consider when making a competitive robot. They seem to use the AdvancedRobot class as well. Other than that, targeting and firing are basic. The radar turns with the robot and the gun fires if an enemy is found.

For the most part, this robot is identical to our Firing01. It sits there, rotates the gun, and fires at scanned enemies. They did move the robot perpendicular to the incoming bullet when it gets hit, so it's not a total sitting duck. The robot also uses bullet power depending on how much energy the robot currently has. Finally, the robot fires hard at any robot that may run into it.

I imagine most would be surprised at the implementation of SittingDuck. For a robot that does nothing, there's a lot of code! All that code is there though to maintain a persistent round count so that the SittingDuck can report how long it's been sitting still. So as far as movement, targeting, and firing are concerned, there is nothing to see here. But there might be something with persistency. Maybe you can record the first enemy to die and pick on it every round since it might be weak.

Pretty basic movement strategy again. It just tucks itself in the corner. That's a pretty smart strategy though, as you now only have to rotate your gun 90 degrees to cover the entire field. On the other hand, it is still in effect a sitting duck. Once a robot targets it, it can be taken out fairly easily. A better strategy might be to sit in the corner until you get hit, then move to another corner.

This is another robot that is somewhat similar in concept to one of our sample robots. All it does in its run loop is search for an enemy. Once an enemy is found though, Tracker moves close to it and fires when it's at a certain distance from the enemy. The way Tracker implemented tracking an enemy might be better than my current implementation. Something to consider if I decide to use a similar "hunt and destroy" technique.

No comments:

Post a Comment