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

@@ -3,11 +3,19 @@ import java.util.Queue;

public class SnakeBot extends Bot {
protected final static String obstacles = "~#X*";
protected final static char target = '@';
protected boolean offByOne = true;
protected int currentStepCount = 0;
protected int steps = 0;

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.run();
}
@@ -102,7 +110,7 @@ public class SnakeBot 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 (grid[move.x][move.y] == target) return move.direction;

for (int[] direction : directions) {
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction));

Loading…
Cancel
Save