|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected char nextMove(View view) { |
|
|
protected char nextMove(View view) { |
|
|
System.out.println(); |
|
|
|
|
|
|
|
|
|
|
|
int size = view.width; |
|
|
int size = view.width; |
|
|
String data = view.data; |
|
|
String data = view.data; |
|
|
char[][] grid = dataToGrid(data, size); |
|
|
char[][] grid = dataToGrid(data, size); |
|
|
|
|
|
|
|
|
if (data.contains("v") || data.contains("^") || data.contains("<") || data.contains(">")) { |
|
|
|
|
|
if (isInLineOfSight(grid)) { |
|
|
|
|
|
return 'f'; |
|
|
|
|
|
} else { |
|
|
|
|
|
return breadthFirstSearch(grid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (isInLineOfSight(grid)) { |
|
|
|
|
|
return 'f'; |
|
|
|
|
|
} else if (data.contains("v") || data.contains("^") || data.contains("<") || data.contains(">")) { |
|
|
|
|
|
return breadthFirstSearch(grid); |
|
|
} else { |
|
|
} else { |
|
|
return walkAround(grid); |
|
|
return walkAround(grid); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected boolean isInLineOfSight(char[][] grid) { |
|
|
protected boolean isInLineOfSight(char[][] grid) { |
|
|
int size = grid.length; |
|
|
int size = grid.length; |
|
|
for (int y = size / 2; y >= 0; y--) { |
|
|
for (int y = size / 2; y >= 0; y--) { |
|
|
if (obstacles.contains("" + grid[size / 2][y])) |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
if (players.contains("" + grid[size / 2][y])) |
|
|
if (players.contains("" + grid[size / 2][y])) |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
if (obstacles.contains("" + grid[size / 2][y])) |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected char walkAround(char[][] grid) { |
|
|
protected char walkAround(char[][] grid) { |
|
|
|
|
|
int size = grid.length; |
|
|
if (steps == 0) { |
|
|
if (steps == 0) { |
|
|
steps = random.nextInt(20); |
|
|
steps = random.nextInt(20); |
|
|
if(random.nextBoolean()) |
|
|
|
|
|
return '<'; |
|
|
|
|
|
else |
|
|
|
|
|
return '>'; |
|
|
|
|
|
|
|
|
return random.nextBoolean() ? '<' : '>'; |
|
|
} else { |
|
|
} else { |
|
|
steps--; |
|
|
steps--; |
|
|
return safeMove(grid); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected char safeMove(char[][] grid) { |
|
|
|
|
|
int size = grid.length; |
|
|
|
|
|
if (obstacles.contains("" + grid[size / 2][size / 2 - 1])) { |
|
|
|
|
|
return '<'; |
|
|
|
|
|
} else { |
|
|
|
|
|
return '^'; |
|
|
|
|
|
|
|
|
return obstacles.contains("" + grid[size / 2][size / 2 - 1]) ? '<' : '^'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
System.err.println("No path found"); |
|
|
System.err.println("No path found"); |
|
|
return safeMove(grid); |
|
|
|
|
|
|
|
|
return walkAround(grid); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected record Move(int x, int y, char direction) { |
|
|
protected record Move(int x, int y, char direction) { |