robocraft.common
Class MapLocation

java.lang.Object
  extended byrobocraft.common.MapLocation
All Implemented Interfaces:
java.io.Serializable

public final class MapLocation
extends java.lang.Object
implements java.io.Serializable

MapLocation is just a wrapper for a pair of integer coordinates that indentify a point on the RoboCraft map. MapLocations are immutable.

See Also:
Serialized Form

Constructor Summary
MapLocation(int x_, int y_)
          creates a new MapLocation with the given coordinates.
 
Method Summary
 MapLocation add(Direction dir)
          returns a new maplocation that is one square in the direction of dir from this.
 Direction directionToAdjacent(MapLocation loc)
          Return the exact direction towards an adjacent square.
 int distanceSquaredTo(MapLocation loc)
           
 boolean equals(java.lang.Object obj)
          two map locations are equal if and only if both their x and y locations are ==.
 int hashCode()
           
 boolean isAdjacentTo(MapLocation loc2)
          Determines whether a given maplocation is "adjacent" to this.
 MapLocation randomNeighbor()
          returns a random neigboring map location l where l.isAdjacentTo(this)
 MapLocation subtract(Direction dir)
          returns a new maplocation that is one square in the direction opposite of dir from this.
 java.lang.String toString()
          returns a string representation that looks like [x,y]
 int x()
           
 int y()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapLocation

public MapLocation(int x_,
                   int y_)
creates a new MapLocation with the given coordinates.

Method Detail

x

public int x()
Returns:
x-coordinate of this MapLocation.

y

public int y()
Returns:
y-coordinate of this MapLocation.

isAdjacentTo

public boolean isAdjacentTo(MapLocation loc2)
Determines whether a given maplocation is "adjacent" to this. There are exactly 8 squares adjacent to any given square, and those are the 8 squares north, northeast, east, etc., in all directions around it. A square is not adjacent to itself.


toString

public java.lang.String toString()
returns a string representation that looks like [x,y]


equals

public boolean equals(java.lang.Object obj)
two map locations are equal if and only if both their x and y locations are ==.


hashCode

public int hashCode()

randomNeighbor

public MapLocation randomNeighbor()
returns a random neigboring map location l where l.isAdjacentTo(this)


add

public MapLocation add(Direction dir)
returns a new maplocation that is one square in the direction of dir from this.


subtract

public MapLocation subtract(Direction dir)
returns a new maplocation that is one square in the direction opposite of dir from this.


distanceSquaredTo

public int distanceSquaredTo(MapLocation loc)
Returns:
(this.x - loc.x)^2 + (this.y - loc.y)^2

directionToAdjacent

public Direction directionToAdjacent(MapLocation loc)
Return the exact direction towards an adjacent square.

Parameters:
loc - an square adjacent to this
Returns:
the direction from this to loc, or Direction.NONE if loc is not adjacent to this.