battlecode.common
Class MapLocation

java.lang.Object
  extended by battlecode.common.MapLocation
All Implemented Interfaces:
Serializable

public final class MapLocation
extends Object
implements Serializable

This class is an immutable representation of two-dimensional coordinates in the battlecode world.

See Also:
Serialized Form

Field Summary
 int x
          The x-coordinate.
 int y
          The y-coordinate.
 
Constructor Summary
MapLocation(int x, int y)
          Creates a new MapLocation representing the location with the given coordinates.
 
Method Summary
 MapLocation add(Direction direction)
          Returns a new MapLocation object representing a location one square from this one in the given direction.
 MapLocation add(Direction direction, int multiple)
          Returns a new MapLocation object representing a location multiple squares from this one in the given direction.
 MapLocation add(int dx, int dy)
          Returns a new MapLocation object translated from this location by a fixed amount
 Direction directionTo(MapLocation location)
          Returns the Direction from this MapLocation to location.
 int distanceSquaredTo(MapLocation location)
          Computes the square of the distance from this location to the specified location.
 boolean equals(Object obj)
          Two MapLocations are regarded as equal iff their coordinates are the same.
 int hashCode()
          
 boolean isAdjacentTo(MapLocation location)
          Determines whether this location is adjacent to the specified location.
 MapLocation subtract(Direction direction)
          Returns a new MapLocation object representing a location one square from this one in the opposite of the given direction.
 String toString()
          
static MapLocation valueOf(String s)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public final int x
The x-coordinate.


y

public final int y
The y-coordinate.

Constructor Detail

MapLocation

public MapLocation(int x,
                   int y)
Creates a new MapLocation representing the location with the given coordinates.

Parameters:
x - the x-coordinate of the location
y - the y-coordinate of the location
Method Detail

equals

public boolean equals(Object obj)
Two MapLocations are regarded as equal iff their coordinates are the same.

Overrides:
equals in class Object
Bytecode cost:
5

hashCode

public int hashCode()

Overrides:
hashCode in class Object
Bytecode cost:
10

valueOf

public static MapLocation valueOf(String s)
Bytecode cost:
25

toString

public String toString()

Overrides:
toString in class Object
Bytecode cost:
10

distanceSquaredTo

public final int distanceSquaredTo(MapLocation location)
Computes the square of the distance from this location to the specified location.

Parameters:
location - the location to compute the distance squared to
Returns:
the distance to the given location squared
Bytecode cost:
10

isAdjacentTo

public final boolean isAdjacentTo(MapLocation location)
Determines whether this location is adjacent to the specified location. Note that squares cannot be adjacent to themselves.

Parameters:
location - the location to test
Returns:
true if the given location is adjacent to this one, or false if it isn't
Bytecode cost:
10

directionTo

public final Direction directionTo(MapLocation location)
Returns the Direction from this MapLocation to location. If the locations are equal this method returns Direction.OMNI. If location is null then the return value is Direction.NONE.

Parameters:
location - The location to which the Direction will be calculated
Returns:
The Direction to location from this MapLocation.
Bytecode cost:
10

add

public final MapLocation add(Direction direction)
Returns a new MapLocation object representing a location one square from this one in the given direction.

Parameters:
direction - the direction to add to this location
Returns:
a MapLocation for the location one square in the given direction, or this location if the direction is NONE or OMNI
Bytecode cost:
5

add

public final MapLocation add(Direction direction,
                             int multiple)
Returns a new MapLocation object representing a location multiple squares from this one in the given direction.

Parameters:
direction - the direction to add to this location
multiple - the number of squares to add
Returns:
a MapLocation for the location one square in the given direction, or this location if the direction is NONE or OMNI
Bytecode cost:
5

add

public final MapLocation add(int dx,
                             int dy)
Returns a new MapLocation object translated from this location by a fixed amount

Parameters:
dx - the amount to translate in the x direction
dy - the amount to translate in the y direction
Bytecode cost:
5

subtract

public final MapLocation subtract(Direction direction)
Returns a new MapLocation object representing a location one square from this one in the opposite of the given direction.

Parameters:
direction - the direction to subtract from this location
Returns:
a MapLocation for the location one square opposite the given direction, or this location if the direction is NONE or OMNI
Bytecode cost:
5