diff --git a/src/RumbleBot.java b/src/RumbleBot.java index 453aa75..fada332 100644 --- a/src/RumbleBot.java +++ b/src/RumbleBot.java @@ -4,19 +4,18 @@ import java.util.Random; public class RumbleBot extends Bot { protected final static String obstacles = "~#X*"; - protected final static String targets = "v^<>"; + protected final static String players = "v^<>"; + protected final static String targets = players + "o"; protected Random random = new Random(); protected int steps = 0; public static void main(String[] args) { - if(args.length == 0) { + if (args.length == 0) { String[] dummyArgs = {"localhost", "63187"}; - new Thread(new EnemyBot(dummyArgs)).start(); - new Thread(new EnemyBot(dummyArgs)).start(); - new Thread(new EnemyBot(dummyArgs)).start(); - new Thread(new EnemyBot(dummyArgs)).start(); - new Thread(new EnemyBot(dummyArgs)).start(); + for (int i = 0; i < 5; i++) { + new Thread(new EnemyBot(dummyArgs)).start(); + } } Bot bot = new RumbleBot(args); @@ -50,40 +49,42 @@ public class RumbleBot extends Bot { char[][] grid = new char[size][size]; for (int i = 0; i < data.length(); i++) { char c = data.charAt(i); - if("ABCDEFGHIJKLMNOPQRSTUVWYZ".contains("" + c)) - c = 'A'; + if (Character.isUpperCase(c) && c != 'X') c = 'A'; grid[i % size][i / size] = c; } return grid; } protected void markFiringLines(char[][] grid) { + int[][] dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; int size = grid.length; + for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { - int[][] dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; switch (grid[x][y]) { - case '^' -> markLine(grid, x, y, dir[0], '*'); - case 'v' -> markLine(grid, x, y, dir[1], '*'); - case '>' -> markLine(grid, x, y, dir[2], '*'); - case '<' -> markLine(grid, x, y, dir[3], '*'); + case '^' -> markLine(grid, x, y, dir[0], '*', false); + case 'v' -> markLine(grid, x, y, dir[1], '*', false); + case '>' -> markLine(grid, x, y, dir[2], '*', false); + case '<' -> markLine(grid, x, y, dir[3], '*', false); } - if(targets.contains("" + grid[x][y])) { + if (players.contains("" + grid[x][y])) { for (int[] direction : dir) { - markLine(grid, x, y, direction, 'o'); + markLine(grid, x, y, direction, 'o', true); } } + } } } - private void markLine(char[][] grid, int x, int y, int[] dir, char c) { + private void markLine(char[][] grid, int x, int y, int[] dir, char c, boolean block) { int size = grid.length; x += dir[0]; y += dir[1]; while (x >= 0 && x < size && y >= 0 && y < size && !obstacles.contains("" + grid[x][y])) { + if (grid[x][y] == 'A' && block) break; if (grid[x][y] == '.') { grid[x][y] = c; } @@ -94,11 +95,11 @@ public class RumbleBot extends Bot { protected boolean isInLineOfSight(char[][] grid) { 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])) break; - if (targets.contains("" + grid[size / 2][y])) + if (players.contains("" + grid[size / 2][y])) return true; } return false;