package taqho; import robocode.*; |
<pre> package taqho; |
import java.awt.Color; |
import robocode.*; |
import java.awt.Color; |
/** |
/** |
public class Seed extends Robot { |
public class Seed extends Robot { |
|
|
|
|
|
|
|
|
|
|
distance = distanceToXY??(cornerX, cornerY); |
distance = distanceToXY?(cornerX, cornerY); |
scanArenaFromCorner??(); |
scanArenaFromCorner?(); |
|
cornerY = getBattleFieldHeight??() - wallMargin; |
cornerY = getBattleFieldHeight?() - wallMargin; |
cornerX = getBattleFieldWidth??() - wallMargin; cornerY = getBattleFieldHeight??() - wallMargin; |
cornerX = getBattleFieldWidth?() - wallMargin; cornerY = getBattleFieldHeight?() - wallMargin; |
cornerX = getBattleFieldWidth??() - wallMargin; |
cornerX = getBattleFieldWidth?() - wallMargin; |
|
|
public double distanceToXY??(double x, double y) { |
public double distanceToXY?(double x, double y) { |
public void scanArenaFromCorner??() { |
public void scanArenaFromCorner?() { |
double needToTurn?? = scanStart - getGunHeading??(); out.println("needToTurn??=" + needToTurn?? + " = " + scanStart + " - " + getGunHeading??()); turnGunRight??(needToTurn??); |
double needToTurn? = scanStart - getGunHeading?(); out.println("needToTurn?=" + needToTurn? + " = " + scanStart + " - " + getGunHeading?()); turnGunRight?(needToTurn?); |
|
|
|
|
turnGunRight??(scanStep); if (getGunHeading??() > scanEnd) { |
turnGunRight?(scanStep); if (getGunHeading?() > scanEnd) { |
turnGunLeft??(scanStep); if (getGunHeading??() < scanStart) { |
turnGunLeft?(scanStep); if (getGunHeading?() < scanStart) { |
|
|
|
|
|
|
else if (getX() + toX > (getBattleFieldWidth??() - getWidth())) toX -= (getWidth()/2); |
else if (getX() + toX > (getBattleFieldWidth?() - getWidth())) toX -= (getWidth()/2); |
else if (getY() + toY > (getBattleFieldHeight??() - getWidth())) toY -= (getWidth()/2); double relativeToX?? = toX - getX(); double relativeToY?? = toY - getY(); double headingToXY?? = radToDeg??(this.arctan(relativeToX??, relativeToY??)); double tankTurn = headingToXY?? - getHeading(); double distance = Math.sqrt(relativeToX??*relativeToX?? + relativeToY??*relativeToY??); tankTurn = normalRelativeAngle?(tankTurn); if (tankTurn > 90 tankTurn < -90) { |
else if (getY() + toY > (getBattleFieldHeight?() - getWidth())) toY -= (getWidth()/2); double relativeToX? = toX - getX(); double relativeToY? = toY - getY(); double headingToXY? = radToDeg?(this.arctan(relativeToX?, relativeToY?)); double tankTurn = headingToXY? - getHeading(); double distance = Math.sqrt(relativeToX?*relativeToX? + relativeToY?*relativeToY?); tankTurn = normalRelativeAngle(tankTurn); |
if (tankTurn > 90 || tankTurn < -90) { |
|
|
turnRight(normalRelativeAngle?(tankTurn-180)); |
turnRight(normalRelativeAngle(tankTurn-180)); |
|
|
* onScannedRobot?: Fire! |
* onScannedRobot: Fire! |
public void onScannedRobot?(ScannedRobotEvent? e) { |
public void onScannedRobot(ScannedRobotEvent e) { |
|
|
* onHitRobot??: Aim at it. Fire Hard! |
* onHitRobot?: Aim at it. Fire Hard! |
public void onHitRobot??(HitRobotEvent?? e) { double turnGunAmt?? = normalRelativeAngle?(e.getBearing() + getHeading() - getGunHeading??()); turnGunRight??(turnGunAmt??); |
public void onHitRobot?(HitRobotEvent? e) { double turnGunAmt? = normalRelativeAngle(e.getBearing() + getHeading() - getGunHeading?()); turnGunRight?(turnGunAmt?); |
|
* onHitByBullet??: What to do when you're hit by a bullet |
* onHitByBullet?: What to do when you're hit by a bullet |
public void onHitByBullet??(HitByBulletEvent?? e) { |
public void onHitByBullet?(HitByBulletEvent? e) { |
double turnGunAmt?? = normalRelativeAngle?(e.getBearing() + getHeading() - getGunHeading??()); turnGunRight??(turnGunAmt??); |
double turnGunAmt? = normalRelativeAngle(e.getBearing() + getHeading() - getGunHeading?()); turnGunRight?(turnGunAmt?); |
|
|
* normalRelativeAngle?: returns angle such that -180<angle<=180 |
* normalRelativeAngle: returns angle such that -180<angle<=180 |
public double normalRelativeAngle?(double angle) { |
public double normalRelativeAngle(double angle) { |
|
public double radToDeg??(double rad) { |
public double radToDeg?(double rad) { |
public double degToRad??(double deg) { |
public double degToRad?(double deg) { |
|
|
else if ((dx < 0.0) && (dy > 0.0)) return normalizeAngle(Math.PI - Math.atan(dy/Math??.abs(dx))); |
else if ((dx < 0.0) && (dy > 0.0)) return normalizeAngle(Math.PI - Math.atan(dy/Math?.abs(dx))); |
} |
} </pre> |