@@ -0,0 +1,90 @@ | |||
package praktikum05; | |||
import java.util.LinkedList; | |||
import java.util.Queue; | |||
import java.util.Random; | |||
import java.util.Scanner; | |||
public class EscapeBot extends Bot { | |||
private boolean rocketFound = false; | |||
public static void main(String[] args) { | |||
EscapeBot escapeBot = new EscapeBot(args); | |||
escapeBot.run(); | |||
} | |||
protected EscapeBot(String[] args) { | |||
super(args); | |||
} | |||
@Override | |||
protected char nextMove(View view) throws Exception { | |||
if (!rocketFound) { | |||
return findRocket(view); | |||
} else { | |||
return 'q'; // Stoppe die Bewegung, nachdem die Rakete gefunden wurde | |||
} | |||
} | |||
private char findRocket(View view) { | |||
int positionRocket = view.data.indexOf('o'); | |||
int positionRover = view.data.indexOf('A'); | |||
if (positionRover == positionRocket) { | |||
rocketFound = true; | |||
return 'q'; // Wenn der Rover bereits auf der Rakete steht, stoppe die Bewegung | |||
} | |||
// Überprüfe, ob die Rakete im Sichtfeld ist | |||
if (positionRocket > -1) { | |||
int width = view.width; | |||
int rowRover = positionRover / width; | |||
int colRover = positionRover % width; | |||
int rowRocket = positionRocket / width; | |||
int colRocket = positionRocket % width; | |||
// Wenn die Rakete auf der gleichen Zeile ist | |||
if (rowRover == rowRocket) { | |||
if (colRocket > colRover) { | |||
return '>'; // Bewege dich nach rechts | |||
} else if (colRocket < colRover) { | |||
return '<'; // Bewege dich nach links | |||
} | |||
} | |||
// Wenn die Rakete auf der gleichen Spalte ist | |||
if (colRover == colRocket) { | |||
if (rowRocket > rowRover) { | |||
return 'v'; // Bewege dich nach unten | |||
} else if (rowRocket < rowRover) { | |||
return '^'; // Bewege dich nach oben | |||
} | |||
} | |||
} | |||
// Ansonsten, benutze eine zufällige Bewegung | |||
return moveRandomly(); | |||
} | |||
private char moveRandomly() { | |||
Random random = new Random(); | |||
int randomDirection = random.nextInt(4); | |||
switch (randomDirection) { | |||
case 0: | |||
return '^'; // Vorwärts | |||
case 1: | |||
return 'v'; // Rückwärts | |||
case 2: | |||
return '<'; // Linksdrehung | |||
case 3: | |||
return '>'; // Rechtsdrehung | |||
default: | |||
return 'q'; // Abbruch der Verbindung | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,56 @@ | |||
package praktikum05; | |||
import java.util.Random; | |||
public class RumbleBot extends Bot { | |||
public static void main(String[] args) { | |||
RumbleBot rumbleBot = new RumbleBot(args); | |||
rumbleBot.run(); | |||
} | |||
protected RumbleBot(String[] args) { | |||
super(args); | |||
} | |||
@Override | |||
protected char nextMove(View view) throws Exception { | |||
if (view.data.indexOf('*') > -1) { | |||
return shootIfEnemyInRange(view); | |||
} else { | |||
return moveRandomly(); | |||
} | |||
} | |||
protected char moveRandomly() { | |||
Random random = new Random(); | |||
int randomDirection = random.nextInt(4); | |||
switch (randomDirection) { | |||
case 0: | |||
return '^'; // Vorwärts | |||
case 1: | |||
return 'v'; // Rückwärts | |||
case 2: | |||
return '<'; // Linksdrehung | |||
case 3: | |||
return '>'; // Rechtsdrehung | |||
default: | |||
return 'q'; // Abbruch der Verbindung | |||
} | |||
} | |||
protected char shootIfEnemyInRange(View view) { | |||
int positionEnemy = view.data.indexOf('B'); | |||
int positionRover = view.data.indexOf('A'); | |||
// Überprüfen, ob der Feind in derselben Zeile istdocker run --rm -p 63187:63187 mediaeng/bots escape | |||
if (positionRover / 5 == positionEnemy / 5) { | |||
return 'f'; // Feuerbefehl | |||
} | |||
// Ansonsten zufällig bewegen | |||
return moveRandomly(); | |||
} | |||
} | |||
@@ -0,0 +1,107 @@ | |||
package praktikum05; | |||
import java.util.Random; | |||
public class SnakeBot extends Bot { | |||
private int wagonsCollected = 0; | |||
int countMoves = 1; | |||
// private boolean damaged = false; | |||
public static void main(String[] args) { | |||
SnakeBot snakeBot = new SnakeBot(args); | |||
snakeBot.run(); | |||
} | |||
protected SnakeBot(String[] args) { | |||
super(args); | |||
} | |||
@Override | |||
protected char nextMove(View view) throws Exception { | |||
/*if (damaged) { | |||
return 'q'; // Wenn der Rover beschädigt ist, stoppe die Bewegung | |||
}*/ | |||
if (view.data.charAt(7) == '*') { | |||
outWalkWagon(view); | |||
} else if (view.data.indexOf('@') > -1) { | |||
return goToRock(view); | |||
} else { | |||
return findRock(view); | |||
} | |||
return '^'; | |||
} | |||
protected char findRock(View view) { | |||
Random random = new Random(); | |||
int randomDirection = random.nextInt(2); | |||
if (countMoves <= 10) { | |||
countMoves ++; | |||
return '^'; | |||
} else if (countMoves > 10) { | |||
switch (randomDirection) { | |||
case 1: | |||
countMoves = 0; | |||
return '>'; // Rechtsdrehung | |||
case 2: | |||
countMoves = 0; | |||
return '<'; // Linksdrehung | |||
} | |||
} | |||
return '<'; | |||
} | |||
protected char goToRock(View view) { | |||
int positionRock = view.data.indexOf('@'); | |||
int positionRover = view.data.indexOf('A'); | |||
if (positionRover / 5 != positionRock / 5) { | |||
if (positionRover / 5 > positionRock / 5) { | |||
if (view.data.charAt(7) == '*') { | |||
return outWalkWagon(view); | |||
} else { | |||
return '^'; | |||
} | |||
} else if (positionRover / 5 < positionRock / 5) { | |||
if (view.data.charAt(17) == '*') { | |||
return outWalkWagon(view); | |||
} else { | |||
return 'v'; | |||
} | |||
} | |||
} | |||
if (positionRover % 5 != positionRock % 5) { | |||
if (positionRover % 5 > positionRock % 5) { | |||
return '<'; | |||
} else if (positionRover % 5 < positionRock % 5) { | |||
return '>'; | |||
} | |||
return 0; | |||
} | |||
return 0; | |||
} | |||
protected char outWalkWagon(View view) { | |||
return '<'; | |||
} | |||
/*protected char collectSample(View view) { | |||
int positionSample = view.data.indexOf('*'); | |||
int positionRover = view.data.indexOf('A'); | |||
// Überprüfen, ob die Gesteinsprobe im selben Feld ist | |||
if (positionRover == positionSample) { | |||
wagonsCollected++; | |||
if (wagonsCollected > 1) { | |||
damaged = true; // Der Rover wird beschädigt, wenn er in mehr als einen Wagen fährt | |||
} | |||
return 'C'; // Aufsammeln der Gesteinsprobe und Hinzufügen eines Wagens | |||
} | |||
// Ansonsten zufällig bewegen | |||
return findRock(view); | |||
}*/ | |||
} | |||