Tuesday, September 20, 2011

Robot Kata

First of all, what exactly is a "kata"? In Japanese, kata is translated as form, but can also mean a set of choreographed movements that aim to perfect certain movements. Now what exactly is a "code kata"? Well it is exactly what it sounds like. It's a "kata" that uses code. We design various kata in order to perfect certain things.

When a lot of people think of programming, they see it as either designing an application, or programming something to do something; usually robots. So let's do that. Let's program robots; and not just any robot, it's a robot that can move, fight, and even scan. All this is done virtually of course. We're talking about a competition called "Robocode".

There were 13 kata I attempted to perfect, however I was only able to finish 12 of them.
  • 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). 
When starting the kata, I found it very simple and thought "oh, maybe I can finish this in no time". I was definitely wrong. Once I got to Position04, things got intense. It required me to brush up on my trigonometry skills, something I haven't used in nearly 5 years. So I spent a few hours reviewing some general trigonometric functions and I was set. I was able to use some basic trigonometry to finish all of the Position kata.

When starting the follow kata, A few hours of reading up on the API on how the robot scans took up the bulk of the time, along with experimenting on how they work. Eventually I was able to figure out the first 2 follow kata, but the Follow03 one doesn't quite do exactly what it is supposed to, but it generally does.

The Boom set of kata was probably the most fun because well, it's how you win. Learning how the gun and radar work together allowed me to start thinking about how the I will be creating a targeting system for my competition robot. Like I mentioned earlier, I only finished 12 of the 13 kata, and the one I didn't finish was the last one. I had troubles getting the gun to move at the same time with the enemy robot and therefore was unable to figure it out. However, I plan to try to get it to work as it is a vital part of the weapon system I am considering on implementing

Overall, the kata took some thinking, but wasn't impossibly hard. As long as one finished the previous kata, the next one often times built on it. It taught me the abilities each robot was able to do and how it is going to help with my competitive robot in the future.

No comments:

Post a Comment