simplify markFiringLines
This commit is contained in:
parent
8c40d7bacb
commit
53482674e6
@ -54,44 +54,26 @@ public class RumbleBot extends Bot {
|
||||
int size = grid.length;
|
||||
for (int x = 0; x < size; x++) {
|
||||
for (int y = 0; y < size; y++) {
|
||||
|
||||
if (grid[x][y] == 'v') {
|
||||
int scanY = y;
|
||||
while (scanY < size && !obstacles.contains("" + grid[x][y])) {
|
||||
if (grid[x][scanY] == '.')
|
||||
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--;
|
||||
switch (grid[x][y]) {
|
||||
case 'v' -> markLine(grid, x, y, 0, 1);
|
||||
case '^' -> markLine(grid, x, y, 0, -1);
|
||||
case '>' -> markLine(grid, x, y, 1, 0);
|
||||
case '<' -> markLine(grid, x, y, -1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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];
|
||||
Queue<Move> queue = new LinkedList<>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user