| 19 | } |
| 20 | |
| 21 | public static boolean getPath(int x, int y, ArrayList<Point> path) { |
| 22 | // If out of bounds or not available, return. |
| 23 | if (y < 0 || x < 0 || !isFree(x, y)) { |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | boolean isAtOrigin = (x == 0) && (y == 0); |
| 28 | |
| 29 | // If there's a path from the start to my current location, add my location. |
| 30 | if (isAtOrigin || getPath(x, y - 1, path) || getPath(x - 1, y, path)) { |
| 31 | Point p = new Point(x, y); |
| 32 | path.add(p); |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | public static boolean getPath(int x, int y, ArrayList<Point> path, Hashtable<Point, Boolean> cache) { |
| 40 | /* If out of bounds or not available, return.*/ |