|
@@ -0,0 +1,212 @@
|
|
|
|
+package hau;
|
|
|
|
+/**
|
|
|
|
+ * Created by PDK on 30.06.2015.
|
|
|
|
+ */
|
|
|
|
+import robocode.*; // robocode.jar must be in Classpath..
|
|
|
|
+
|
|
|
|
+import java.awt.Color;
|
|
|
|
+import java.util.Random;
|
|
|
|
+
|
|
|
|
+public class HauBot extends RateControlRobot {
|
|
|
|
+ double setCourse = 270; // drive left at start
|
|
|
|
+ double yawGunRate = 20;
|
|
|
|
+ double yawRadarRate = 90;
|
|
|
|
+ double yawRate = 20;
|
|
|
|
+
|
|
|
|
+ //// PRIVATES
|
|
|
|
+ private double changeDirection(double Rate) {
|
|
|
|
+ return Rate * -1;
|
|
|
|
+ }
|
|
|
|
+ private void hauInit() {
|
|
|
|
+ setAdjustRadarForGunTurn(true);
|
|
|
|
+ setAdjustGunForRobotTurn(true);
|
|
|
|
+ }
|
|
|
|
+ private void setHeading(int degrees) {
|
|
|
|
+ // this command stops the bot and lets him turn ... this command is 'blocking'
|
|
|
|
+ if (getHeading() != degrees) {
|
|
|
|
+ turnRight(robocode.util.Utils.normalRelativeAngleDegrees(degrees - getHeading()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void yawHeading(double wantedHeading) {
|
|
|
|
+ double bearingToWantedHeading;
|
|
|
|
+
|
|
|
|
+ bearingToWantedHeading = robocode.util.Utils.normalRelativeAngleDegrees(wantedHeading - getHeading());
|
|
|
|
+
|
|
|
|
+ setDebugProperty("getHeading", String.valueOf(getHeading()));
|
|
|
|
+ setDebugProperty("wantedHeading", String.valueOf(wantedHeading));
|
|
|
|
+ setDebugProperty("bearingToWantedHeading", String.valueOf(bearingToWantedHeading));
|
|
|
|
+
|
|
|
|
+ if (Math.abs(bearingToWantedHeading) <= 3) {
|
|
|
|
+ turnRight(bearingToWantedHeading);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (bearingToWantedHeading > 0) {
|
|
|
|
+ setTurnRate(yawRate);
|
|
|
|
+ setDebugProperty("setTurnRate", String.valueOf(yawRate));
|
|
|
|
+ }
|
|
|
|
+ if (bearingToWantedHeading < 0) {
|
|
|
|
+ setTurnRate(0 - yawRate);
|
|
|
|
+ setDebugProperty("setTurnRate", String.valueOf(0 - yawRate));
|
|
|
|
+ }
|
|
|
|
+ if (bearingToWantedHeading == 0) {
|
|
|
|
+ setTurnRate(0);
|
|
|
|
+ setDebugProperty("setTurnRate", String.valueOf(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void hauRadar() {
|
|
|
|
+ setRadarRotationRate(yawRadarRate);
|
|
|
|
+ }
|
|
|
|
+ private void hauMove() {
|
|
|
|
+ Random randomGenerator = new Random();
|
|
|
|
+ int rndBack = randomGenerator.nextInt(30);
|
|
|
|
+ int rndFwd = randomGenerator.nextInt(30);
|
|
|
|
+ int randomAhead = randomGenerator.nextInt(8) + 2;
|
|
|
|
+
|
|
|
|
+ setVelocityRate(randomAhead);
|
|
|
|
+
|
|
|
|
+ int abstandVonWand = 75;
|
|
|
|
+ // linke wand
|
|
|
|
+ if ((getX() < 0 + abstandVonWand + getWidth())
|
|
|
|
+ && getY() < getBattleFieldHeight() + getHeight()
|
|
|
|
+ && setCourse != 0) {
|
|
|
|
+ // nach oben fahren
|
|
|
|
+ setCourse = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // obere wand
|
|
|
|
+ if ((getY() > getBattleFieldHeight() - abstandVonWand - getHeight())
|
|
|
|
+ && getX() < getBattleFieldWidth() + getWidth()
|
|
|
|
+ && setCourse != 90 ) {
|
|
|
|
+ // nach rechts fahren
|
|
|
|
+ setCourse = 90;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // rechte wand
|
|
|
|
+ if ((getX() > getBattleFieldWidth() - abstandVonWand - getWidth())
|
|
|
|
+ && getY() > 5 + getHeight()
|
|
|
|
+ && setCourse != 180) {
|
|
|
|
+ // nach unten fahren
|
|
|
|
+ setCourse = 180;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // untere wand
|
|
|
|
+ if ((getY() < 0 + abstandVonWand + getHeight())
|
|
|
|
+ && getX() > 5 + getWidth() + abstandVonWand
|
|
|
|
+ && setCourse != 270) {
|
|
|
|
+ // nach links fahren
|
|
|
|
+ setCourse = 270;
|
|
|
|
+ }
|
|
|
|
+ yawHeading(setCourse);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //// PUBLICS
|
|
|
|
+ public void onScannedRobot(ScannedRobotEvent e) {
|
|
|
|
+ double bearingToEnemyFromTankHeading = getHeading() + e.getBearing();
|
|
|
|
+ double bearingToEnemyFromGunHeading = robocode.util.Utils.normalRelativeAngleDegrees(bearingToEnemyFromTankHeading - getGunHeading());
|
|
|
|
+ double bearingToEnemyFromRadarHeading = robocode.util.Utils.normalRelativeAngleDegrees(bearingToEnemyFromTankHeading - getRadarHeading());
|
|
|
|
+
|
|
|
|
+ out.println("scanned him: " + e.getName());
|
|
|
|
+
|
|
|
|
+ double parallelZurKanoneToleranz = 40;
|
|
|
|
+
|
|
|
|
+ double fireModifiers = 1.1;
|
|
|
|
+
|
|
|
|
+ // change direction.. chances are high, we scan him again
|
|
|
|
+ yawRadarRate = changeDirection(yawRadarRate);
|
|
|
|
+ //turnRadarRight(bearingToEnemyFromRadarHeading); // lock on
|
|
|
|
+ // yawRadarRate = yawRadarRate;
|
|
|
|
+
|
|
|
|
+ // If the bearing in degrees is less than 10 ..
|
|
|
|
+ if (Math.abs(bearingToEnemyFromGunHeading) <= 5) {
|
|
|
|
+ // adjust last little degrees ...
|
|
|
|
+ turnGunRight(bearingToEnemyFromGunHeading);
|
|
|
|
+ if (e.getVelocity() == 0) {
|
|
|
|
+ out.println(e.getName() + " steht ..");
|
|
|
|
+ fireModifiers = fireModifiers + 1;
|
|
|
|
+ }
|
|
|
|
+ // 90 < 360 - 270 + 20 (=110
|
|
|
|
+ // 90 > - 20 (=70)
|
|
|
|
+ //
|
|
|
|
+ if ( (getGunHeading() < robocode.util.Utils.normalAbsoluteAngleDegrees(360 - e.getHeading()) + parallelZurKanoneToleranz) &&
|
|
|
|
+ (getGunHeading() > robocode.util.Utils.normalAbsoluteAngleDegrees(360 - e.getHeading()) - parallelZurKanoneToleranz) ) {
|
|
|
|
+ out.println(e.getName() + "faehrt in meine Kanone rein");
|
|
|
|
+ fireModifiers = fireModifiers + 1.5;
|
|
|
|
+ }
|
|
|
|
+ if (e.getDistance() < 200) {
|
|
|
|
+ fireModifiers = fireModifiers + 1;
|
|
|
|
+ }
|
|
|
|
+ if (e.getDistance() > 450) {
|
|
|
|
+ fireModifiers = fireModifiers - 1;
|
|
|
|
+ }
|
|
|
|
+ if (getGunHeat() == 0) {
|
|
|
|
+ fireModifiers = fireModifiers + 1;
|
|
|
|
+ }
|
|
|
|
+ fire(Math.min(fireModifiers, getEnergy() - .1));
|
|
|
|
+
|
|
|
|
+ //hauMove(); // we call it .. because otherwise we block execution while turning radar and gun..
|
|
|
|
+ //execute();
|
|
|
|
+ //scan();
|
|
|
|
+ }
|
|
|
|
+ // otherwise just set the gun to turn.
|
|
|
|
+ else {
|
|
|
|
+ turnGunRight(bearingToEnemyFromGunHeading);
|
|
|
|
+ /*if (bearingToEnemyFromGunHeading > 0) {
|
|
|
|
+ setGunRotationRate(yawGunRate);
|
|
|
|
+ }
|
|
|
|
+ if (bearingToEnemyFromGunHeading < 0) {
|
|
|
|
+ setGunRotationRate(0 - yawGunRate);
|
|
|
|
+ }
|
|
|
|
+ if (bearingToEnemyFromGunHeading == 0) {
|
|
|
|
+ //scan();
|
|
|
|
+ } */
|
|
|
|
+ //yawGunRate = bearingToEnemyFromGunHeading * 0.1;
|
|
|
|
+ //setGunRotationRate(yawGunRate);
|
|
|
|
+ //setDebugProperty("yawGunRate", String.valueOf(yawGunRate));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Generates another scan event if we see a robot.
|
|
|
|
+ // We only need to call this if the gun (and therefore radar)
|
|
|
|
+ // are not turning. Otherwise, scan is called automatically.
|
|
|
|
+/*
|
|
|
|
+ if (e.getVelocity() == 0 && e.getDistance() < 150) {
|
|
|
|
+ fire(4);
|
|
|
|
+ //turnRight(e.getBearing());
|
|
|
|
+ //if (e.getDistance() < 500) {
|
|
|
|
+ // ahead(510);
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ setAdjustGunForRobotTurn(true);
|
|
|
|
+ turnRight(e.getBearing() + 90);
|
|
|
|
+ if (e.getBearing() - getGunHeading() == 0) {
|
|
|
|
+ fire(3);
|
|
|
|
+ }
|
|
|
|
+ setAdjustGunForRobotTurn(false);
|
|
|
|
+ }
|
|
|
|
+ fire(2); */
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public void onHitByBullet(HitByBulletEvent e) {
|
|
|
|
+ // Replace the next line with any behavior you would like
|
|
|
|
+ //Random randomGenerator = new Random();
|
|
|
|
+ //int rndBack = randomGenerator.nextInt(30);
|
|
|
|
+ //back(rndBack);
|
|
|
|
+ }
|
|
|
|
+ public void onHitWall(HitWallEvent e) {
|
|
|
|
+ // doing nothing yet
|
|
|
|
+ }
|
|
|
|
+ public void run() {
|
|
|
|
+ setColors(Color.lightGray, Color.gray, Color.darkGray);
|
|
|
|
+ setScanColor(Color.yellow);
|
|
|
|
+
|
|
|
|
+ hauInit();
|
|
|
|
+
|
|
|
|
+ while(true) {
|
|
|
|
+ hauMove();
|
|
|
|
+ hauRadar();
|
|
|
|
+ execute();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|