Copyright Tristan Aubrey-Jones December 2005.
Home Up ( Download )
TajBot - Robocode bot http://robocode.sourceforge.net/ Copyright Tristan Aubrey-Jones December 2005. The idea is similar to Robot Wars, only these robots are not remote controlled, they have to think for themselves. The task was to program a robot class that would control the robot, and make it battle against opponents. You all start by inheriting from the same robot base class, and so you have to look to tactics and pure cunning to give your robot the edge on its opponents ;) My robot featured: * Full sensor sweep and enemy absolute coordinate calculation * Target threat estimation * Seperate target priority estimation * Predictive aiming * Evasive manovering * Basic target tracking - at a distance * Target movement pattern recognition - not functional Target Selection: Every half second (at 30fps) it performs a 360degree sensor sweep in which each scanned target is added (or updated) within a hashtable. When a target is scanned I use a bit of vector trig (using the Vector and BotMaths classes i wrote) to calculate their absolute coordinates (Vector from 0,0) and their heading vector is also stored. A accessor method within the Enemy class wich stores this data called getPriority uses a function of all this data to calculate a "priority rating" for each target, and the TajBot then finds the maximum priority to choose the current target. Aiming: When a target has been chosen scanning is mainly performed between +20 and -20degrees around that target (so that information is as recent as possible) - though 360degree scans still occur every half second. To find the point at which to aim I form simultaneous functions between the position the target will be after time t and the time taken for a bullet to travel to that position. To solve this I use an iterative method where I take an estimate for the bullet's time (given the target's last location) and then use that to choose a point at that time of the target's current vector. I iterate several times using an improved estimation for t until I have a fairly accurate target location. Firing: When the gun has cooled off, and I have a satisfactory lock (the gunHeading is within +1 or -1 degrees of the correct bearing, the gun will fire, with an energy appropriate based on the chance of a hit. Movement: Using a similer approach as the target priority the current worst threat is calculated, and the robot ensures it is at 90degrees to this threat and strifing. When the robot gets too far away from its target, it will follow and close the gap.