import records.Move; | |||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.Queue; | import java.util.Queue; | ||||
while (!queue.isEmpty()) { | while (!queue.isEmpty()) { | ||||
Move move = queue.poll(); | Move move = queue.poll(); | ||||
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] == 'o') return move.direction; | |||||
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()] == 'o') return move.direction(); | |||||
for (int[] direction : directions) { | for (int[] direction : directions) { | ||||
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction)); | |||||
queue.add(new Move(move.x() + direction[0], move.y() + direction[1], move.direction())); | |||||
} | } | ||||
} | } | ||||
return safeMove(grid); | return safeMove(grid); | ||||
} | } | ||||
protected record Move(int x, int y, char direction) { | |||||
} | |||||
} | } |
import records.Move; | |||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.Queue; | import java.util.Queue; | ||||
import java.util.Random; | import java.util.Random; | ||||
while (!queue.isEmpty()) { | while (!queue.isEmpty()) { | ||||
Move move = queue.poll(); | Move move = queue.poll(); | ||||
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 (targets.contains("" + grid[move.x][move.y])) return move.direction; | |||||
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 (targets.contains("" + grid[move.x()][move.y()])) return move.direction(); | |||||
for (int[] direction : directions) { | for (int[] direction : directions) { | ||||
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction)); | |||||
queue.add(new Move(move.x() + direction[0], move.y() + direction[1], move.direction())); | |||||
} | } | ||||
} | } | ||||
return walkAround(grid); | return walkAround(grid); | ||||
} | } | ||||
protected record Move(int x, int y, char direction) { | |||||
} | |||||
} | } |
import records.Move; | |||||
import java.util.HashSet; | |||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.Queue; | import java.util.Queue; | ||||
while (!queue.isEmpty()) { | while (!queue.isEmpty()) { | ||||
Move move = queue.poll(); | Move move = queue.poll(); | ||||
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] == target) return move.direction; | |||||
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()] == target) return move.direction(); | |||||
for (int[] direction : directions) { | for (int[] direction : directions) { | ||||
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction)); | |||||
queue.add(new Move(move.x() + direction[0], move.y() + direction[1], move.direction())); | |||||
} | } | ||||
} | } | ||||
return safeMove(grid); | return safeMove(grid); | ||||
} | } | ||||
protected record Move(int x, int y, char direction) { | |||||
} | |||||
} | } |
package records; | |||||
public record Move(int x, int y, char direction) { | |||||
} |