Wednesday, September 9, 2009

The Robocode Experience

For the past week, our first real java project in class was to familiarize and try our luck at at RoboCode.

What is RoboCode you may ask?Well, Robocode is an
Open Source educational game started by Mathew Nelson. You build small tanks that are thrown into a battlefield where they battle it out until one is left. The catch is that each tank has to be programmed in java by you.

After installing the open source game, we were assigned simple design tasks for basic movement, tracking, and firing. The tasks ranged from simply doing nothing, to having tracking software installed onto your tank.

While it is fun to play around with, anyone learning java can greatly benefit from creating a few robots. After about a year of learning new programming languages, I too, have to admit my java was very rusty. After spending a couple hours on RoboCode, memories of searching through the java API and creating insanely complex loops and methods only to find out there was one in the API, came rushing back. An uneasy feeling rose up in my stomach as I instantly knew I was going to be getting very little sleep this entire semester.

I was able to start slow, learning the basic methods involved in moving and turning the tank, but some of the later movement specifications were no simple task. It required you to think about the positioning of your tank for different orientations and adjust accordingly. In one of the movements, I found myself making a different test case for the tank’s relative position to the center of the battlefield, and which way it’s gun was facing. Throw obstibcles in front of that and you’ve got yourself a thinker.

If you want to take a look at my completed (12/13) Robots, download them
here.

One of the hardest problems I had was having to use complex math to allow more elegant movement. One of the robots, which I was unable to finish was a robot that would move from one corner to the opposite corner, which was more complex than I initially though. In the game itself there was a sample robot that would move to corners by first moving vertical then horizontally. I had implemented something similar to this, but then after some discussion with other friends, we agreed that it did not hold up to the true task for the movement, which was to be able to move diagonally from one corner to the next. This seems somewhat simple in math, though my worst subject, it requires just a bit of trigonometry. Drawing things out on paper or even in the air can help many times. It helps you visualize your objectives. On paper is sounded simple, use the position to make a triangle using some trig functions and you’ve got yourself a direction, but trying to implement it in java still causes me many problems. This was in fact the only one I was unable to complete.

This was an overall good exercise in java. The real challenge lies in creating an actual competitive robot. Implementing creative movement patterns and attack strategies may require a lot more planning, and much more complex math. We can build upon the smaller programs that we have made, much like our experiences with java programming. Always keep good code in case you ever have use for it in another.

No comments:

Post a Comment