src/Praktikum3/SnakeBot.java aktualisiert

This commit is contained in:
Alina Weiss 2025-02-12 09:32:00 +00:00
parent f3f5bf26cc
commit 4b8bffe333

View File

@ -14,7 +14,7 @@ public class SnakeBot extends Bot {
protected char nextMove(View view) {
if (view == null || view.data == null || view.data.isEmpty()) {
System.err.println("FEHLER: View-Daten fehlen! Verbindung unterbrochen?");
return 'q'; // Stoppt sicher
return 'q';
}
int width = view.width;
@ -43,7 +43,7 @@ public class SnakeBot extends Bot {
while (!queue.isEmpty()) {
int current = queue.poll();
if (data.charAt(current) == '@') {
return current; // `@` gefunden, direkt dorthin!
return current;
}
for (int next : getNeighbors(current, width, data)) {
if (!visited.contains(next)) {
@ -52,7 +52,7 @@ public class SnakeBot extends Bot {
}
}
}
return -1; // Keine `@` gefunden
return -1;
}
private List<Integer> getNeighbors(int pos, int width, String data) {
@ -76,7 +76,7 @@ public class SnakeBot extends Bot {
if (tx < x && canMove(pos - 1, data)) return '<';
if (tx > x && canMove(pos + 1, data)) return '>';
return randomMove(); // Falls kein direkter Weg verfügbar ist, bewege dich zufällig
return randomMove();
}
private char exploreStrategically(int pos, int width, String data) {