Package battlecode.common
Class MapLocation
java.lang.Object
battlecode.common.MapLocation
- All Implemented Interfaces:
Serializable,Comparable<MapLocation>
This class is an immutable representation of two-dimensional coordinates
in the battlecode world.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMapLocation(int x, int y) Creates a new MapLocation representing the location with the given coordinates. -
Method Summary
Modifier and TypeMethodDescriptionfinal MapLocationReturns a new MapLocation object representing a location one unit in distance from this one in the given direction.intcompareTo(MapLocation other) A comparison function for MapLocations.final DirectiondirectionTo(MapLocation location) Returns the closest approximate Direction from this MapLocation tolocation.final intdistanceSquaredTo(MapLocation location) Computes the squared distance from this location to the specified location.booleanTwo MapLocations are regarded as equal iff their coordinates are the same.inthashCode()final booleanisAdjacentTo(MapLocation location) Determines whether this location is adjacent to a given location.final booleanisWithinDistanceSquared(MapLocation location, int distanceSquared) Determines whether this location is within a specified distance from target location.final MapLocationReturns a new MapLocation object representing a location one unit in distance from this one in the opposite direction of the given direction.toString()final MapLocationtranslate(int dx, int dy) Returns a new MapLocation object translated from this location by a fixed amount.static MapLocation
-
Field Details
-
x
public final int xThe x-coordinate. -
y
public final int yThe y-coordinate.
-
-
Constructor Details
-
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 locationy- the y-coordinate of the location
-
-
Method Details
-
compareTo
A comparison function for MapLocations. Smaller x values go first, with ties broken by smaller y values.- Specified by:
compareToin interfaceComparable<MapLocation>- Parameters:
other- the MapLocation to compare to.- Returns:
- whether this MapLocation goes before the other one.
- Bytecode cost:
2
-
equals
Two MapLocations are regarded as equal iff their coordinates are the same. -
hashCode
public int hashCode() -
valueOf
-
toString
-
distanceSquaredTo
Computes the squared distance from this location to the specified location.- Parameters:
location- the location to compute the squared distance to- Returns:
- the squared distance to the given location
- Bytecode cost:
2
-
isWithinDistanceSquared
Determines whether this location is within a specified distance from target location.- Parameters:
location- the location to testdistanceSquared- the distance squared for the location to be within- Returns:
- true if the given location is within distanceSquared to this one; false otherwise
- Bytecode cost:
2
-
isAdjacentTo
Determines whether this location is adjacent to a given location.- Parameters:
location- the target location- Returns:
- true if the given location is adjacent to this one
-
directionTo
Returns the closest approximate Direction from this MapLocation tolocation. Iflocationis null then the return value is null. Iflocationequals this location then the return value is Direction.CENTER.- Parameters:
location- The location to which the Direction will be calculated- Returns:
- the Direction to
locationfrom this MapLocation - Bytecode cost:
2
-
add
Returns a new MapLocation object representing a location one unit in distance from this one in the given direction.- Parameters:
direction- the direction to add to this location- Returns:
- a MapLocation for the location one unit in distance in the given direction.
- Bytecode cost:
2
-
subtract
Returns a new MapLocation object representing a location one unit in distance from this one in the opposite direction of the given direction.- Parameters:
direction- the direction to subtract from this location- Returns:
- a MapLocation for the location one unit in distance in the opposite of the given direction.
- Bytecode cost:
2
-
translate
Returns a new MapLocation object translated from this location by a fixed amount.- Parameters:
dx- the amount to translate in the x directiondy- the amount to translate in the y direction- Returns:
- the new MapLocation that is the translated version of the original.
- Bytecode cost:
2
-