Browse Source

simplify markFiringLines

master
Your Average Code 11 months ago
parent
commit
53482674e6
1 changed files with 22 additions and 35 deletions
  1. 22
    35
      src/RumbleBot.java

+ 22
- 35
src/RumbleBot.java View File

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++) {

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;
} }
} }


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…
Cancel
Save