Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package patel_mister;
- import robocode.HitRobotEvent;
- import robocode.Robot;
- import robocode.ScannedRobotEvent;
- public class Dodge_Walls_V2 extends Robot
- {
- boolean peek;
- double moveAmount;
- public void walls(){
- moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
- peek = false;
- turnLeft(getHeading() % 90);
- ahead(moveAmount);
- peek = true;
- turnGunRight(90);
- turnRight(90);
- while (getOthers() >= 5) {
- peek = true;
- ahead(moveAmount);
- turnRight(90);
- turnRight(-90);
- peek = false;
- turnRight(90);
- }
- }
- public void dodge(){
- getHeading();
- turnLeft(getHeading());
- ahead(1800);
- back(700);
- while (getOthers() < 5)
- ahead(700);
- turnLeft(90);
- ahead(700);
- turnLeft(90);
- }
- public void run() {
- if(getOthers() >= 5)
- walls();
- else if(getOthers() < 5)
- dodge();
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- if(getEnergy() > 100)
- {
- fire(3);
- }
- if(getEnergy() > 50)
- {
- fire(2);
- }
- else
- {
- fire(1);
- }
- }
- public void onHitRobot(HitRobotEvent e) {
- if (e.getBearing() > -90 && e.getBearing() < 90) {
- back(100);
- }
- else {
- ahead(100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement