Tuesday, September 14, 2010

Robocode

For the third programming assignment in ICS 413, we were asked to write codes for 13  different robots all having different behaviors. We used an open source programming game called Robocode. Its main goal is to create a robot/tank using java and battle against other creators and developers. It is more than a programming game since it also teaches users java programming.

The installation of the program is pretty straight forward. It has tutorials on how to develop robots using Eclipse, which helped a lot since we're already familiar with it. The program itself can be found at http://robocode.sourceforge.net/ and tutorials  in this comprehensive wiki among many others available online.

Here are the following robots that we have to develop:
  • Position01: The minimal robot.  Does absolutely nothing at all.
  • Position02: Move forward a total of 100 pixels per turn.  When you hit a wall, reverse direction.
  • Position03: Each turn, move forward a total of N pixels per turn, then turn right.  N is initialized to 15, and increases by 15 per turn.
  • Position04: Move to the center of the playing field, spin around in a circle,  and stop.
  • Position05: Move to the upper right corner.  Then move to the lower left corner.  Then move to the upper left corner. Then move to the lower right corner.
  • Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
  • Follow01: Pick one enemy and follow them.
  • Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
  • Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
  • Boom01: Sit still.  Rotate gun.  When it is pointing at an enemy, fire.
  • Boom02: Sit still.  Pick one enemy.  Only fire your gun when it is pointing at the chosen enemy.
  • Boom03:  Sit still. Rotate gun.  When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss). 
  • Boom04: Sit still.  Pick one enemy and attempt to track it with your gun. In other words, try to have your gun always pointing at that enemy.  Don't fire (you don't want to kill it). 
 I expected these assignment to be programming intensive but I didn't expect math to play a role in this. I never had trigonometry for more than a decade so I had to brush up on it before I even touch the keyboard. Position04 is the first challenging robot to develop. I had to relearned Pyhtagorean theorem. Here are the pseudocode for this robot:
 
        1. Get the coordinates of the center of the battlefield
             -this requires to get the width and length of the battlefield and divide each by two.
        2. Get the position of the robot and subtract from the given x & y coordinates
        3. Use Pythagorean theorem to find the angle to the destination the robot should turn.
       4. The use Pythagorean theorem again to compute the distance to the destination.

But wait there's more.......

I also need to figure out which quadrant the robot is at to be able to compute how much it need to turn the robot to face the center and then go forward. 

The Boom01 trough 04 are probably the easiest set of robots to develop. This are also the most fun part, because I get to fire at the other robots. The whole Eclipse package of my work can be download here.

All in all, this assignment reminded me on how fun and frustrating programming is. It's fun when you were able to see the finish program, but it's guaranteed that you will have lots of frustrations to get there and see your creations comes alive. It also reminded me that robots are very cool, but useless without humans. With the help of these robots, now I can get started with my competitive robot and test its ability with others.....

No comments:

Post a Comment