Posted on 12/20/2001 5:14:19 AM PST by Dominic Harr
Robot Wars - Java Style
By Mat Nelson
Robocode is a new twist on programming games such as CoreWars, RobotWars, and Robot Battle. It's like Logo, but with tanks, guns, and explosions instead of penup and pendown... and it's all in Java(tm).
The framework is simple: Robocode exposes a set of APIs you can call to interact with the game. In short, you write a Java class extending robocode.Robot... then by calling methods in the superclass, your actions take effect in the onscreen battlefield.
Here's a complete, super-simple robot:
import robocode.*;
/**
* Devastator: A not-all-that-devastating robot
*/
public class Devastator extends AdvancedRobot {
/**
* run - called by the game
*/
public void run() {
while (true) {
turnGunRight(360);
ahead(200);
turnGunLeft(360);
back(200);
}
}
/**
* onScannedRobot - What to do when you see an enemy...
*/
public void onScannedRobot(ScannedRobotEvent e) {
fire(3);
}
}
Easy to learn but difficult to master, Robocode gives you complete freedom to code as you wish. Whether that be an EnemyAnalyzer running in its own thread to track enemy positions, a neural network, a predictive firing algorithm, a reusable wall-avoidance object, an abstracted set of classes to deal with the physics of the game -- whatever it is, the choice is yours.
The only thing Robocode requires is that you tell it what you want to do. Deciding what to do, and how you come to that decision, is completely up to you.
There are already hundreds of robots to test your skills against at websites linked from http://robocode.alphaworks.ibm.com/links/Links.html -- and you can safely run them in Robocode with its built in SecurityManager.
Upcoming Robocode features include: Team support with messaging, walls and objects in the battlefield, terrain, tutorials and objectives to complete... plus whatever else you help us dream up.
Robocode is available at: http://robocode.alphaworks.ibm.com/
The current API you can use to interact with the game can be seen at: http://robocode.alphaworks.ibm.com/docs/robocode/index.html
I'm in the corporate womb. No one here even is comprehensible before about 10 am.
Half of us *never* are, actually.
(Which half am I in?)
I like playing Tank Wars. Cool game.
Some of the strategies seen there:
gun turret
wall-hugger
corner-hugger
wall-hopper (like wall-hugger, but will move to other walls if in danger/getting pounded)
corner-hopper
hesitator ( the idea being to use depletion of energy to halt one's movement, thus throwing off opponents' shots)
machine gunner ( overwhelming rate of fire. Overwhelms opponents that are "too smart" defensively.)
dasher ( rush opponent, deliver kill shot at close range )
a number of strategies depending on weapon type
Some of these strategies might not be applicable, depending on the game physics.
It has also been observed that many robots that rule in single combat often die quick, horrible deaths in a melee. Changing strategy for the number of opponents and/or the presence of teammates is a must.
Now how can explain to my wife why I 'need' to waste a few hours?
Disclaimer: Opinions posted on Free Republic are those of the individual posters and do not necessarily represent the opinion of Free Republic or its management. All materials posted herein are protected by copyright law and the exemption for fair use of copyrighted works.