RumbleBot unfinished

This commit is contained in:
Your Average Code 2024-01-10 19:00:49 +01:00
parent 94f5f2bceb
commit 6bbe7e029b

60
src/RumbleBot.java Normal file
View File

@ -0,0 +1,60 @@
public class RumbleBot extends Bot {
boolean foundShip = false;
boolean offByOne = true;
int currentStepCount = 0;
int steps = 0;
public static void main(String[] args) {
Bot bot = new RumbleBot(args);
bot.run();
}
protected RumbleBot(String[] args) {
super(args);
}
@Override
protected char nextMove(View view) throws Exception {
String data = view.data;
int width = view.width;
int height = data.length() / view.width;
data = data.replace('^', '*');
data = data.replace('<', '*');
data = data.replace('>', '*');
data = data.replace('V', '*');
System.out.println();
if (data.contains("*")) {
int index = data.indexOf('*');
if (index < view.width * height / 2 && !(index > view.width * height / 2 + 1)) {
return safeMove(data);
} else if (index % 5 < 2) {
return '<';
} else if (index % 5 > 2) {
return '>';
}
return ' ';
} else if (steps == 0) {
currentStepCount += 1;
if (offByOne) {
currentStepCount += 1;
}
offByOne = !offByOne;
steps = currentStepCount;
return '>';
} else {
steps -= 1;
return safeMove(data);
}
}
protected char safeMove(String data) {
if ("~#X".contains("" + data.charAt(35))) {
return '>';
} else {
return '^';
}
}
}