EnemyBot has line of sight
This commit is contained in:
parent
9c555c9cde
commit
a242381a9d
@ -9,13 +9,16 @@ public class EnemyBot extends Bot {
|
|||||||
|
|
||||||
@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)) {
|
||||||
@ -29,4 +32,21 @@ public class EnemyBot extends Bot {
|
|||||||
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user