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">
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />

View File

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