A closer look at the world Grid World Part 3 A closer look at the world
Class interactions
Location class (0,0) is top left of grid Constants for direction (row, column) Constants for direction Location.NORTH Constants for common turn angles Location.LEFT, Location.HALF_RIGHT are -90 and 45
Location Methods public Location(int r, int c) public int getRow() public int getCol() public Location getAdjacentLocation(int direction) public int getDirectionToward(Location target) .equals(Location other) .compareTo(Location other) closest to upper left corner goes first
Grid Interface Implemented by BoundedGrid and UnboundedGrid boolean isValid(Location loc) E put(Location loc, E obj) Put object at location and return previous inhabitant or null E remove(Location loc) E get(Location loc) ArrayList<Location> getOccupiedLocations() int getNumRows() int getNumCols()
Grid continued Methods to collect info about surroundings ArrayList<Location> getValidAdjacentLocations(Location loc) ArrayList<Location> getEmptyAdjacentLocations(Location loc) ArrayList<Location> getOccupiedAdjacentLocations(Location loc) ArrayList<Actor> getNeighbors(Location loc)