Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package period2;
- import robocode.*;
- import java.awt.Color;
- // API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html
- /**
- * AhmadAdam - a robot by (Adam Ahmad)
- */
- public class AhmadAdam extends Robot
- {
- /**
- * run: AhmadAdam's default behavior
- */
- public void run() {
- setAdjustRadarForRobotTurn(true);
- setAdjustGunForRobotTurn(true);
- setAdjustRadarForGunTurn(true);
- setBodyColor(new Color(255, 209, 26));
- setGunColor(new Color(0, 0, 0));
- setRadarColor(new Color(0, 0, 0));
- setBulletColor(new Color(255, 255, 255));
- setScanColor(Color.red);
- while(true) {
- // Replace the next 4 lines with any behavior you would like
- turnRadarRight(45);
- }
- }
- /**
- * 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 gunDist = getHeading() + e.getBearing() - getGunHeading();
- double radarDist = getHeading() + e.getBearing() - getRadarHeading();
- turnRadarRight(efficientAngle(radarDist));
- turnGunRight(efficientAngle(gunDist));
- double distance = e.getDistance();
- if(distance <= 40){
- fire(3);
- }
- else if(distance > 40 && distance <= 150){
- fire(2);
- }
- else {
- fire(1);
- }
- scan();
- }
- /**
- * 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
- ahead((int)(80 * Math.random())+40);
- }
- /**
- * onHitWall: What to do when you hit a wall
- */
- public void onHitWall(HitWallEvent e) {
- turnLeft(90-e.getBearing());
- }
- public double efficientAngle(double angle){
- while (angle > 180) angle -= 360;
- while (angle < -180) angle += 360;
- return angle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement