simplify markFiringLines
This commit is contained in:
parent
8c40d7bacb
commit
53482674e6
@ -54,44 +54,26 @@ public class RumbleBot extends Bot {
|
|||||||
int size = grid.length;
|
int size = grid.length;
|
||||||
for (int x = 0; x < size; x++) {
|
for (int x = 0; x < size; x++) {
|
||||||
for (int y = 0; y < size; y++) {
|
for (int y = 0; y < size; y++) {
|
||||||
|
switch (grid[x][y]) {
|
||||||
if (grid[x][y] == 'v') {
|
case 'v' -> markLine(grid, x, y, 0, 1);
|
||||||
int scanY = y;
|
case '^' -> markLine(grid, x, y, 0, -1);
|
||||||
while (scanY < size && !obstacles.contains("" + grid[x][y])) {
|
case '>' -> markLine(grid, x, y, 1, 0);
|
||||||
if (grid[x][scanY] == '.')
|
case '<' -> markLine(grid, x, y, -1, 0);
|
||||||
grid[x][scanY] = '*';
|
}
|
||||||
scanY++;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grid[x][y] == '^') {
|
|
||||||
int scanY = y;
|
|
||||||
while (scanY >= 0 && !obstacles.contains("" + grid[x][y])) {
|
|
||||||
if (grid[x][scanY] == '.')
|
|
||||||
grid[x][scanY] = '*';
|
|
||||||
scanY--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grid[x][y] == '>') {
|
|
||||||
int scanX = x;
|
|
||||||
while (scanX < size && !obstacles.contains("" + grid[x][y])) {
|
|
||||||
if (grid[scanX][y] == '.')
|
|
||||||
grid[scanX][y] = '*';
|
|
||||||
scanX++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grid[x][y] == '<') {
|
|
||||||
int scanX = x;
|
|
||||||
while (scanX >= 0 && !obstacles.contains("" + grid[x][y])) {
|
|
||||||
if (grid[scanX][y] == '.')
|
|
||||||
grid[scanX][y] = '*';
|
|
||||||
scanX--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void markLine(char[][] grid, int x, int y, int dx, int dy) {
|
||||||
|
int size = grid.length;
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
while (x >= 0 && x < size && y >= 0 && y < size && !obstacles.contains("" + grid[x][y])) {
|
||||||
|
if (grid[x][y] == '.') {
|
||||||
|
grid[x][y] = '*';
|
||||||
}
|
}
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +118,11 @@ public class RumbleBot extends Bot {
|
|||||||
int size = grid.length;
|
int size = grid.length;
|
||||||
int start = size / 2;
|
int start = size / 2;
|
||||||
|
|
||||||
|
for (int y = 0; y < size; y++) {
|
||||||
|
for (char[] chars : grid) System.err.print(chars[y]);
|
||||||
|
System.err.println();
|
||||||
|
}
|
||||||
|
|
||||||
boolean[][] visited = new boolean[size][size];
|
boolean[][] visited = new boolean[size][size];
|
||||||
Queue<Move> queue = new LinkedList<>();
|
Queue<Move> queue = new LinkedList<>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user