Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nielegalnaplantacja;
- import robocode.HitByBulletEvent;
- import robocode.ScannedRobotEvent;
- import robocode.TeamRobot;
- import java.awt.*;
- import java.io.IOException;
- import robocode.HitRobotEvent;
- import robocode.StatusEvent;
- import sampleteam.Point;
- import static robocode.util.Utils.normalRelativeAngleDegrees;
- public class LeszekBoczkowski extends TeamRobot {
- boolean peek;
- double moveAmount;
- public void run() {
- // Set the color of this robot containing the RobotColors
- setBodyColor(Color.yellow);
- setGunColor(Color.yellow);
- setRadarColor(Color.white);
- setScanColor(Color.yellow);
- setBulletColor(Color.white);
- moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
- peek = false;
- turnLeft(getHeading() % 90);
- ahead(moveAmount);
- peek = true;
- turnGunRight(90);
- turnRight(90);
- execute();
- while (true) {
- peek = true;
- ahead(moveAmount);
- peek = false;
- turnRight(90);
- execute();
- }
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- // Don't fire on teammates
- if (isTeammate(e.getName())) {
- return;
- }
- // Calculate enemy bearing
- double enemyBearing = this.getHeading() + e.getBearing();
- double bearingFromGun = normalRelativeAngleDegrees(enemyBearing - getGunHeading());
- // Calculate enemy's position
- double enemyX = getX() + e.getDistance() * Math.sin(Math.toRadians(enemyBearing));
- double enemyY = getY() + e.getDistance() * Math.cos(Math.toRadians(enemyBearing));
- if (Math.abs(bearingFromGun) <= 3) {
- turnGunRight(bearingFromGun);
- if (getGunHeat() == 0) {
- fire(Math.min(3 - Math.abs(bearingFromGun), getEnergy() - .1));
- }
- }
- else {
- turnGunRight(bearingFromGun);
- }
- try {
- broadcastMessage(new Point(enemyX, enemyY));
- } catch (IOException ex) {
- out.println("Unable to send order: ");
- ex.printStackTrace(out);
- }
- }
- public void onStatus( StatusEvent e) {
- setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
- }
- public void onHitRobot(HitRobotEvent e) {
- if (e.getBearing() > -90 && e.getBearing() < 90) {
- back(100);
- }
- else {
- ahead(100);
- }
- }
- }
Add Comment
Please, Sign In to add comment