EscapeBot using walkBySpiral. Avg moves 54.
This commit is contained in:
parent
261d4f4d16
commit
1bf3ea159d
@ -1,6 +1,8 @@
|
|||||||
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);
|
||||||
@ -11,7 +13,7 @@ public class EscapeBot extends Bot{
|
|||||||
}
|
}
|
||||||
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;
|
||||||
@ -20,7 +22,7 @@ public class EscapeBot extends Bot{
|
|||||||
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 ? ">^^^^^>" : "<^^^^^<");
|
||||||
@ -30,4 +32,29 @@ public class EscapeBot extends Bot{
|
|||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user