|
|
|
|
|
|
|
|
public class EscapeBot extends Bot{ |
|
|
public class EscapeBot extends Bot{ |
|
|
String moves = ""; |
|
|
String moves = ""; |
|
|
private boolean goesForward = true; |
|
|
private boolean goesForward = true; |
|
|
|
|
|
private int circleNumber = 0; |
|
|
|
|
|
private int spiralNumber = 0; |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
Bot escapeBot = new EscapeBot(args); |
|
|
Bot escapeBot = new EscapeBot(args); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
protected char nextMove(View view){ |
|
|
protected char nextMove(View view){ |
|
|
boolean rocketDetected = view.data.contains("o"); |
|
|
boolean rocketDetected = view.data.contains("o"); |
|
|
return rocketDetected ? goToRocket(view) : randomWalk(); |
|
|
|
|
|
|
|
|
return rocketDetected ? goToRocket(view) : walkBySpiral(); |
|
|
} |
|
|
} |
|
|
private char goToRocket(View view){ |
|
|
private char goToRocket(View view){ |
|
|
int rowDifference = findRocketRow(view) - 2; |
|
|
int rowDifference = findRocketRow(view) - 2; |
|
|
|
|
|
|
|
|
private int findRocketRow(View view) { |
|
|
private int findRocketRow(View view) { |
|
|
return view.data.indexOf('o') / 5; |
|
|
return view.data.indexOf('o') / 5; |
|
|
} |
|
|
} |
|
|
private char randomWalk() { |
|
|
|
|
|
|
|
|
private char walkByColumns() { |
|
|
if(moves.isEmpty()){ |
|
|
if(moves.isEmpty()){ |
|
|
moves = "^".repeat(28); |
|
|
moves = "^".repeat(28); |
|
|
moves += (goesForward ? ">^^^^^>" : "<^^^^^<"); |
|
|
moves += (goesForward ? ">^^^^^>" : "<^^^^^<"); |
|
|
|
|
|
|
|
|
moves = moves.substring(1); |
|
|
moves = moves.substring(1); |
|
|
return nextMove; |
|
|
return nextMove; |
|
|
} |
|
|
} |
|
|
|
|
|
private char WalkByCircles(){ |
|
|
|
|
|
if (moves.isEmpty()) { |
|
|
|
|
|
circleNumber++; |
|
|
|
|
|
moves += "^".repeat(5) + ">"; |
|
|
|
|
|
int[] steps = {5, 10, 10, 10}; |
|
|
|
|
|
|
|
|
|
|
|
for (int step : steps) { |
|
|
|
|
|
moves += "^".repeat(step * circleNumber) + ">"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
moves += "^".repeat(5 * circleNumber) + "<"; |
|
|
|
|
|
} |
|
|
|
|
|
char nextMove = moves.charAt(0); |
|
|
|
|
|
moves = moves.substring(1); |
|
|
|
|
|
return nextMove; |
|
|
|
|
|
} |
|
|
|
|
|
private char walkBySpiral(){ |
|
|
|
|
|
if (moves.isEmpty()) { |
|
|
|
|
|
spiralNumber++; |
|
|
|
|
|
moves += "^".repeat(5 * spiralNumber) + ">" + "^".repeat(5 * spiralNumber) + ">"; |
|
|
|
|
|
} |
|
|
|
|
|
char nextMove = moves.charAt(0); |
|
|
|
|
|
moves = moves.substring(1); |
|
|
|
|
|
return nextMove; |
|
|
|
|
|
} |
|
|
} |
|
|
} |