2023-12-14 17:15:23 +01:00
|
|
|
public class EscapeBot extends Bot{
|
2024-01-06 18:17:24 +01:00
|
|
|
String moves = "";
|
|
|
|
private boolean goesForward = true;
|
2023-12-14 17:15:23 +01:00
|
|
|
|
2024-01-06 18:17:24 +01:00
|
|
|
public static void main(String[] args) {
|
2023-12-14 17:15:23 +01:00
|
|
|
Bot escapeBot = new EscapeBot(args);
|
|
|
|
escapeBot.run();
|
|
|
|
}
|
|
|
|
protected EscapeBot(String[] args) {
|
|
|
|
super(args);
|
|
|
|
}
|
2024-01-06 18:17:24 +01:00
|
|
|
protected char nextMove(View view){
|
|
|
|
boolean rocketDetected = view.data.contains("o");
|
|
|
|
return rocketDetected ? goToRocket(view) : randomWalk();
|
|
|
|
}
|
|
|
|
private char goToRocket(View view){
|
|
|
|
int rowDifference = findRocketRow(view) - 2;
|
|
|
|
return rowDifference < 0 ? '^' : '<';
|
|
|
|
}
|
|
|
|
private int findRocketRow(View view) {
|
|
|
|
return view.data.indexOf('o') / 5;
|
2023-12-14 17:15:23 +01:00
|
|
|
}
|
|
|
|
private char randomWalk() {
|
2024-01-06 18:17:24 +01:00
|
|
|
if(moves.isEmpty()){
|
|
|
|
moves = "^".repeat(28);
|
|
|
|
moves += (goesForward ? ">^^^^^>" : "<^^^^^<");
|
|
|
|
goesForward = !goesForward;
|
|
|
|
}
|
|
|
|
char nextMove = moves.charAt(0);
|
|
|
|
moves = moves.substring(1);
|
|
|
|
return nextMove;
|
2023-12-14 17:15:23 +01:00
|
|
|
}
|
2024-01-06 18:17:24 +01:00
|
|
|
}
|