Wednesday, September 9, 2009

Practice run in Robocode, gearing up for the Big Fight!

Robocode is an excellent program that lets users design their robot's function and puts it to the test by facing off with other robots. For this assignment, we familiarize ourselves to the program by creating simple functions that teaches us movement, radar control and targeting.
These functions are:
  • Movement01: The minimal robot. Does absolutely nothing at all.
  • Movement02: Move forward a total of 50 pixels per turn. If you hit a wall, reverse direction.
  • Movement03: Each turn, move forward a total of N pixels per turn, then turn left. N is initialized to 10, and increases by 10 per turn.
  • Movement04: Move to the center of the playing field and stop.
  • Movement05: Move to the upper left corner. Then move to the lower right corner. Then move to the upper right corner. Then move to the lower left corner.
  • Movement06: Move to the center, then move in a circle, ending up where you started.
  • Tracking01: Pick one enemy and follow them.
  • Tracking02: Pick one enemy and follow them, but stop if your robot gets within 20 pixels of them.
  • Tracking03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
  • Firing01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
  • Firing02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
  • Firing03: Sit still. Rotate gun. When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you.
  • Firing04: 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.
The problems that I encountered were from Movement04 and Tracking02. I thought that movement04 was pretty hard because it involved trigonometry. After several failed attempts of trying to figure it out on my own, I asked my friend about it and he mentioned a website where he found a code that does what we needed to do for movement04. The code helped me a lot in figuring out how to do movement04 especially with the trigonometry functions. As for tracking02 my problem was getting my robot to stop within 20 pixels away from my enemy. I tried factoring in the sizes of my robot and my enemy into the calculated distance between, since the distance is calculated from the center of each robot, but it never worked. It is one of the problems I still need to work on.

All in all I thought that it was a fun assignment. As challenging as it is, I think that this is a good exercise for us not only to use open source materials but to apply different fields such as Math as tools needed in programming. My ideas for a competitive robot will most definitely involve Math since I plan to focus on movement and targeting.
My sample code can be found here.

0 comments:

Post a Comment