From 0bcdabe75e03b83beccb1d8e32c22fef37836643 Mon Sep 17 00:00:00 2001 From: Your Average Code <138674451+UrAvgCode@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:57:34 +0100 Subject: [PATCH] RumbleBot detect players with direction --- src/RumbleBot.java | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/RumbleBot.java b/src/RumbleBot.java index f596ef3..d081b5a 100644 --- a/src/RumbleBot.java +++ b/src/RumbleBot.java @@ -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 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));