Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tp;
- import robocode.*;
- import java.util.*;
- import java.awt.Color;
- // API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
- /**
- * Killer3000 - a robot by (your name here)
- */
- public class Killer3000 extends AdvancedRobot
- {
- /**
- * run: Killer3000's default behavior
- */
- Random r = new Random();
- 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.red,Color.blue,Color.green); // body,gun,radar
- // Robot main loop
- setAdjustGunForRobotTurn (true);
- setAdjustRadarForGunTurn(true);
- while (true) {
- turnRadarLeft (90);
- }
- }
- /**
- * onScannedRobot: What to do when you see another robot
- */
- public double normalize (double angle) {
- while (angle > 180) angle -= 360;
- while (angle < -180) angle += 360;
- return angle;
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- // Replace the next line with any behavior you would like
- if (getGunHeat() == 0 && Math.abs(getGunTurnRemaining()) < 1)
- fire(Math.min(600 / e.getDistance(), 3));
- double a = (getHeading () - getGunHeading () + e.getBearing ());
- turnGunRight (normalize(a));
- }
- /**
- * onHitByBullet: What to do when you're hit by a bullet
- */
- public void onHitByBullet (HitByBulletEvent e) {
- int a = r.nextInt(100);
- if (a < 50)
- {
- turnLeft(r.nextInt(30) + 30);
- } else
- {
- turnRight(r.nextInt(30) + 30);
- }
- ahead (r.nextInt(70) + 30);
- }
- /**
- * onHitWall: What to do when you hit a wall
- */
- public void onHitWall(HitWallEvent e) {
- // Replace the next line with any behavior you would like
- turnLeft (r.nextInt(90) + 90);
- ahead (100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement