Tuesday, September 14, 2010

Introduction to RoboCode

I had a blast this past week while working on our newest assignment: RoboCode.  I wish someone had turned me on to this sooner.  RoboCode, for the uninformed, is a BattleBots-esq, Open-Source platform released by IBM.  Basically, you program a robot to move, aim and fire at other robots.  Once you look past the silly testbots, you really start to see the deep-rooted strategy, and elegance of programming.  Some developers went so far as to implement neural net systems in their bots, but I opted stayed in the shallow end of the pool. 

Our assignment was to complete 12 "starter" bots, see the link here for the specifics. 

Overview:
Basically, all of our robots are extending the Robot class.  Battles consist of a series of turns, and Robots should have a run() method which is called each turn.  While running, Robots may experience various Event flags (such as being hit, shot, running into walls, running into other robots, etc).  Robots may (but aren't required to) have methods that deal with these Events, and allow the robot to respond accordingly.  RoboCode tactics consist of three major areas: targeting, movement, and firing.  Targeting is done by whirling around a radar dish that sits atop the Robot's gun.  When it finds another Robot, an Event flag is raised, and the Robot will execute the appropriate method (which usually involves firing).  Movement is the final component of the Robot, and is the simplest defensive tactic the Robot can employ.


I finished all 12 bots in about a week (realistically it was two days with a long hiatus in between).  Once I started planning out my competitive robot, my progress on the "starter" bots dropped all but stopped.  I learned a few tricks while working on my competitive bot, and half wanted to go back and apply them to my "starter" bots.  The main one was an elegant little targeting method that effectively keeps the gun fixed on a single target.  (I'll post more details after the big tournament).  The magic method that makes the algorithm work is normalRelativeAngleDegrees() which turns a given 360 degree angle into an angle between -180 and 180.  My plan for the competitive bot is to use this tracking algorithm, along with a targeting algorithm that sets bullet power proportional to the distance of a target.  This should save energy, and effectively hit any robot that:
  1. Tries to double back on its path
  2. Moves too slowly
  3. Ventures too close
To avoid getting shot, I plan to implement the movement pattern of the testbot "walls".  I found that in a free-for-all matchup, walls had the greatest survivability of any of the other testbots.  Hopefully the combination of these three elements will win the day. 

My "starter" bots:
http://www2.hawaii.edu/~gburgess/glb.zip

No comments:

Post a Comment