Given the amount of press Java garners, you'd think that every programmer is busily building Java applications. The reality is that many programmers have yet to give Java a try. If you're one of those programmers, Robocode might just be the project you need to jump into Java.
Given the amount of press Java garners, you’d think that every programmer is busily building Java applications. The reality is that many programmers have yet to give Java a try. If you’re one of those programmers, Robocode might just be the project you need to jump into Java.
Ready to Rumble
IBM’s Robocode draws its inspiration from two popular pastimes: writing computer games to learn to program, and watching Junkyard Wars, Battle Bots, and similar machine vs. machine competitions. Robocode is a Java-based framework for building intelligent robots that maneuver around a virtual battlefield and attempt to destroy each other (or at least stay alive).
|Figure One: A robot|
While battling bots is a lot of fun, the real purpose of Robocode is to provide an approachable and fun way to learn how to program in Java. Rather than building yet another database front-end or middleware component, Robocode lets you build the brains of a virtual robot and endow it with as much intelligence as you can. Each robot is equipped with an independentally-controlled radar and gun (shown in Figure One), and is capable of turning, moving forward, and moving backward.
Once you’ve programmed your robot, you can test it against some of the pre-fabricated robots that come with Robocode. However, as you refine your robot’s strategies and test it, you’ll eventually grow tired of the stock robots. Not to worry. A very active community has sprung up to bring Robocode hackers together from around the world. Web sites like Robocode Fanatics (http://robocode.diverman.com), and Robocode.net (http://robocode.net) provide places to discuss design strategies and exchange bots with others. You can even upload your robot so that others can grab it and battle against it.
The first thing you’ll need to do is verify that you have a Java 2 runtime version 1.4 (or newer) installed. If the output of java -version indicates that you’re using 1.3 or an older release, you’ll need to upgrade. The latest downloads for Java 2 Standard Edition (J2SE) are on Sun’s Web site at http://java.sun.com.
With the right version of Java in place, you just need to download the Robocode installer from the IBM alphaWorks site (http://robocode.alphaworks.ibm.com/installer/index.html) and start the installation:
java -jar robocode-setup.jar
You’ll need to agree to the license agreement to get the installation started. After that, just select an installation directory.
|Figure Two: The battlefield|
Once installed, you can start the Robocode GUI by running robocode.sh from the directory where Robocode was installed. The user interface consists of the battlefield, which is surrounded by a number of control buttons, and an integrated code editor (the Robocode Editor). Figure Two illustrates a battle in progress.
Kick Some Bot
A full Robocode tutorial is well beyond the scope of what we can cover here. But after you’ve had a chance to browse the on-line docs and try your had at building a few robots, you’ll probably be itching for more. Robocode can be quite addictive.
A quick Google search for Robocode reveals several popular web sites where programmers gather to discuss Robocode and kick bot.
Have an idea for a project we should feature? Drop a note to firstname.lastname@example.org and let us know.
Fatal error: Call to undefined function aa_author_bios() in /opt/apache/dms/b2b/linux-mag.com/site/www/htdocs/wp-content/themes/linuxmag/single.php on line 62