前回は最下位だったけど、今回は5回戦中一回最後まで残ったので、4位に入りました。
ただ、4台のみで戦ったら、やっぱり最下位でした・・・ 一番強かったロボットは、弾を発射しているときに立ち止まらず、常に動きながら弾を発射していました。このことにより、一度ロックオンしたら立ち止まってしまい、逆にねらわれることを回避しています。 ロボコードで戦うロボットも、それぞれクラスのインスタンス クラスとは・・・オブジェクトの設計図 インスタンスとは メソッドとは クラスディレクションとは・・・ package mf; import robocode.*; import java.awt.Color; /** * Miffyproto - a robot by (your name here) */ public class Miffyproto extends Robot { //ここからプログラムスタート boolean peek; // Don't turn if there's a robot there // ロボットがいれば回転しない double moveAmount; // How much to move // どれだけ動くか public void run() { Direction myDir = new Direction(); //ここで新しい変数のようなものを作っている Direction myRadarDir = new Direction(); setColors(Color.yellow,Color.pink,new Color(150,0,150));//色は本体が黄色で砲台がピンク turnLeft(getHeading());//左に曲がる //turnGunRight(360);//砲台を右へ360度回転 while(true) { //もし真ならば turnRadarRight(360);//レーダーを360度回転する //ahead(50);//50前進 //turnRight(90);//右へ90度 //turnRadarLeft(360);//レーダーを左へ360度 setAdjustGunForRobotTurn(true);// ahead(100*myDir.getDir()); myDir.flip(); turnRadarRight(120 * myRadarDir.getDir()); myRadarDir.flip(); // double r=Math.random();//方向のみランダムで決定 // if(r > 0.75){ // ahead(50); // }else if(r >0.5){ // turnLeft(90);//ahead(50); // }else if(r>0.25){ // turnRight(90);//ahead(50); // }else back(50); // turnRadarRight(360);//レーダーを360度回転する // double s=Math.random(); //移動のみランダムで決定 // if(s > 0.75){ // ahead(50); // }else if(s >0.5){ // ahead(50); // }else if(s>0.25){ // ahead(50); //}else back(50); } } public void onScannedRobot(ScannedRobotEvent e) {//ロボット索敵で発見したら? double energy; double distance; double deg; distance = e.getDistance(); System.out.println("found;"+e.getName()); ///////////////// deg =e.getBearing() - ( getGunHeading() - getHeading() ) ; if(deg==0){ turnGunRight(0); }else{ if(deg<180){ turnGunRight(deg); }else{ turnGunLeft(359-deg); } } ////////////////////////////// if(distance<30){//敵との距離が30以下だったら・・・ fire(10);//見つけたらファイア! }else if(distance<100){fire(3); }else fire(1);//それ以上離れていたら1の火力でファイア! System.out.println("energy;"+getEnergy()); System.out.println("distance;"+distance); scan();//索敵 } public void onHitRobot(HitRobotEvent e) { // If he's in front of us, set back up a bit. // もし敵が私たちの前にいれば、少し後退します。 if (e.getBearing() > -90 && e.getBearing() < 90) back(100); // else he's in back of us, so set ahead a bit. // そうでなければ敵は後ろにいるので、すこし前進します。 else ahead(100); } public void onHitByBullet(HitByBulletEvent e) {//敵に攻撃されたら scan(); while(true) { //もし真ならば turnRadarRight(360);//レーダーを360度回転する //ahead(50);//50前進 //turnRight(90);//右へ90度 //turnRadarLeft(360);//レーダーを左へ360度 setAdjustGunForRobotTurn(true);// turnLeft(90 - e.getBearing());//砲台の方向から左へ90度向く back(200);//後ろへ90 } } public void onHitWall(HitWallEvent e) {//壁に当たったら turnGunRight(180); //砲台を右へ180度 turnRight(90); ahead(200); } public void onWin(WinEvent e) { turnRight(90);//右へ90度 turnLeft(90);//左へ90度 //勝利のダンス動作を記述 ex.360度回転するなど }} class Direction{ int flag;//方向の保存 //コンストラクタ public Direction(){ this.flag = 1; } //方向の読み出し public int getDir(){ return this.flag; } //方向の反転 public void flip(){ this.flag = -1; } } //class Radardirection extends //public void flip(){//5回に一回は回転する // if((this counter % 5)==0{ // this.flag=-1; // } // this.flag=this.flag*(-1); // this.counter++; // } //}
by viewtleaf
| 2004-12-14 20:37
| JAVAプログラミング
|
検索
カテゴリ
全体Diary 学校での取り組み全般 バレーボール 修論 Linux Network Security Software 総合関係 Medical treatment JAVAプログラミング 研究会等 特別支援 Fishing 流体力学 機械工学 画像処理 電気工学 情報工学 木材加工 異文化間教育 ビデオ編集 イギリスの学校 書評 リンク 金属加工 学ぶ・わかる Bowling Hardware 麺類 Piano English パズル 卓球 未分類 フォロー中のブログ
異能者集団のチームワーキング私たちにもできる!国際協力 ジャストジャンプ3@フレ... その他のジャンル
記事ランキング
ブログジャンル
画像一覧
| ||||||||||||||||||||||||||||||||||||||||||||||||||
ファン申請 |
||