From 1cdd750c5d298ed5cbe002e74f670c61838c4a02 Mon Sep 17 00:00:00 2001 From: Ben Mojo <155706745+oakes777@users.noreply.github.com> Date: Thu, 3 Apr 2025 14:50:03 -0700 Subject: [PATCH 1/3] JS initial commit, need to add some more tests --- src/SalamanderSearch.java | 75 +++++- src/SalamanderSearchTest.java | 415 +++++++++++++++++----------------- 2 files changed, 281 insertions(+), 209 deletions(-) diff --git a/src/SalamanderSearch.java b/src/SalamanderSearch.java index 688cda7..4e351f0 100644 --- a/src/SalamanderSearch.java +++ b/src/SalamanderSearch.java @@ -1,5 +1,4 @@ -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class SalamanderSearch { public static void main(String[] args) { @@ -18,6 +17,8 @@ public static void main(String[] args) { {'f','W','.','.','W','.'}, {'W','.','W','.','.','.'}, }; + + } /** @@ -43,6 +44,76 @@ public static void main(String[] args) { * @return whether the salamander can reach the food */ public static boolean canReach(char[][] enclosure) { + int[] start = salamanderLocation(enclosure); + boolean[][] visited = new boolean[enclosure.length][enclosure[0].length]; + return canReach(enclosure, start, visited); + } + + public static boolean canReach(char[][] enclosure, int[] current, boolean[][] visited) { + + int curR = current[0]; + int curC = current[1]; + + //base case already been there + if(visited[curR][curC]) return false; + //base case found food + if(enclosure[curR][curC] == 'f') return true; + + visited[curR][curC] = true; + + List moves = possibleMoves(enclosure, current); + for(int[] move : moves) { + if(canReach(enclosure, move, visited)) return true; + } return false; } + + //int array holds {row,col} location of sal + public static int[] salamanderLocation(char[][] enclosure) { + //base case if array null auto produces NPE + for(int r = 0; r < enclosure.length; r++) { + for (int c = 0; c < enclosure[0].length; c++) { + if(enclosure[r][c] == 's') { + return new int[]{r, c}; + } + } + } + throw new IllegalArgumentException("No salamander present"); + } + + public static List possibleMoves(char[][] enclosure, int[] current) { + int curR = current[0]; + int curC = current[1]; + + List moves = new ArrayList<>(); + + // UP + int newR = curR - 1; + int newC = curC; + if(newR >= 0 && enclosure[newR][newC] != 'W') { + moves.add(new int[]{newR, newC}); + } + + // DOWN + newR = curR + 1; + newC = curC; + if(newR < enclosure.length && enclosure[newR][newC] != 'W') { + moves.add(new int[]{newR, newC}); + } + + // LEFT + newR = curR; + newC = curC - 1; + if(newC >= 0 && enclosure[newR][newC] != 'W') { + moves.add(new int[]{newR, newC}); + } + + // RIGHT + newR = curR; + newC = curC + 1; + if(newC < enclosure[0].length && enclosure[newR][newC] != 'W') { + moves.add(new int[]{newR, newC}); + } + return moves; + } } diff --git a/src/SalamanderSearchTest.java b/src/SalamanderSearchTest.java index ddad9de..f3a1e7d 100644 --- a/src/SalamanderSearchTest.java +++ b/src/SalamanderSearchTest.java @@ -11,11 +11,11 @@ public class SalamanderSearchTest { @Test public void canReach_PathExists() { char[][] enclosure = { - {'.','.','.','.','.','.'}, - {'W','.','W','W','.','.'}, - {'.','.','W','.','.','W'}, - {'f','W','.','.','W','.'}, - {'W','.','W','s','.','.'}, + { '.', '.', '.', '.', '.', '.' }, + { 'W', '.', 'W', 'W', '.', '.' }, + { '.', '.', 'W', '.', '.', 'W' }, + { 'f', 'W', '.', '.', 'W', '.' }, + { 'W', '.', 'W', 's', '.', '.' }, }; boolean actual = SalamanderSearch.canReach(enclosure); assertTrue(actual); @@ -24,214 +24,215 @@ public void canReach_PathExists() { @Test public void canReach_NoPath() { char[][] enclosure = { - {'.','.','.','.','.','.'}, - {'W','W','W','W','s','.'}, - {'.','.','W','.','.','W'}, - {'f','W','.','.','W','.'}, - {'W','.','W','.','.','.'}, + { '.', '.', '.', '.', '.', '.' }, + { 'W', 'W', 'W', 'W', 's', '.' }, + { '.', '.', 'W', '.', '.', 'W' }, + { 'f', 'W', '.', '.', 'W', '.' }, + { 'W', '.', 'W', '.', '.', '.' }, }; boolean actual = SalamanderSearch.canReach(enclosure); assertFalse(actual); } - // @Test - // public void testSalamanderLocation_centerOfGrid() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'.', 's', '.'}, - // {'.', '.', '.'} - // }; - // int[] expected = {1, 1}; - // assertArrayEquals(expected, SalamanderSearch.salamanderLocation(enclosure)); - // } - - // @Test - // public void testSalamanderLocation_topLeftCorner() { - // char[][] enclosure = { - // {'s', '.', '.'}, - // {'.', '.', '.'}, - // {'.', '.', '.'} - // }; - // int[] expected = {0, 0}; - // assertArrayEquals(expected, SalamanderSearch.salamanderLocation(enclosure)); - // } - - // @Test - // public void testSalamanderLocation_notFound_throwsException() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'.', '.', '.'}, - // {'.', '.', '.'} - // }; - // Exception exception = assertThrows(IllegalArgumentException.class, () -> { - // SalamanderSearch.salamanderLocation(enclosure); - // }); - // assertEquals("No salamander present", exception.getMessage()); - // } - - - // @Test - // public void testSalamanderLocation_at_1_2() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'.', '.', 's'}, - // {'.', '.', '.'} - // }; - // int[] expected = {1, 2}; - // assertArrayEquals(expected, SalamanderSearch.salamanderLocation(enclosure)); - // } - - // @Test - // public void testPossibleMoves_allDirectionsOpen() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'.', 's', '.'}, - // {'.', '.', '.'} - // }; - // int[] location = {1, 1}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - // Set moveSet = toSet(moves); - - // assertEquals(4, moves.size()); - // assertTrue(moveSet.contains("0,1")); // up - // assertTrue(moveSet.contains("2,1")); // down - // assertTrue(moveSet.contains("1,0")); // left - // assertTrue(moveSet.contains("1,2")); // right - // } - - // @Test - // public void testPossibleMoves_allDirectionsBlockedByWalls() { - // char[][] enclosure = { - // {'W', 'W', 'W'}, - // {'W', 's', 'W'}, - // {'W', 'W', 'W'} - // }; - // int[] location = {1, 1}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - // assertTrue(moves.isEmpty()); - // } - - // @Test - // public void testPossibleMoves_partialEdge() { - // char[][] enclosure = { - // {'s', '.', '.'} - // }; - // int[] location = {0, 0}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - // Set moveSet = toSet(moves); - - // assertEquals(1, moves.size()); - // assertTrue(moveSet.contains("0,1")); // only right - // } - - // @Test - // public void testPossibleMoves_oneOpen_twoWalls_oneEdge() { - // // Salamander at (1, 1) - // // Up is W, down is wall, left is edge (0), right is open - // char[][] enclosure = { - // {'W', 'W', 'W'}, - // {'.', 's', '.'}, - // {'W', 'W', 'W'} - // }; - // int[] location = {1, 1}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - // Set moveSet = toSet(moves); - - // assertEquals(2, moves.size()); - // assertTrue(moveSet.contains("1,2")); - // assertTrue(moveSet.contains("1,0")); - // } - - // @Test - // public void testPossibleMoves_blockedAboveByWall() { - // char[][] enclosure = { - // {'.', 'W', '.'}, - // {'.', 's', '.'}, - // {'.', '.', '.'} - // }; - // int[] location = {1, 1}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - // Set moveSet = toSet(moves); - - // assertFalse(moveSet.contains("0,1")); // up blocked - // assertTrue(moveSet.contains("2,1")); // down open - // assertTrue(moveSet.contains("1,0")); // left open - // assertTrue(moveSet.contains("1,2")); // right open - // } - - // @Test - // public void testPossibleMoves_blockedBelowByWall() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'.', 's', '.'}, - // {'.', 'W', '.'} - // }; - // int[] location = {1, 1}; - // Set moveSet = toSet(SalamanderSearch.possibleMoves(enclosure, location)); - - // assertTrue(moveSet.contains("0,1")); // up open - // assertFalse(moveSet.contains("2,1")); // down blocked - // assertTrue(moveSet.contains("1,0")); // left open - // assertTrue(moveSet.contains("1,2")); // right open - // } - - // @Test - // public void testPossibleMoves_blockedLeftByWall() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'W', 's', '.'}, - // {'.', '.', '.'} - // }; - // int[] location = {1, 1}; - // Set moveSet = toSet(SalamanderSearch.possibleMoves(enclosure, location)); - - // assertTrue(moveSet.contains("0,1")); // up open - // assertTrue(moveSet.contains("2,1")); // down open - // assertFalse(moveSet.contains("1,0")); // left blocked - // assertTrue(moveSet.contains("1,2")); // right open - // } - - // @Test - // public void testPossibleMoves_blockedRightByWall() { - // char[][] enclosure = { - // {'.', '.', '.'}, - // {'.', 's', 'W'}, - // {'.', '.', '.'} - // }; - // int[] location = {1, 1}; - // Set moveSet = toSet(SalamanderSearch.possibleMoves(enclosure, location)); - - // assertTrue(moveSet.contains("0,1")); // up open - // assertTrue(moveSet.contains("2,1")); // down open - // assertTrue(moveSet.contains("1,0")); // left open - // assertFalse(moveSet.contains("1,2")); // right blocked - // } - - // @Test - // public void testPossibleMoves_topLeftCornerWithOneOpen() { - // char[][] enclosure = { - // {'s', 'W'}, - // {'W', '.'} - // }; - // int[] location = {0, 0}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - - // assertTrue(moves.isEmpty()); // surrounded by walls/edges - // } - - // @Test - // public void testPossibleMoves_rightEdgeWithOpenLeft() { - // char[][] enclosure = { - // {'.', '.', 's'} - // }; - // int[] location = {0, 2}; - // List moves = SalamanderSearch.possibleMoves(enclosure, location); - // Set moveSet = toSet(moves); - - // assertEquals(1, moves.size()); - // assertTrue(moveSet.contains("0,1")); - // } + @Test + public void testSalamanderLocation_centerOfGrid() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', 's', '.' }, + { '.', '.', '.' } + }; + int[] expected = { 1, 1 }; + assertArrayEquals(expected, SalamanderSearch.salamanderLocation(enclosure)); + } + + @Test + public void testSalamanderLocation_topLeftCorner() { + char[][] enclosure = { + { 's', '.', '.' }, + { '.', '.', '.' }, + { '.', '.', '.' } + }; + int[] expected = { 0, 0 }; + assertArrayEquals(expected, SalamanderSearch.salamanderLocation(enclosure)); + } + + @Test + public void testSalamanderLocation_notFound_throwsException() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', '.', '.' }, + { '.', '.', '.' } + }; + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + SalamanderSearch.salamanderLocation(enclosure); + }); + assertEquals("No salamander present", exception.getMessage()); + } + + @Test + public void testSalamanderLocation_at_1_2() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', '.', 's' }, + { '.', '.', '.' } + }; + int[] expected = { 1, 2 }; + assertArrayEquals(expected, SalamanderSearch.salamanderLocation(enclosure)); + } + + @Test + public void testPossibleMoves_allDirectionsOpen() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', 's', '.' }, + { '.', '.', '.' } + }; + int[] location = { 1, 1 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + Set moveSet = toSet(moves); + + assertEquals(4, moves.size()); + assertTrue(moveSet.contains("0,1")); // up + assertTrue(moveSet.contains("2,1")); // down + assertTrue(moveSet.contains("1,0")); // left + assertTrue(moveSet.contains("1,2")); // right + } + + @Test + public void testPossibleMoves_allDirectionsBlockedByWalls() { + char[][] enclosure = { + { 'W', 'W', 'W' }, + { 'W', 's', 'W' }, + { 'W', 'W', 'W' } + }; + int[] location = { 1, 1 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + assertTrue(moves.isEmpty()); + } + + @Test + public void testPossibleMoves_partialEdge() { + char[][] enclosure = { + { 's', '.', '.' } + }; + int[] location = { 0, 0 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + Set moveSet = toSet(moves); + + assertEquals(1, moves.size()); + assertTrue(moveSet.contains("0,1")); // only right + } + + @Test + public void testPossibleMoves_oneOpen_twoWalls_oneEdge() { + // Salamander at (1, 1) + // Up is W, down is wall, left is edge (0), right is open + char[][] enclosure = { + { 'W', 'W', 'W' }, + { '.', 's', '.' }, + { 'W', 'W', 'W' } + }; + int[] location = { 1, 1 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + Set moveSet = toSet(moves); + + assertEquals(2, moves.size()); + assertTrue(moveSet.contains("1,2")); + assertTrue(moveSet.contains("1,0")); + } + + @Test + public void testPossibleMoves_blockedAboveByWall() { + char[][] enclosure = { + { '.', 'W', '.' }, + { '.', 's', '.' }, + { '.', '.', '.' } + }; + int[] location = { 1, 1 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + Set moveSet = toSet(moves); + + assertFalse(moveSet.contains("0,1")); // up blocked + assertTrue(moveSet.contains("2,1")); // down open + assertTrue(moveSet.contains("1,0")); // left open + assertTrue(moveSet.contains("1,2")); // right open + } + + @Test + public void testPossibleMoves_blockedBelowByWall() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', 's', '.' }, + { '.', 'W', '.' } + }; + int[] location = { 1, 1 }; + Set moveSet = toSet(SalamanderSearch.possibleMoves(enclosure, + location)); + + assertTrue(moveSet.contains("0,1")); // up open + assertFalse(moveSet.contains("2,1")); // down blocked + assertTrue(moveSet.contains("1,0")); // left open + assertTrue(moveSet.contains("1,2")); // right open + } + + @Test + public void testPossibleMoves_blockedLeftByWall() { + char[][] enclosure = { + { '.', '.', '.' }, + { 'W', 's', '.' }, + { '.', '.', '.' } + }; + int[] location = { 1, 1 }; + Set moveSet = toSet(SalamanderSearch.possibleMoves(enclosure, + location)); + + assertTrue(moveSet.contains("0,1")); // up open + assertTrue(moveSet.contains("2,1")); // down open + assertFalse(moveSet.contains("1,0")); // left blocked + assertTrue(moveSet.contains("1,2")); // right open + } + + @Test + public void testPossibleMoves_blockedRightByWall() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', 's', 'W' }, + { '.', '.', '.' } + }; + int[] location = { 1, 1 }; + Set moveSet = toSet(SalamanderSearch.possibleMoves(enclosure, + location)); + + assertTrue(moveSet.contains("0,1")); // up open + assertTrue(moveSet.contains("2,1")); // down open + assertTrue(moveSet.contains("1,0")); // left open + assertFalse(moveSet.contains("1,2")); // right blocked + } + + @Test + public void testPossibleMoves_topLeftCornerWithOneOpen() { + char[][] enclosure = { + { 's', 'W' }, + { 'W', '.' } + }; + int[] location = { 0, 0 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + assertTrue(moves.isEmpty()); // surrounded by walls/edges + } + + @Test + public void testPossibleMoves_rightEdgeWithOpenLeft() { + char[][] enclosure = { + { '.', '.', 's' } + }; + int[] location = { 0, 2 }; + List moves = SalamanderSearch.possibleMoves(enclosure, location); + Set moveSet = toSet(moves); + + assertEquals(1, moves.size()); + assertTrue(moveSet.contains("0,1")); + } private Set toSet(List list) { Set set = new HashSet<>(); From c581c8c2ea237bea255a84111c3a257a191bf416 Mon Sep 17 00:00:00 2001 From: Ben Mojo <155706745+oakes777@users.noreply.github.com> Date: Thu, 3 Apr 2025 16:05:10 -0700 Subject: [PATCH 2/3] JS final commit added 4 unit tests to canReach --- src/SalamanderSearchTest.java | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/SalamanderSearchTest.java b/src/SalamanderSearchTest.java index f3a1e7d..63a7499 100644 --- a/src/SalamanderSearchTest.java +++ b/src/SalamanderSearchTest.java @@ -34,6 +34,59 @@ public void canReach_NoPath() { assertFalse(actual); } + // additional unit tests for canReach + // sal adjacent to food + @Test + public void canReach_StartAdjacentToFood() { + char[][] enclosure = { + { '.', '.', '.' }, + { '.', 's', 'f' }, + { '.', '.', '.' } + }; + + boolean actual = SalamanderSearch.canReach(enclosure); + assertTrue(actual); + } + + // food Walled in! + @Test + public void canReach_FoodWalledIn() { + char[][] enclosure = { + { '.', '.', '.', '.', '.' }, + { '.', 's', 'W', '.', '.' }, + { '.', 'W', 'f', 'W', '.' }, + { '.', '.', 'W', '.', '.' }, + }; + boolean actual = SalamanderSearch.canReach(enclosure); + assertFalse(actual); + } + + // multiple possible paths to food + @Test + public void canReach_MultiplePathsAvailable() { + char[][] enclosure = { + { '.', '.', '.', '.', 'f' }, + { 's', 'W', '.', 'W', '.' }, + { '.', '.', '.', '.', '.' }, + }; + boolean actual = SalamanderSearch.canReach(enclosure); + assertTrue(actual); + } + + // extra large grid + @Test + public void canReach_LargeMazeComplexPath() { + char[][] enclosure = { + { 's', 'W', '.', '.', '.', '.', '.', '.', '.', '.' }, + { '.', 'W', '.', 'W', 'W', 'W', 'W', 'W', '.', '.' }, + { '.', '.', '.', '.', '.', '.', '.', 'W', '.', '.' }, + { '.', 'W', 'W', 'W', 'W', 'W', '.', 'W', '.', '.' }, + { '.', '.', '.', '.', '.', 'W', '.', '.', '.', 'f' } + }; + boolean actual = SalamanderSearch.canReach(enclosure); + assertTrue(actual); + } + @Test public void testSalamanderLocation_centerOfGrid() { char[][] enclosure = { From dbbb4fb226e2adc0704e0acc2ae79ab11d854500 Mon Sep 17 00:00:00 2001 From: Ben Mojo <155706745+oakes777@users.noreply.github.com> Date: Tue, 8 Apr 2025 14:26:04 -0700 Subject: [PATCH 3/3] JS commit refactored possibleMoves --- .vscode/settings.json | 5 ++ src/SalamanderSearch.java | 123 ++++++++++++++++++++++++-------------- 2 files changed, 83 insertions(+), 45 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b242572 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file diff --git a/src/SalamanderSearch.java b/src/SalamanderSearch.java index 4e351f0..6c5538f 100644 --- a/src/SalamanderSearch.java +++ b/src/SalamanderSearch.java @@ -3,21 +3,33 @@ public class SalamanderSearch { public static void main(String[] args) { char[][] enclosure1 = { - {'.','.','.','.','.','.'}, - {'W','.','W','W','.','.'}, - {'.','.','W','.','.','W'}, - {'f','W','.','.','W','.'}, - {'W','.','W','s','.','.'}, + { '.', '.', '.', '.', '.', '.' }, + { 'W', '.', 'W', 'W', '.', '.' }, + { '.', '.', 'W', '.', '.', 'W' }, + { 'f', 'W', '.', '.', 'W', '.' }, + { 'W', '.', 'W', 's', '.', '.' }, }; char[][] enclosure2 = { - {'.','.','.','.','.','.'}, - {'W','W','W','W','s','.'}, - {'.','.','W','.','.','W'}, - {'f','W','.','.','W','.'}, - {'W','.','W','.','.','.'}, + { '.', '.', '.', '.', '.', '.' }, + { 'W', 'W', 'W', 'W', 's', '.' }, + { '.', '.', 'W', '.', '.', 'W' }, + { 'f', 'W', '.', '.', 'W', '.' }, + { 'W', '.', 'W', '.', '.', '.' }, }; + Set coordinateSet = new HashSet<>(); + int[] coord1 = new int[] { 1, 5 }; + int[] coord2 = new int[] { 3, 7 }; + int[] coord3 = new int[] { 1, 5 }; + + coordinateSet.add(coord1); + coordinateSet.add(coord2); + coordinateSet.add(coord3); + + // the actual contents are not what's been added, it's the references to each + // variable that's added! + System.out.println(coordinateSet.size()); } @@ -50,31 +62,34 @@ public static boolean canReach(char[][] enclosure) { } public static boolean canReach(char[][] enclosure, int[] current, boolean[][] visited) { - + int curR = current[0]; int curC = current[1]; - //base case already been there - if(visited[curR][curC]) return false; - //base case found food - if(enclosure[curR][curC] == 'f') return true; + // base case already been there + if (visited[curR][curC]) + return false; + // base case found food + if (enclosure[curR][curC] == 'f') + return true; visited[curR][curC] = true; List moves = possibleMoves(enclosure, current); - for(int[] move : moves) { - if(canReach(enclosure, move, visited)) return true; + for (int[] move : moves) { + if (canReach(enclosure, move, visited)) + return true; } return false; } - //int array holds {row,col} location of sal + // int array holds {row,col} location of sal public static int[] salamanderLocation(char[][] enclosure) { - //base case if array null auto produces NPE - for(int r = 0; r < enclosure.length; r++) { + // base case if array null auto produces NPE + for (int r = 0; r < enclosure.length; r++) { for (int c = 0; c < enclosure[0].length; c++) { - if(enclosure[r][c] == 's') { - return new int[]{r, c}; + if (enclosure[r][c] == 's') { + return new int[] { r, c }; } } } @@ -87,33 +102,51 @@ public static List possibleMoves(char[][] enclosure, int[] current) { List moves = new ArrayList<>(); - // UP - int newR = curR - 1; - int newC = curC; - if(newR >= 0 && enclosure[newR][newC] != 'W') { - moves.add(new int[]{newR, newC}); - } + int[][] directions = new int[][] { + { -1, 0 }, + { 1, 0 }, + { 0, -1 }, + { 0, 1 } + }; - // DOWN - newR = curR + 1; - newC = curC; - if(newR < enclosure.length && enclosure[newR][newC] != 'W') { - moves.add(new int[]{newR, newC}); - } + for (int[] direction : directions) { + int newR = curR + direction[0]; + int newC = curC + direction[1]; + if (newR >= 0 && newR < enclosure.length && + newC >= 0 && newC < enclosure[0].length && + enclosure[newR][newC] != 'W') { + moves.add(new int[] { newR, newC }); + } - // LEFT - newR = curR; - newC = curC - 1; - if(newC >= 0 && enclosure[newR][newC] != 'W') { - moves.add(new int[]{newR, newC}); } - // RIGHT - newR = curR; - newC = curC + 1; - if(newC < enclosure[0].length && enclosure[newR][newC] != 'W') { - moves.add(new int[]{newR, newC}); - } + // // UP + // int newR = curR - 1; + // int newC = curC; + // if(newR >= 0 && enclosure[newR][newC] != 'W') { + // moves.add(new int[]{newR, newC}); + // } + + // // DOWN + // newR = curR + 1; + // newC = curC; + // if(newR < enclosure.length && enclosure[newR][newC] != 'W') { + // moves.add(new int[]{newR, newC}); + // } + + // // LEFT + // newR = curR; + // newC = curC - 1; + // if(newC >= 0 && enclosure[newR][newC] != 'W') { + // moves.add(new int[]{newR, newC}); + // } + + // // RIGHT + // newR = curR; + // newC = curC + 1; + // if(newC < enclosure[0].length && enclosure[newR][newC] != 'W') { + // moves.add(new int[]{newR, newC}); + // } return moves; } }