2005-9-1
[Robocode]
1.Download robocode-setup.jar from http://www.ai-code.org/download/detail.php?id=1
(I'm so sorry that I don't know my downloads' version)
2.Setup
java -jar robocode-setup.jar
3.After setup, you'll run the robocode. First of all, you can play the samples, then , if you like ,you can program you own robot . If you download other's robot(*.jar), you can put it in the directory $/robocode/robots/ directoryly.
4.If you want to develop on other platform, such as Eclipse, you should config the robocode form Options->Preferences->Development Options, input your project's class path; meanwhile, you should import robocode.jar from your setup directory.
5.The follow codes is my robot, which can beat "sample.Walls". ^0^
package metaphy;
import robocode.*;
import java.awt.Color;
import java.util.Random;
/**
* GrobotV1 - a robot by metaphy
*/
public class GrobotV1 extends AdvancedRobot {
/**
* run: GrobotV1's default behavior
*/
public void run() {
this.setColors(Color.green,Color.green,Color.red);
this.setAdjustGunForRobotTurn(false);
this.setAdjustRadarForGunTurn(true);
this.setAdjustRadarForRobotTurn(true);
this.setTurnRadarLeft(400); //initial scan
this.execute();
while(true){
if (this.getRadarTurnRemaining() ==0 ) {
this.setTurnRadarRight(90);
}
this.execute() ;
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// turn the gun toward the robot we scanned
this.setTurnRight(e.getBearing());
if(Math.abs(e.getDistance())<100.0){
this.setBack(e.getDistance()*2);
}
this.setFire(3);
if(Math.abs(e.getDistance())>200.0){
this.setAhead(e.getDistance()/2) ;
}
// lock our radar onto our target
this.setTurnRadarRight(this.getHeading() - this.getRadarHeading() + e.getBearing());
}
/**
* Hit Robot
*/
public void onHitRobot(HitRobotEvent e) {
this.setBack(100);
}
//攻
private void fireStrategy(ScannedRobotEvent e){
}
//防
private void moveStrategy(ScannedRobotEvent e){
}
}
6.References:
http://www.codepoet.org/~markw/weber/java/robocode/lesson1.html
...
http://www.codepoet.org/~markw/weber/java/robocode/lesson4.html
Downloads(you can find good things from here):
http://www.ai-code.org/download/