/** * Finds all empty nearby spaces * * @return a point that is adjacent and empty */ public Point nearEmpty() { Point temp; ArrayList<Point> available = new ArrayList<Point>(); final Point location = summative.getLocation(this); assert (location != null); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { temp = new Point(location.x + x, location.y + y); if (summative.emptyAt(temp) && (summative.terrainGet(temp)) == TERRAIN.LAND) { available.add(temp); } } } if (available.size() > 0) { return available.get((int) (Math.random() * available.size())); } else { return null; } }