outsource record Move
This commit is contained in:
parent
a3de94a4f8
commit
3f96b89a47
@ -1,3 +1,5 @@
|
||||
import records.Move;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
@ -80,13 +82,13 @@ public class EscapeBot extends Bot {
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
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) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +96,4 @@ public class EscapeBot extends Bot {
|
||||
return safeMove(grid);
|
||||
}
|
||||
|
||||
protected record Move(int x, int y, char direction) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import records.Move;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
@ -133,13 +135,13 @@ public class RumbleBot extends Bot {
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
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) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +149,4 @@ public class RumbleBot extends Bot {
|
||||
return walkAround(grid);
|
||||
}
|
||||
|
||||
protected record Move(int x, int y, char direction) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
import records.Move;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
@ -107,13 +110,13 @@ public class SnakeBot extends Bot {
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
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) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +124,4 @@ public class SnakeBot extends Bot {
|
||||
return safeMove(grid);
|
||||
}
|
||||
|
||||
protected record Move(int x, int y, char direction) {
|
||||
}
|
||||
|
||||
}
|
||||
|
4
src/records/Move.java
Normal file
4
src/records/Move.java
Normal file
@ -0,0 +1,4 @@
|
||||
package records;
|
||||
|
||||
public record Move(int x, int y, char direction) {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user