木浦 package sample; import robocode.*; import java.awt.*; //import java.awt.Color; // API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html /** * Kiura01 - a robot by (your name here) */ public class Kiura01 extends AdvancedRobot { int moveDirection=1;//which way to move int myHealth=100;//HP of my robot /** * run: Kiura01's default behavior */ public void run() { setAdjustRadarForRobotTurn(true);//keep the radar still while we turn // setColors(Color.red,Color.blue,Color.green); // body,gun,radar setBodyColor(new Color(128, 128, 50)); setGunColor(new Color(50, 50, 20)); setRadarColor(new Color(200, 200, 70)); setScanColor(Color.white); setBulletColor(Color.blue); setAdjustGunForRobotTurn(true); // Keep the gun still when we turn turnRadarRightRadians(Double.POSITIVE_INFINITY);//keep turning radar right // Robot main loop //while(true) { // Replace the next 4 lines with any behavior you would like //ahead(100); //turnGunRight(360); //back(100); //turnGunRight(360); //} } /** * onScannedRobot: What to do when you see another robot */ public void onScannedRobot(ScannedRobotEvent e) { double absBearing=e.getBearingRadians()+getHeadingRadians();//enemies absolute bearing double latVel=e.getVelocity() * Math.sin(e.getHeadingRadians() -absBearing);//enemies later velocity double gunTurnAmt;//amount to turn our gun setTurnRadarLeftRadians(getRadarTurnRemainingRadians());//lock on the radar if(Math.random()>.9){ setMaxVelocity((12*Math.random())+12);//randomly change speed } if (e.getDistance() > 150) {//if distance is greater than 150 gunTurnAmt = robocode.util.Utils.normalRelativeAngle(absBearing- getGunHeadingRadians()+latVel/22);//amount to turn our gun, lead just a little bit setTurnGunRightRadians(gunTurnAmt); //turn our gun setTurnRightRadians(robocode.util.Utils.normalRelativeAngle(absBearing-getHeadingRadians()+latVel/getVelocity()));//drive towards the enemies predicted future location if (getEnergy() > 80) { setAhead((e.getDistance() - 140)*moveDirection);//move forward setFire(3);//fire } else if (getEnergy() > 40) { if( (getEnergy()- e.getEnergy() ) >20){ setAhead((e.getDistance() - 140)*moveDirection);//move forward setFire(3);//fire } else{ setTurnLeft(45); setBack(140); setTurnRight(45); setFire(1); } } } else{//if we are close enough... gunTurnAmt = robocode.util.Utils.normalRelativeAngle(absBearing- getGunHeadingRadians()+latVel/15);//amount to turn our gun, lead just a little bit setTurnGunRightRadians(gunTurnAmt);//turn our gun setTurnLeft(-90-e.getBearing()); //turn perpendicular to the enemy if (getEnergy() > 80) { setAhead((e.getDistance() - 140)*moveDirection);//move forward setFire(3);//fire } else if (getEnergy() > 40) { if((getEnergy()-e.getEnergy())>20){ setAhead((e.getDistance() - 140)*moveDirection);//move forward setFire(3);//fire } else{ setTurnLeft(45); setBack(140); setTurnRight(45); setFire(1); } } } } /** * 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); setTurnLeft(135); setAhead(140); } /** * onHitWall: What to do when you hit a wall */ public void onHitWall(HitWallEvent e) { // Replace the next line with any behavior you would like moveDirection=-moveDirection; } }