|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected char nextMove(View view) { |
|
|
protected char nextMove(View view) { |
|
|
|
|
|
int size = view.width; |
|
|
String data = view.data |
|
|
String data = view.data |
|
|
.replace('^', '*') |
|
|
.replace('^', '*') |
|
|
.replace('<', '*') |
|
|
.replace('<', '*') |
|
|
.replace('>', '*') |
|
|
.replace('>', '*') |
|
|
.replace('v', '*'); |
|
|
.replace('v', '*'); |
|
|
|
|
|
|
|
|
if (data.contains("*") && random.nextFloat() < 0.8) |
|
|
|
|
|
|
|
|
char[][] grid = dataToGrid(data, size); |
|
|
|
|
|
|
|
|
|
|
|
if (data.contains("*") && isInLineOfSight(grid)) |
|
|
return 'f'; |
|
|
return 'f'; |
|
|
|
|
|
|
|
|
return switch (random.nextInt(10)) { |
|
|
return switch (random.nextInt(10)) { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void print(View view) { |
|
|
protected void print(View view) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected char[][] dataToGrid(String data, int size) { |
|
|
|
|
|
char[][] grid = new char[size][size]; |
|
|
|
|
|
for (int i = 0; i < data.length(); i++) { |
|
|
|
|
|
grid[i % size][i / size] = data.charAt(i); |
|
|
|
|
|
} |
|
|
|
|
|
return grid; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected boolean isInLineOfSight(char[][] grid) { |
|
|
|
|
|
int size = grid.length; |
|
|
|
|
|
for (int y = size / 2; y > 0; y--) { |
|
|
|
|
|
if (grid[size / 2][y] == '*') |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |