diff --git a/RumbleBot.java b/RumbleBot.java new file mode 100644 index 0000000..bbff739 --- /dev/null +++ b/RumbleBot.java @@ -0,0 +1,95 @@ +public class RumbleBot extends Bot { + + 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) { + super(args); //Konstruktor der Elternklasse wird aufgerufen + this.shouldFire = false; + } + + // Logik für den RumbleBot, der in Fahrtrichtung schießt + @Override + protected char nextMove(View view) throws Exception { + + // Wenn andere Bots in Sicht sind, wird abgefeuert + if (isOtherBotInSight(view.data)) { + shouldFire = true; + } + + if (shouldFire) { + shouldFire = false; + return 'f'; + } + // 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 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) { + new RumbleBot(args).run(); + } +} \ No newline at end of file diff --git a/out/production/Prog3A-Bot/.idea/.gitignore b/out/production/Prog3A-Bot/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/out/production/Prog3A-Bot/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/Prog3A-Bot/.idea/Prog3A-Bot.iml b/out/production/Prog3A-Bot/.idea/Prog3A-Bot.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/Prog3A-Bot/.idea/Prog3A-Bot.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Prog3A-Bot/.idea/misc.xml b/out/production/Prog3A-Bot/.idea/misc.xml new file mode 100644 index 0000000..8633114 --- /dev/null +++ b/out/production/Prog3A-Bot/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Prog3A-Bot/.idea/modules.xml b/out/production/Prog3A-Bot/.idea/modules.xml new file mode 100644 index 0000000..5b0a7f2 --- /dev/null +++ b/out/production/Prog3A-Bot/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Prog3A-Bot/.idea/vcs.xml b/out/production/Prog3A-Bot/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/Prog3A-Bot/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Prog3A-Bot/Bot$View.class b/out/production/Prog3A-Bot/Bot$View.class new file mode 100644 index 0000000..87e9dc6 Binary files /dev/null and b/out/production/Prog3A-Bot/Bot$View.class differ diff --git a/out/production/Prog3A-Bot/Bot.class b/out/production/Prog3A-Bot/Bot.class new file mode 100644 index 0000000..254ddf0 Binary files /dev/null and b/out/production/Prog3A-Bot/Bot.class differ diff --git a/out/production/Prog3A-Bot/EscapeBot$Node.class b/out/production/Prog3A-Bot/EscapeBot$Node.class new file mode 100644 index 0000000..a049978 Binary files /dev/null and b/out/production/Prog3A-Bot/EscapeBot$Node.class differ diff --git a/out/production/Prog3A-Bot/EscapeBot.class b/out/production/Prog3A-Bot/EscapeBot.class new file mode 100644 index 0000000..8116c06 Binary files /dev/null and b/out/production/Prog3A-Bot/EscapeBot.class differ diff --git a/out/production/Prog3A-Bot/ManualBot.class b/out/production/Prog3A-Bot/ManualBot.class new file mode 100644 index 0000000..d18fcb9 Binary files /dev/null and b/out/production/Prog3A-Bot/ManualBot.class differ diff --git a/out/production/Prog3A-Bot/RumbleBot.class b/out/production/Prog3A-Bot/RumbleBot.class new file mode 100644 index 0000000..fb151c2 Binary files /dev/null and b/out/production/Prog3A-Bot/RumbleBot.class differ diff --git a/out/production/Prog3A-Bot/SnakeBot.class b/out/production/Prog3A-Bot/SnakeBot.class new file mode 100644 index 0000000..96bf9cc Binary files /dev/null and b/out/production/Prog3A-Bot/SnakeBot.class differ