RumbleBot detect players with direction
This commit is contained in:
parent
3744c8232e
commit
0bcdabe75e
@ -2,12 +2,18 @@ import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class RumbleBot extends Bot {
|
||||
protected final static String obstacles = "~#X";
|
||||
protected final static String obstacles = "~#X*";
|
||||
protected final static String targets = "v^<>";
|
||||
protected boolean offByOne = true;
|
||||
protected int currentStepCount = 0;
|
||||
protected int steps = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if(args.length == 0) {
|
||||
DummyBot dummy = new DummyBot(args);
|
||||
new Thread(dummy).start();
|
||||
}
|
||||
|
||||
Bot bot = new RumbleBot(args);
|
||||
bot.run();
|
||||
}
|
||||
@ -19,15 +25,12 @@ public class RumbleBot extends Bot {
|
||||
@Override
|
||||
protected char nextMove(View view) {
|
||||
System.out.println();
|
||||
|
||||
int size = view.width;
|
||||
String data = view.data
|
||||
.replace('^', '*')
|
||||
.replace('<', '*')
|
||||
.replace('>', '*')
|
||||
.replace('v', '*');
|
||||
String data = view.data;
|
||||
char[][] grid = dataToGrid(data, size);
|
||||
|
||||
if (data.contains("*")) {
|
||||
if (data.contains("v") || data.contains("^") || data.contains("<") || data.contains(">")) {
|
||||
if (isInLineOfSight(grid)) {
|
||||
return 'f';
|
||||
} else {
|
||||
@ -43,18 +46,21 @@ public class RumbleBot extends Bot {
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
grid[i % size][i / size] = data.charAt(i);
|
||||
}
|
||||
return markFiringLines(grid);
|
||||
}
|
||||
|
||||
protected char[][] markFiringLines(char[][] grid) {
|
||||
return grid;
|
||||
}
|
||||
|
||||
boolean isInLineOfSight(char[][] grid) {
|
||||
protected boolean isInLineOfSight(char[][] grid) {
|
||||
int size = grid.length;
|
||||
for (int y = size / 2; y > 0; y--) {
|
||||
if (obstacles.contains("" + grid[size / 2][y]))
|
||||
break;
|
||||
|
||||
if (grid[size / 2][y] == '*') {
|
||||
if (targets.contains("" + grid[size / 2][y]))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -91,7 +97,7 @@ public class RumbleBot extends Bot {
|
||||
Queue<Move> queue = new LinkedList<>();
|
||||
|
||||
int[][] directions = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
|
||||
char[] commands = {'^', '>', '>', '<'};
|
||||
char[] commands = {'^', 'v', '>', '<'};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
queue.add(new Move(start + directions[i][0], start + directions[i][1], commands[i]));
|
||||
}
|
||||
@ -101,7 +107,7 @@ public class RumbleBot extends Bot {
|
||||
if (move.x < 0 || move.x >= size || move.y < 0 || move.y >= size || visited[move.x][move.y]) continue;
|
||||
visited[move.x][move.y] = true;
|
||||
if (obstacles.contains("" + grid[move.x][move.y])) continue;
|
||||
if (grid[move.x][move.y] == '*') return move.direction;
|
||||
if (targets.contains("" + grid[move.x][move.y])) return move.direction;
|
||||
|
||||
for (int[] direction : directions) {
|
||||
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction));
|
||||
|
Loading…
x
Reference in New Issue
Block a user