Wednesday, September 9, 2009

CodingWars with Robocode

In the past, the Java programs that I've worked on usually involves solving problems and implementing the basics of Java. Robocode has to be the most interesting Java programming that I've ever worked on. The main reason is that, it's a GAME that involves robots beating the crap out of each other. The concept is that you build your robot, have it battle one or many robots, and hope that it destroys all of its enemies. In our homework assignment, we had to build 13 robots with the following traits (taken from the assignment page):
  • 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. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss).
  • 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 (you don't want to kill it).
Creating those robots familiarized us with the basics of Robocode from movement, tracking, and firing. I was able to finish all of the assigned robots with some minor bugs.

One of the things I noticed while working on this assignment was that I had to refer to the Robocode wiki and API a lot because most of the functions that I used were new to me. The robot that gave me the hardest time was Movement05. This robot had to go to each corners of the field diagonally. I was trying to figure out how to make the robot go to a specific coordinate so that I can command it to go to the corners one after the other. A couple of hours later, one of our classmates found this website that shows exactly what we wanted our robot to do. We implemented the code and voila! Movement05 did exactly what I wanted it to do. Of course I cited the website and its author in our code :) .

One thing I learned about how the robots behave is that they can be as flexible as you want them to be, as long as you program them correctly. I also learned that the robot doesn't always behave the way you want it to be :( . I also noticed that there are some kind of physics involved in the game. I noticed this when I was working on the firing robots. Their firing accuracy is higher when their gun turns slowly rather than spinning fast.

My ideal competitive robot would be finely tuned in all ways possible. Pinpoint firing accuracy and bullet evasion would be good. When I work on the advanced robots then I'll have more ideas for what can be done better for competitions.

You guys can download and try my robots by clicking this link.

David Joel Lazaro

0 comments:

Post a Comment