Sunday, October 02, 2005

Robocode

I came across "Robocode" a year or two ago, but I didn't really give it a second thought at the time. I just picked it up about a week or two ago (just before my trip to London), and it has me really engrossed.

Robocode is a free, open source toy that you can download (make sure you have Java installed) and immediately start to create your own little tank robots. Think of it as a really deep version of Carnage Heart, you program your robots and send them out to do battle with other people's creations. You can even build teams of robots that work together against other teams if you're up for that.

I started with a very simple robot. It's called SimpleRobot. And this is the main gist of it's logic:

/**
* Fire when we see a robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
aimGun(e.getBearing());
fire(1);
turnLeft(90 - e.getBearing());
}

So when it sees a robot, it aims at the robot, fires, and turns perpendicular to the target in order to better dodge incoming fire. Oh but that's not all. This simple robot also is smart enough to not run into a wall over and over. Behold:

public void onHitWall(HitWallEvent event) {
changeDirection();
}


Well, I updated that robot and made SimpleCounterRobot. It is more of the same with a bit more intelligence in terms of avoiding incoming fire, and occasionally changing direction and the like. The problem with both of these robots is that if they fired at the bearing of the enemy, they would miss if the enemy was moving. I then took on the challenge of calculating the right angle with which to lead a moving target. And thus SimpleAimingRobot was born.

Of course, my robot programming has just begun, I still cannot accurately hit moving targets that have a variable velocity (speed and angle) like those that move in a circle. There are lots of examples of code out there that I could probably just copy but I'm trying to learn step by step. It's a lot of fun actually. You can try my robots out by downloading the JAR file included in this post. I left the source code in the JAR so you can take a look at what I've done if that interests you.

Now I'm going to try to get Indesin, CdnAttackBeaver, DJ Derelict, Cibbuano and the rest of you into making something so that we can all compete and laugh at the losers. A FactionFive Robocode League!!!

Actually if Kevin gets his act together I think we can take some inspiration from Carnage Heart and make a more accessible game out of this. So now I go back to my robots, to tinker away. If I had money to burn I might even consider using these programming skills to control something real but then some of those robots cost over $2000, so maybe not. At least not until they can carry around real guns. Oh wait, those already exist. Cool!

3 Comments:

At Sun Oct 02, 10:57:00 PM EST, Blogger Cibbuano said...

Man, I'm all over that noise.

I don't really know how to program these 'robots' but I'll give it shake.

 
At Tue Oct 04, 01:23:00 PM EST, Blogger D to tha L I C T said...

Neato. I'll give it a try when I have some time as well.

BTW, Cibby, I can't get onto your blog for some reason, and haven't been able to for a while. I get an XML error.

 
At Tue Oct 04, 01:37:00 PM EST, Blogger Blight said...

Awesome. Glad to see you guys are game to try it. I also cannot view Cibby's blog.

 

Post a Comment

<< Home


News | Profile | Gallery | Code | Contact