Tuesday, 30 August 2011

TARGETTING

In Robocode, you deplete your opponent's energy and increase your own energy by hitting other bots with bullets. Thus, coming up with targeting algorithms to hit your opponents accurately is a cornerstone of a successful Robocode bot. Different algorithms are more appropriate for different Code Size divisions and styles of play.
The main components of a targeting system are:
  • Choosing a target (Melee only)
  • Energy Management - Whether or not to fire, what bullet power to use
  • Choosing a firing angle
Most descriptions of Robocode targeting systems focus on choosing a firing angle. For a learning gun, this is essentially a classification problem. The enemy robot can't react to where you fired your bullets because he can't see your gun or your bullets (until they hit). He can, however, see when you fire by monitoring your energy.
Some aspects that make Robocode targeting an interesting classification problem are:
  • You have a very small amount of time per tick to make a decision. Dropping in the most sophisticated classification algorithm you can find in a textbook won't work. This time needs to be split between inputting data and generating output values.
  • You have to continually make decisions - when you have no data, when you have 50 ticks, 500 ticks, or 20,000 ticks of data. Your algorithm has to perform well and remain fast enough throughout the entire battle.

MOVEMENTS

In Robocode, you deplete your opponent's energy and increase your own energy by hitting other bots with bullets. Thus, coming up with movement algorithms to keep enemies from hitting you is a cornerstone of a successful Robocode bot. Different algorithms are more appropriate for different CodeSize divisions and styles of play.
Melee and 1v1 are the most explored Robocode rule sets, so most movement algorithms could be categorized as most appropriate for one of them. Other rule sets, like Teams, Twin Duel, Droids, and Virtual Combat add various other elements and borrow from Melee and 1v1 movement styles.
In Melee, besides moving unpredictably, it's also very important to choose a stategically beneficial location. For instance, not being closest to any other bot means that you will likely not be targeted by other bots - this allows you to easily collect survival points and also rack up bullet damage against bots that may not be perpendicular to you, making them easier targets. Corners tend to be coveted positions in a Melee battle. You cannot scan the entire battle field every tick in Melee, and Robocode's bullet hit events only fire for bullets that you fire or that hit you, so you have access to a far lower percentage of the total information in the battle. This makes it difficult or impossible to employ precise forms of bullet dodging in Melee.
In 1v1, a primary differentiator of movements at the highest level is bullet dodging. There are still strategic choices, like distancing, attack angle control, dive protection, and staying out of corners (which can limit your Maximum Escape Angle). But distancing is reciprocal, most decent attack angle control schemes perform similarly, and the benefit of staying far away may offset the negative impact of being cornered. Between gathering scans of the enemy every tick and receiving bullet hit events for every bullet that hits you or the enemy, you have a very high amount of information about the battle. About the only thing you are unaware of is the location of enemy bullets that don't (or haven't yet) hit you. Wave Surfing movements with Precise Prediction put all of this together to dodge bullets with surprising accuracy, especially against simple targeters.
For 1v1 in lower weight classes, like MicroBots and NanoBots, there is not enough room to track all of the data needed for Wave Surfing. Still, Stop And Go movements do a great job of dodging simple targeters like Head-On Targeting, and well tuned Random Movement can make your movement fairly unpredictable even to powerful guns by creating a flat movement profile.

radar

A radar in Robocode can turn a maximum of 45° or π/4rad in a single tick. The radar scans robots up to 1200 units away. The angle that the radar rotates between two ticks creates what is called a radar arc, and every robot detected within the arc is sent to the onScannedRobot() method in order of distance from the scanning bot. The closest bot is detected first, while the furthest bot is detected last. By default, the onScannedRobot() method has the lowest event priority of all the event handlers in Robocode, so it is the last one to be triggered each tick.


For most of these radar locks, you will need to add one of the following to your run() method:
 
setAdjustRadarForRobotTurn(true);
setAdjustGunForRobotTurn(true);
setAdjustRadarForGunTurn(true);