我來問關於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