Appendix B Testable API
Appendix B — Testable API
info.gridworld.grid.Location class (implements Comparable)
public Location(int r, int c)
constructs a location with given row and column coordinates
public int getRow()
returns the row of this location
public int getCol()
returns the column of this location
public Location getAdjacentLocation(int direction)
returns the adjacent location in the direction that is closest to
direction
public int getDirectionToward(Location target)
returns the closest compass direction from this location toward
target
public boolean equals(Object other)
returns
true if other is a Location with the same row and column as this location; false otherwise
public int hashCode()
returns a hash code for this location
public int compareTo(Object other)
returns a negative integer if this location is less than
other, zero if the two locations are equal, or a positive
integer if this location is greater than
other. Locations are ordered in row-major order.
Precondition:
other is a Location object.
public String toString()
returns a string with the row and column of this location, in the format (row, col)
Compass directions:
public static final int NORTH = 0;
public static final int EAST = 90;
public static final int SOUTH = 180;
public static final int WEST = 270;
public static final int NORTHEAST = 45;
public static final int SOUTHEAST = 135;
public static final int SOUTHWEST = 225;
public static final int NORTHWEST = 315;
Turn angles:
public static final int LEFT = -90;
public static final int RIGHT = 90;
public static final int HALF_LEFT = -45;
public static final int HALF_RIGHT = 45;
public static final int FULL_CIRCLE = 360;
public static final int HALF_CIRCLE = 180;
public static final int AHEAD = 0;
-B1-