Tuesday, September 20, 2011

Robocode Katas

When thinking of katas the first thing that comes to my mind is the next karate kid.  More specifically the scene where Julie-San asks Mr. Miyagi when she was going to start breaking boards.  Mr. Miyagi responds by telling her to continue washing his car, remember 'wax on, wax off.'  This is where the beauty of Katas come in, it might seem repetitive to wash a car, or print a hello world program, however the underlying idea is that you are sharpening specific skills.  Katas are not necessarily easy, some katas may challenge you and bring you to the brink of frustration and insanity.  I welcomed this idea of a programming challenge and applied the code kata idea on building robots.


danger danger will robinson... these aren't the robots you're looking for. In fact these robots are part of an open source game called Robocode.  These robots fight for the user and set out to destroy other robots, until there is only one.  Robocode is a game in Java, where programmers can build their robots to do all sorts of fantastic things. These robots are very intricate, because of all the things the user must account for when building his/her ultimate robot.  Such as the direction the robot is facing, the direction the gun is facing, the enemy robot, and the strength of attack. 



  • 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.
  • 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). 
I've successfully finished the code katas listed above, however I've yet to implement a working version of the following robots
  • Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
  • 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). 
The main problem I've had with these 2 code katas is that it involves the use of trigonometry and that is a field where I lack in. Although I have gained a lot of knowledge in developing a basic robot that involves moving, firing, and scanning. While doing these katas I found myself looking at the Robocode API since it was a very useful page displaying the functionality of everything in Robocode. Also I've gotten more comfortable reading other people's code. One of the code katas asked for the robot to reach the middle, and a researcher at IBM had posted his code that solves this in an intricate way. Overall my ineptness to use trigonometry haltered the completion of the last two katas.  

My future plans on Robocode would involve building a competitive robot that will incorporate trigonometry. I will focus on the firing aspect on my competitive robot, as this will indefinitely help fire me into robot glory. 

0 comments:

Post a Comment