de.uni_paderborn.robots.robot.group10
Class Map.Coordinate

java.lang.Object
  |
  +--de.uni_paderborn.robots.robot.group10.Map.Coordinate
Enclosing class:
Map

public class Map.Coordinate
extends java.lang.Object

Stores x and y coordinates and area information (when robot uses a wormhole). It is also capable of using modulo values for the coordinates in order to support cyclic arenas. The modulos are read from Map.getHorizontalCycleSize() and Map.getVerticalCycleSize().


Field Summary
protected  int area
          The coordinate "name space".
protected  int x
          The horizontal part of the coordinate
protected  int y
          The vertical part of the coordinate
 
Constructor Summary
Map.Coordinate(int x, int y, int area)
          Creates a Coordinate object using the given values.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares two coordinates.
 int getArea()
          Read access method for the field area.
 Map.Coordinate getCoordinateByDirection(int direction)
          Calculates the coordinate of the position neighbored by the position represented by this object.
 int getX()
          Read access method for the field x.
 int getY()
          Read access method for the field y.
 int hashCode()
          More or less efficient hash calculation for this datatype
 void moduloChanged()
          Should be called when the values Map.horizontalCycleSize or Map.verticalCycleSize have changed
protected  int posMod(int a, int b)
          Returns a modulo b.
 java.lang.String toString()
          Returns a string representation of the coordinate.
 Map.Coordinate transform(Map.Coordinate c)
          Adds two coordinates.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

x

protected int x
The horizontal part of the coordinate

y

protected int y
The vertical part of the coordinate

area

protected int area
The coordinate "name space". Used when a robot uses a wormhole and thus has to create coordinates that are independant from the previously recorded coordinates
Constructor Detail

Map.Coordinate

public Map.Coordinate(int x,
                      int y,
                      int area)
Creates a Coordinate object using the given values.
Parameters:
x - the horizontal part of the coordiante
y - the vertical part of the coordinate
area - the coordinate "name space"
Method Detail

getX

public int getX()
Read access method for the field x.
Returns:
x the horizontal part of the coordinate

getY

public int getY()
Read access method for the field y.
Returns:
y the vertical part of the coordinate

getArea

public int getArea()
Read access method for the field area.
Returns:
area the "name space" of the coordinate

posMod

protected int posMod(int a,
                     int b)
Returns a modulo b. Takes care that the result is always the lowest possible positive result.
Parameters:
a - the dividend for the modulo operation
b - the divisor for the modulo operation
Returns:
a mod b, guaranteed to be the lowest possible positive result

moduloChanged

public void moduloChanged()
Should be called when the values Map.horizontalCycleSize or Map.verticalCycleSize have changed

equals

public boolean equals(java.lang.Object o)
Compares two coordinates. Takes also the modulo values into account, i.e. values that are in the same "restklassenring" are also regarded as equal.
Overrides:
equals in class java.lang.Object
Parameters:
o - Object to be compared
Returns:
true if the objects describe the same position in the arena.

hashCode

public int hashCode()
More or less efficient hash calculation for this datatype
Overrides:
hashCode in class java.lang.Object
Returns:
the hash value of this object. This value does not neccessarily identify this object or the coordinate

getCoordinateByDirection

public Map.Coordinate getCoordinateByDirection(int direction)
Calculates the coordinate of the position neighbored by the position represented by this object. The object is not affected by this operation.
Parameters:
direction - the direction which to calculate the coordinate for
Returns:
the newly calculated coordinate

transform

public Map.Coordinate transform(Map.Coordinate c)
Adds two coordinates. The object is not affected by this operation.
Parameters:
c - the coordinate to add
Returns:
the newly calculated coordinate

toString

public java.lang.String toString()
Returns a string representation of the coordinate. Coordinate implements the toString() method to ease debugging.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the coordinate in the format "x: n, y: n, a: n"