Browse Source

SnakeBot enemies

master
Your Average Code 11 months ago
parent
commit
a3de94a4f8
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      src/SnakeBot.java

+ 9
- 1
src/SnakeBot.java View File



public class SnakeBot extends Bot { public class SnakeBot extends Bot {
protected final static String obstacles = "~#X*"; protected final static String obstacles = "~#X*";
protected final static char target = '@';
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) {
String[] dummyArgs = {"localhost", "63187"};
for (int i = 0; i < 5; i++) {
new Thread(new SnakeBot(dummyArgs)).start();
}
}

Bot bot = new SnakeBot(args); Bot bot = new SnakeBot(args);
bot.run(); bot.run();
} }
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 (grid[move.x][move.y] == target) 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…
Cancel
Save