Package clarkson.cs551.robocode.radar

Source Code of clarkson.cs551.robocode.radar.LockingHandler

package clarkson.cs551.robocode.radar;

import robocode.AdvancedRobot;
import robocode.Rules;
import robocode.ScannedRobotEvent;
import robocode.util.Utils;
import clarkson.cs551.robocode.common.RelativePos;

public class LockingHandler implements RadarHandler {

  private RelativePos lastPosition;

  @Override
  public void enemyScanned(AdvancedRobot self, ScannedRobotEvent event) {
    lastPosition = new RelativePos(self.getHeadingRadians()
        + event.getBearingRadians(), event.getDistance());
  }

  @Override
  public void action(AdvancedRobot robot) {
    if (null == lastPosition) {
      robot.setTurnRadarRightRadians(2 * Math.PI);
      return;
    }
    double radarStart = robot.getRadarHeadingRadians();
    double target = lastPosition.getDirection();
    double turn = Utils.normalRelativeAngle(target - radarStart);
    double extraTurn = Math.min(
        Math.atan(36.0 / lastPosition.getDistance()),
        Rules.RADAR_TURN_RATE_RADIANS);
    turn += turn > 0 ? extraTurn : -extraTurn;
    robot.setTurnRadarRightRadians(turn);
  }
}
TOP

Related Classes of clarkson.cs551.robocode.radar.LockingHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.