import info.gridworld.actor.*; import info.gridworld.grid.*; import java.util.ArrayList; import java.util.List; import java.awt.Color; public class GridChecker { /** The grid to check; guaranteed never to be null */ private BoundedGrid gr; /** @return an Actor in the grid gr with the most neighbors; null if no actors in the grid. */ public Actor actorWithMostNeighbors() { /* to be implemented in part (a) */ } /** Returns a list of all occupied locations in the grid gr that are within 2 rows * and 2 columns of loc. The object references in the returned list may appear in any order. * @param loc a valid location in the grid gr * @return a list of all occupied locations in the grid gr that are within 2 rows * and 2 columns of loc. */ public List getOccupiedWithinTwo(Location loc) { /* to be implemented in part (b) */ } /** method to print out the locations in a list */ private static void printLocs(List locs) { if (locs.size() == 0) { System.out.println("empty list"); return; } for (Location loc: locs) { System.out.println("(" + loc.getRow() + "," + loc.getCol() + ")"); } } /** main for testing */ public static void main(String[] args) { Grid grid = new BoundedGrid(7,7); GridChecker checker = new GridChecker(grid); Actor a = new Rock(); a.putSelfInGrid(grid,new Location(0,0)); a = new Bug(); a.putSelfInGrid(grid,new Location(3,2)); a = new Rock(); a.putSelfInGrid(grid,new Location(3,3)); a = new Critter(); a.putSelfInGrid(grid,new Location(5,4)); a = new Critter(); a.putSelfInGrid(grid,new Location(5,6)); a = checker.actorWithMostNeighbors(); System.out.println("This should be the bug at 3,2 or the rock at 3,3"); System.out.println(a); System.out.println(a.getLocation()); List occLocs = checker.getOccupiedWithinTwo(new Location(0,0)); System.out.println("should be an empty list"); printLocs(occLocs); occLocs = checker.getOccupiedWithinTwo(new Location(1,1)); System.out.println("should be (0,0), (3,2), (3,3)"); printLocs(occLocs); occLocs = checker.getOccupiedWithinTwo(new Location(3,3)); System.out.println("should be (3,2), (5,4)"); printLocs(occLocs); occLocs = checker.getOccupiedWithinTwo(new Location(5,4)); System.out.println("should be (3,2), (3,3), (5,6)"); printLocs(occLocs); occLocs = checker.getOccupiedWithinTwo(new Location(5,6)); System.out.println("should be (5,4)"); printLocs(occLocs); } }