Browse Source

EscapeBot using walkBySpiral. Avg moves 54.

testing_N
Illia Soloviov 11 months ago
parent
commit
1bf3ea159d
1 changed files with 29 additions and 2 deletions
  1. 29
    2
      src/EscapeBot.java

+ 29
- 2
src/EscapeBot.java View File

@@ -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;
}
}

Loading…
Cancel
Save