robocode 笔记

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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值