EscapeBot beta version. Max 200 moves. Avg 100 moves.

This commit is contained in:
Illia Soloviov 2024-01-06 18:17:24 +01:00
parent 498bcb89c1
commit 261d4f4d16
3 changed files with 22 additions and 31 deletions

1
.idea/misc.xml generated
View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />

View File

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

View File

@ -1,7 +1,6 @@
import java.util.Scanner; import java.util.Scanner;
public class ManualBot extends Bot{ public class ManualBot extends Bot{
public static void main(String[] args) { public static void main(String[] args) {
Bot manualBot = new ManualBot(args); Bot manualBot = new ManualBot(args);
manualBot.run(); manualBot.run();
} }
@ -14,7 +13,6 @@ public class ManualBot extends Bot{
switch(scanner.nextLine().toLowerCase()){ switch(scanner.nextLine().toLowerCase()){
case "w": case "w":
return '^' ; return '^' ;
case "s": case "s":
return 'v' ; return 'v' ;
case "a": case "a":
@ -27,7 +25,5 @@ public class ManualBot extends Bot{
break; break;
} }
return 0; return 0;
} }
} }