|
|
@@ -1,37 +1,33 @@ |
|
|
|
public class EscapeBot extends Bot{ |
|
|
|
boolean rocketDetected = false; |
|
|
|
public static void main(String[] args) { |
|
|
|
String moves = ""; |
|
|
|
private boolean goesForward = true; |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
Bot escapeBot = new EscapeBot(args); |
|
|
|
escapeBot.run(); |
|
|
|
} |
|
|
|
protected EscapeBot(String[] args) { |
|
|
|
super(args); |
|
|
|
} |
|
|
|
|
|
|
|
protected char nextMove(View view) throws Exception { |
|
|
|
char[] viewField = view.data.toCharArray(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < viewField.length; i++) { |
|
|
|
if(viewField[i] == 'o'){ |
|
|
|
rocketDetected = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(rocketDetected){ |
|
|
|
|
|
|
|
}else{ |
|
|
|
return randomWalk(); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
private char randomWalk() { |
|
|
|
return '^'; |
|
|
|
if(moves.isEmpty()){ |
|
|
|
moves = "^".repeat(28); |
|
|
|
moves += (goesForward ? ">^^^^^>" : "<^^^^^<"); |
|
|
|
goesForward = !goesForward; |
|
|
|
} |
|
|
|
char nextMove = moves.charAt(0); |
|
|
|
moves = moves.substring(1); |
|
|
|
return nextMove; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |