|
|
@@ -1,6 +1,8 @@ |
|
|
|
public class EscapeBot extends Bot{ |
|
|
|
String moves = ""; |
|
|
|
private boolean goesForward = true; |
|
|
|
private int circleNumber = 0; |
|
|
|
private int spiralNumber = 0; |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
Bot escapeBot = new EscapeBot(args); |
|
|
@@ -11,7 +13,7 @@ public class EscapeBot extends Bot{ |
|
|
|
} |
|
|
|
protected char nextMove(View view){ |
|
|
|
boolean rocketDetected = view.data.contains("o"); |
|
|
|
return rocketDetected ? goToRocket(view) : randomWalk(); |
|
|
|
return rocketDetected ? goToRocket(view) : walkBySpiral(); |
|
|
|
} |
|
|
|
private char goToRocket(View view){ |
|
|
|
int rowDifference = findRocketRow(view) - 2; |
|
|
@@ -20,7 +22,7 @@ public class EscapeBot extends Bot{ |
|
|
|
private int findRocketRow(View view) { |
|
|
|
return view.data.indexOf('o') / 5; |
|
|
|
} |
|
|
|
private char randomWalk() { |
|
|
|
private char walkByColumns() { |
|
|
|
if(moves.isEmpty()){ |
|
|
|
moves = "^".repeat(28); |
|
|
|
moves += (goesForward ? ">^^^^^>" : "<^^^^^<"); |
|
|
@@ -30,4 +32,29 @@ public class EscapeBot extends Bot{ |
|
|
|
moves = moves.substring(1); |
|
|
|
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; |
|
|
|
} |
|
|
|
} |