From a3de94a4f8795304773b450d62437a0959c8221f Mon Sep 17 00:00:00 2001 From: Your Average Code <138674451+UrAvgCode@users.noreply.github.com> Date: Thu, 25 Jan 2024 21:27:20 +0100 Subject: [PATCH] SnakeBot enemies --- src/SnakeBot.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SnakeBot.java b/src/SnakeBot.java index b3df2d2..380567a 100644 --- a/src/SnakeBot.java +++ b/src/SnakeBot.java @@ -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));