Before I talk about my experiences I should first explain a little about the battlefield and the robots. Each battle in robocode consists of a given number of robots in a 2d board. The view is top down and each robot has a gun and a certain number of life points. The robots battle until only one robot is remaining. Points are awarded not only on survivability but also damage dealt, and other factors. There are robocode leagues in which people create robots that need to satisfy certain requirements. For example in a Melee league no robots may fire guns and can only do damage by ramming other bots. There are also leagues based on the size of one's code so elegant bots written in efficient code don't challenge bots with complex algorithms.
Reach your dreams vicariously by destroying tiny robotsFor this assignment we were instructed to create 13 simple robots that satisfied certain requirements. Six of them had movement requirements, three had tracking requirements and the other four were concerned with the process of firing the gun.
I believe I completed all of the simple robots correctly, but I may have misinterpreted some of the steps. For example I don't know the exact definition of a turn but I was too lazy to ask for clarification. For example I was not sure if Tracking03 was meant to move back 100 steps each round and never move again or if it was supposed to scan for the closest bot, move 100 steps away from it and repeat... In any case I just did what I interpreted as a correct implementation.
For the movement robots I completed the first three pretty quickly, but I had trouble on the Movement04 robot which needed to head towards the center of the map. I ended up writing on lots of scrap paper in order to do the trigonometric calculations. I did separate test cases based upon what quadrant the robot is in at the start relative to the center. For example if the robot starts above and to the left of the center then different calculations are needed compared to if the robot starts below and to the right of the center. I discovered my first problem was that the arc tangent function in Java returned the angle in radians while robocode functions return values in degrees. I also had some issues because robocode functions such as getBearing() return the bearing relative to the robots heading while other values like getHeading() return values in absolute terms (0 to 360 degrees). In addition the orientation for robocode is that 0 is facing north, 90 degrees is east, etc... which is different from the unit circle. Fortunately I am pretty good at Trigonometry and as a math major I was able to get a solution. I wrote a function which gets the robot to any x,y point and then I was able to do Movement05 and Movement06 easily.
The second issue I had with this assignment was getting Tracking03 to work. At first I thought I did it correctly by simply spinning the radar and moving away from the first robot it found. However I realized that this doesn't move the robot away from the closest robot. To identify the closest robot I read a tutorial from http://www.codepoet.org/~markw/weber/java/robocode/lesson3.html which suggested that one implement an enemy bot class to keep track of the distances of each bot. It also had a link to a lab assignment on implementing this class. So basically I did the lab assignment for some other class and came up with an enemy class that seemed to work. The robot scans for the nearest robot, turns toward that robot, then backs away. It then searches for the next closest robot and backs away.
While I did complete the assignments, I know I didn't do them in the most optimal way. For example although Firing04 does track a robot with its gun, it doesn't have a 100% lock on the target. I implemented it in a simple narrow lock method while I read about much better and more sophisticated locks. Also I didn't make the tracking turns efficiently, instead I just had the robot/gun/radar turn left or right until the condition was satisfied. I read about more efficient methods but I didn't have a chance to implement them because of all the grading I had to do this weekend.
After completing the simple robots, I tried to implement a robot with predictive targeting. I followed the tutorial from
http://www.codepoet.org/~markw/weber/java/robocode/lesson4.html
and implemented an AdvancedEnemyRobot but I was unable to get a robot working. I kept getting null pointer exceptions so I decided to delete it and start again when I have more time.
I learned from this assignment that there's a lot of trigonometry in robocode and even a good Java programmer may have trouble if she doesn't understand the usage of sin,cos, and tan functions. In fact I think that my math and statistical background will help me in developing algorithms in the future. Combine that with my experience of programming the AI in a connect four Java game and I should have a leg up on programmers without the math experience.
For a competitive robot I want to implement predictive targeting so I can beat a robot like walls. I'm not sure about movement but I like the idea of moving perpendicular to an enemy in a 1-1 setting. I also want to optimize my radar movement and implement a radar that locks onto an enemy bot and better than the narrow radar that I implemented.
To download the sample robots in java click here
Keeping track of resource prices is one of the complicated features of FreeCol
FreeCol world map image taken from www.freecol.com
Colopedia provides in game information on every resource in FreeCol
Screenshot of the sourcecode for your viewing pleasure