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