rc.yoda.utils
Class YUtils

java.lang.Object
  extended by rc.yoda.utils.YUtils

public final class YUtils
extends java.lang.Object

YUtils - A utilies class that contains common variables and methods needed throughout this robot

Version:
v 1.0
Author:
Robert Codd

Field Summary
static java.awt.geom.Rectangle2D.Double battleField
          A rectangle the size of the current safe battle field, the border the size of WALL_MARGIN is removed
static double battleFieldHeight
          The pixel height of the current battle field, defaults to 600
static double battleFieldWidth
          The pixel width of the current battle field, defaults to 800
static int BOT_WIDTH
          The pixel width of a robocode robot
static java.awt.geom.Rectangle2D.Double field
          A rectangle the size of the current battle field
static int WALL_MARGIN
          The closest distance a robot can be from a wall with out hitting it
static int WALL_STICK
          The distance ahead of the robot to start wall smoothing
 
Constructor Summary
YUtils()
           
 
Method Summary
static double absoluteBearing(java.awt.geom.Point2D.Double source, java.awt.geom.Point2D.Double target)
          Caculates the absolute bearing relative from source to the target
static int backAsFrontDirection(double newHeading, double oldHeading)
          Calculates direction to move based on your oldheading and your wanted heading
static double backAsFrontTurn(double newHeading, double oldHeading)
          Calculates how to move based on your oldheading and the heading you want
static double cosineLaw(double a, double b, double c)
          Calculates the angle opposite side a using the cosine Law
static double getMinBulletPower(double damage)
           
static double limit(double minimum, double value, double maximum)
          Caps a value to within a minimum and maximum range
static double maxEscapeAngle(double velocity)
          Calculates the max angle a robot can travel going max velocity if firing a bullet travel a specified velocity
static double normalAbsoluteAngle(double angle)
          Normalizes an angle to an absolute angle.
static double normalRelativeAngle(double angle)
          Normalizes an angle to a relative angle.
static java.awt.geom.Point2D.Double project(java.awt.geom.Point2D.Double location, double angle, double distance)
          Projects a location a certain distance along its current angle
static double rollingAverage(double currentAvg, double newEntry, double depth, double weighting)
          Calculates a rolling average of a current average and a new entry using the data current depth and this entry's weighting
static void setFieldAttr(robocode.AdvancedRobot robot)
          Extracts battle field specifications from an AdvancedRobot class
static int sign(double v)
          Calculates the sign(+/-) of an number
static double stopDistance(double velocity)
          Caculates the distance traveled while stopping from a specified velocity
static double wallSmoothing(java.awt.geom.Point2D.Double botLocation, double angle, int orientation)
          Caculates a "wallsmoothed" angle for a point traveling along a specified angle and a left or right orientation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOT_WIDTH

public static final int BOT_WIDTH
The pixel width of a robocode robot

See Also:
Constant Field Values

WALL_STICK

public static final int WALL_STICK
The distance ahead of the robot to start wall smoothing

See Also:
Constant Field Values

WALL_MARGIN

public static final int WALL_MARGIN
The closest distance a robot can be from a wall with out hitting it

See Also:
Constant Field Values

battleFieldWidth

public static double battleFieldWidth
The pixel width of the current battle field, defaults to 800


battleFieldHeight

public static double battleFieldHeight
The pixel height of the current battle field, defaults to 600


field

public static java.awt.geom.Rectangle2D.Double field
A rectangle the size of the current battle field


battleField

public static java.awt.geom.Rectangle2D.Double battleField
A rectangle the size of the current safe battle field, the border the size of WALL_MARGIN is removed

Constructor Detail

YUtils

public YUtils()
Method Detail

setFieldAttr

public static void setFieldAttr(robocode.AdvancedRobot robot)
Extracts battle field specifications from an AdvancedRobot class

Parameters:
an - AdvancedRobot

sign

public static int sign(double v)
Calculates the sign(+/-) of an number

Parameters:
a - number
Returns:
one if positive

maxEscapeAngle

public static double maxEscapeAngle(double velocity)
Calculates the max angle a robot can travel going max velocity if firing a bullet travel a specified velocity

Parameters:
bullet - velocity
Returns:
max angle a robot can travel

limit

public static double limit(double minimum,
                           double value,
                           double maximum)
Caps a value to within a minimum and maximum range

Parameters:
minimum - value of range
value - to cap
maximum - value of range
Returns:
the capped value

stopDistance

public static double stopDistance(double velocity)
Caculates the distance traveled while stopping from a specified velocity

Parameters:
velocity - at which appling breaks
Returns:
distance traveled while stopping

backAsFrontTurn

public static double backAsFrontTurn(double newHeading,
                                     double oldHeading)
Calculates how to move based on your oldheading and the heading you want

Parameters:
wanted - heading
heading - current at
Returns:
the amount to turn

backAsFrontDirection

public static int backAsFrontDirection(double newHeading,
                                       double oldHeading)
Calculates direction to move based on your oldheading and your wanted heading

Parameters:
wanted - heading
heading - current at
Returns:
the amount to turn

cosineLaw

public static double cosineLaw(double a,
                               double b,
                               double c)
Calculates the angle opposite side a using the cosine Law

Parameters:
length - of side a
length - of side b
length - of side c
Returns:
the angle opposite side a

rollingAverage

public static double rollingAverage(double currentAvg,
                                    double newEntry,
                                    double depth,
                                    double weighting)
Calculates a rolling average of a current average and a new entry using the data current depth and this entry's weighting

Parameters:
current - average of sample
new - entry to average
depth - of the sample
weighting - for this entry

absoluteBearing

public static double absoluteBearing(java.awt.geom.Point2D.Double source,
                                     java.awt.geom.Point2D.Double target)
Caculates the absolute bearing relative from source to the target

Parameters:
source - fo bearing
target - of the bearing
absolute - bearing from source to target

normalAbsoluteAngle

public static double normalAbsoluteAngle(double angle)
Normalizes an angle to an absolute angle. The normalized angle will be in the range from 0 to 2*PI, where 2*PI itself is not included.

Parameters:
angle - the angle to normalize
Returns:
the normalized angle that will be in the range of [0,2*PI[

normalRelativeAngle

public static double normalRelativeAngle(double angle)
Normalizes an angle to a relative angle. The normalized angle will be in the range from -PI to PI, where PI itself is not included.

Parameters:
angle - the angle to normalize
Returns:
the normalized angle that will be in the range of [-PI,PI[

project

public static java.awt.geom.Point2D.Double project(java.awt.geom.Point2D.Double location,
                                                   double angle,
                                                   double distance)
Projects a location a certain distance along its current angle

Parameters:
location - of the point to project
angle - point is travel
distance - to project the point
Returns:
the new projected point

getMinBulletPower

public static double getMinBulletPower(double damage)

wallSmoothing

public static double wallSmoothing(java.awt.geom.Point2D.Double botLocation,
                                   double angle,
                                   int orientation)
Caculates a "wallsmoothed" angle for a point traveling along a specified angle and a left or right orientation

Parameters:
point - to wallsmooth fro
angle - to project point
orientation - of the robot (-1 / 1)
Returns:
wallsmoothed angle to travel at