Browse Source

EnemyBot has line of sight

master
Your Average Code 11 months ago
parent
commit
a242381a9d
1 changed files with 21 additions and 1 deletions
  1. 21
    1
      src/EnemyBot.java

+ 21
- 1
src/EnemyBot.java View File



@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;
}
} }

Loading…
Cancel
Save