我来问关于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);
}
}
也许尝试发明了一些策略。像追逐另一个机器人。或者逃跑。或者只是隐藏在角落直到结束......你可以发明更多,然后随机决定什么待办事项。 – bdecaf 2012-03-15 20:37:00
即时新增robocode,但我相信一个子弹的最大火力是3,所以你使用的3.5是无效的 – Yiannis 2015-04-25 15:25:18