我是来询问有关 Robocode 机器人的。我有我的机器人代码,我的 26 个朋友排名第 11。但是,我想尝试让它变得更好。我查看了网站并调整了我的代码,以便它可以不可预测地移动。这有助于它在十轮比赛中获得第一名。你能给我一些想法和技巧来帮助改进这个机器人吗?然后我可以编辑我的机器人,看看它是如何工作的。不过,我希望机器人留在扩展机器人中。
package aaa;
import robocode.*;
//import java.awt.Color;
// API help: http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
/**
*Epictron - a robot by ASHAR ASLAM!!!
*/
public class Epictron extends Robot
{
/**
* run: Epictron's default behavior
*/
public void run() {
// Initialization of the robot should be put here
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
// setColors(Color.blue,Color.blue,Color.grey,Color.red,Color.green); // body,gun,radar
// Robot main loop
while(true) {
// Replace the next 4 lines with any behavior you would like
double distance = Math.random()*300;
double angle = Math.random()*45;
turnRight(angle);
ahead(distance);
ahead(100);
turnGunRight(90);
back(100);
turnGunRight(90);
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
double distance = e.getDistance();
if(distance<200)
{
fire(3.5);
}
else if(distance<500)
{
fire(2.5);
}
else if(distance<800)
{
fire(1.5);
}
else
{
fire(0.5);
}
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
// Replace the next line with any behavior you would like
back(10);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
// Replace the next line with any behavior you would like
back(20);
}
}