Dateien hochladen nach „“
This commit is contained in:
parent
3d69d0a6df
commit
64f5e67470
@ -1,11 +1,11 @@
|
||||
package bot;
|
||||
|
||||
|
||||
|
||||
public class RumbleBot extends Bot {
|
||||
|
||||
private boolean shouldFire; // wichtig um den Feuerstatus des Bots zu verfolgen
|
||||
private int currentDirection = 1; // Variable, um die aktuelle Bewegungsrichtung des Rovers zu halten
|
||||
// 0 - oben, 1 - rechts, 2 - unten, 3 - links
|
||||
|
||||
private boolean shouldFire; // wichtig um den Feuerstatus des Bots zu verfolgen
|
||||
|
||||
// Konstruktor für RumbleBot
|
||||
public RumbleBot(String[] args) {
|
||||
@ -16,28 +16,82 @@ public class RumbleBot extends Bot {
|
||||
// Logik für den RumbleBot, der in Fahrtrichtung schießt
|
||||
@Override
|
||||
protected char nextMove(View view) throws Exception {
|
||||
// Logik für den RumbleBot muss hier dann noch implementiert werden
|
||||
|
||||
|
||||
// Wenn andere Bots in Sicht sind, wird gefeuert
|
||||
// Wenn andere Bots in Sicht sind, wird abgefeuert
|
||||
if (isOtherBotInSight(view.data)) {
|
||||
shouldFire = true;
|
||||
}
|
||||
|
||||
if (shouldFire) {
|
||||
shouldFire = false; // Zurücksetzen, damit nicht mehrmals hintereinander geschossen wird
|
||||
return 'f'; // Feuerbefehl
|
||||
shouldFire = false;
|
||||
return 'f';
|
||||
}
|
||||
return 'w'; // nur als Notloesung gedacht fuer den Anfang
|
||||
// Bewegungsbefehl für die nächste Runde generieren
|
||||
char moveCommand = getNextMove(view.data, view.width);
|
||||
|
||||
// Überprüfen, ob der Rover am Rand des Spielfelds ist und die Richtung ändern muss, um im Spielfeld zu bleiben
|
||||
int nextPosition = getNextPosition(view.data.indexOf('A'), view.width, moveCommand);
|
||||
if (nextPosition < 0 || nextPosition >= view.data.length() || view.data.charAt(nextPosition) == '#') {
|
||||
currentDirection++;
|
||||
moveCommand = getNextMove(view.data, view.width); // Neue Richtung erneut berechnen
|
||||
}
|
||||
|
||||
return moveCommand;
|
||||
}
|
||||
|
||||
// Methode zur Berechnung des nächsten Bewegungsbefehls
|
||||
private char getNextMove(String data, int width) {
|
||||
char moveCommand;
|
||||
|
||||
// Aktuelle Bewegungsrichtung des Roboters festlegen
|
||||
int moveDirection = currentDirection % 4; // Modulo 4, um innerhalb des Bereichs von 0 bis 3 zu bleiben
|
||||
|
||||
// Bewegungsbefehl entsprechend der aktuellen Richtung generieren
|
||||
switch (moveDirection) {
|
||||
case 0: // Hoch
|
||||
moveCommand = 'w';
|
||||
break;
|
||||
case 1: // Rechts
|
||||
moveCommand = 'd';
|
||||
break;
|
||||
case 2: // Runter
|
||||
moveCommand = 's';
|
||||
break;
|
||||
case 3: // Links
|
||||
moveCommand = 'a';
|
||||
break;
|
||||
default:
|
||||
moveCommand = ' ';
|
||||
break;
|
||||
}
|
||||
|
||||
return moveCommand;
|
||||
}
|
||||
|
||||
// Methode zur Berechnung der nächsten Position basierend auf der aktuellen Position und dem Bewegungsbefehl
|
||||
private int getNextPosition(int roverPosition, int width, char moveCommand) {
|
||||
switch (moveCommand) {
|
||||
case 'w': // Hoch
|
||||
return roverPosition - width;
|
||||
case 'd': // Rechts
|
||||
return roverPosition + 1;
|
||||
case 's': // Runter
|
||||
return roverPosition + width;
|
||||
case 'a': // Links
|
||||
return roverPosition - 1;
|
||||
default:
|
||||
return -1; // Ungültige Position
|
||||
}
|
||||
}
|
||||
|
||||
// Methode zur Überprüfung, ob andere Bots in Sicht sind
|
||||
private boolean isOtherBotInSight(String data) {
|
||||
// Überprüft, ob anderer Bot in Sicht sind (z.B., "^", "<", ">", "v" in der Karte)
|
||||
// Überprüft, ob andere Bots in Sicht sind (z.B., "^", "<", ">", "v" in der Karte)
|
||||
return data.contains("^") || data.contains("<") || data.contains(">") || data.contains("v");
|
||||
}
|
||||
|
||||
// main Methode um den Bot zu starten
|
||||
public static void main(String[] args) {
|
||||
RumbleBot rumbleBot = new RumbleBot(args);
|
||||
rumbleBot.run();
|
||||
new RumbleBot(args).run();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user