|
|
|
|
|
|
|
|
int leftIndex = centerIndex - 1; |
|
|
int leftIndex = centerIndex - 1; |
|
|
int rightIndex = centerIndex + 1; |
|
|
int rightIndex = centerIndex + 1; |
|
|
|
|
|
|
|
|
frontIsBlocked = view.data.charAt(frontIndex) == '*'; |
|
|
|
|
|
backIsBlocked = view.data.charAt(backIndex) == '*'; |
|
|
|
|
|
leftIsBlocked = view.data.charAt(leftIndex) == '*'; |
|
|
|
|
|
rightIsBlocked = view.data.charAt(rightIndex) == '*'; |
|
|
|
|
|
|
|
|
char[] obstacles = {'#', '~', 'X', '*'}; |
|
|
|
|
|
|
|
|
|
|
|
frontIsBlocked = containsChar(obstacles, view.data.charAt(frontIndex)); |
|
|
|
|
|
backIsBlocked = containsChar(obstacles, view.data.charAt(backIndex)); |
|
|
|
|
|
leftIsBlocked = containsChar(obstacles, view.data.charAt(leftIndex)); |
|
|
|
|
|
rightIsBlocked = containsChar(obstacles, view.data.charAt(rightIndex)); |
|
|
|
|
|
|
|
|
trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked; |
|
|
trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked; |
|
|
|
|
|
|
|
|
if (trapped) { |
|
|
if (trapped) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean containsChar(char[] array, char target) { |
|
|
|
|
|
for (char c : array) { |
|
|
|
|
|
if (c == target) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private char checkMove(char move) throws Exception { |
|
|
private char checkMove(char move) throws Exception { |
|
|
if (frontIsBlocked) { |
|
|
if (frontIsBlocked) { |
|
|
resetMovesSequence(); |
|
|
resetMovesSequence(); |