2012-03-15 26 views
2

私はRobocodeロボットについて尋ねました。私は自分のロボットのコードを持っていて、私の友達のうち26人が11番になった。しかし、私はそれをより良くしようとします。私はウェブサイトを見て、コードを調整して予測不能に動くようにしました。これは10ラウンドで1回1位になりました。このロボットの改善に役立つアイデアやヒントを教えてください。私は自分のロボットを編集して、それがどのようになるか見ることができます。私はロボットが拡張ロボットに残ることを望む。あなたを助ける必要があります -Robocodeのロボットを作るための助けが必要

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); 
    } 
} 
+0

はたぶん、いくつかの戦略を考案してみてください。他のロボットを追うように。または逃げる。または、最後まで角を隠すだけです...もっと多くを発明し、ランダムに何をするかを決めることができます。 – bdecaf

+1

私はrobocodeに新しいが、私は弾丸の最大の火力は3だからあなたが使用している3.5は有効ではないと信じている – Yiannis

答えて

0

robowikiは、すべてのトップボットについての情報を持っています。私はちょっとロボコーディングをして、パターンマッチングガンと一緒にウェーブサーフィンをするのはおそらくほとんどのボットに匹敵するほど良いと知っていましたが、パターンマッチングと波乗りをするのに数ヶ月かかりました半分の実装を一緒にcobbleする程度。それでも、コードが失われたときにそれを再実装するための十分な知識を保持していませんでした。

2

ランダムに回転して、あなたの側面がスキャンするロボットに向くようにするのではなく、この方法で簡単に左右に移動して弾丸をかわすことができます。横方向にランダムに移動することも、他のロボットのエネルギーレベルに変更を登録するときに移動することもできます。これは、それらがあなたに発砲したことを意味する可能性があるからです。

また、敵をより適切にターゲティングする方法が必要です。あなたがそれらを見ると、弾丸がそれらに達する頃には、あなたはおそらく動いたでしょう。基本的な三角法を使って、弾丸が到達するときの敵の位置を推測することができます。

4

最初にOnScannedRobotメソッドを記述します。

ランダムな値は不正確なので使用しないでください。

レーダーはガンの同じ角度で指しています。レーダーがロボットを指してそれをスキャンすると、ロボットは発砲しています。

レーダーがロボットをスキャンするときにonScanned()メソッドが呼び出されます。

public void onScannedRobot(ScannedRobotEvent e){ 
    double distance = e.getDistance(); //get the distance of the scanned robot 
    if(distance > 800) //this conditions adjust the fire force according the distance of the scanned robot. 
     fire(5); 
    else if(distance > 600 && distance <= 800) 
     fire(4); 
    else if(distance > 400 && distance <= 600) 
     fire(3); 
    else if(distance > 200 && distance <= 400) 
     fire(2); 
    else if(distance < 200) 
     fire(1); 
} 

ここで、run()メソッドを記述します。

ループ内でのみ書き込みます。したがって、ループは各秒で同じ操作を繰り返します。

すべてのゾーンをスキャンするには、ガンを360度回転させます。

while(true){ 
    ahead(100); //Go ahead 100 pixels 
    turnGunRight(360); //scan 
    back(75); //Go back 75 pixels 
    turnGunRight(360); //scan 

    //For each second the robot go ahead 25 pixels. 
} 

ここで、ロボットは1秒あたり25ピクセル進みます。

遅かれ早かれ、ロボットはマップの壁に到達します。

壁に届くとロボットをブロックすることができます。

私たちはonHitWall()メソッドを使って解決します。

public void onHitWall(HitWallEvent e){ 
    double bearing = e.getBearing(); //get the bearing of the wall 
    turnRight(-bearing); //This isn't accurate but release your robot. 
    ahead(100); //The robot goes away from the wall. 
} 

臆病なロボットを作成しますか?D?エネルギーが低い場合には、onHitByBullet()メソッドを使用してください。ロボットが弾丸で殴られると、この方法が呼び出されます。

double energy = getEnergy(); 
public void onHitByBullet(HitByBulletEvent e){ 
    double bearing = e.getBearing(); //Get the direction which is arrived the bullet. 
    if(energy < 100){ // if the energy is low, the robot go away from the enemy 
     turnRight(-bearing); //This isn't accurate but release your robot. 
     ahead(100); //The robot goes away from the enemy. 
    } 
    else 
     turnRight(360); // scan 
} 

すべてのRobocode API http://robocode.sourceforge.net/docs/robocode/

を見るために訪問このページを:D別れ、フランク

関連する問題