123456789101112131415161718192021222324252627282930313233 |
- public class EscapeBot extends Bot{
- 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){
- 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() {
- if(moves.isEmpty()){
- moves = "^".repeat(28);
- moves += (goesForward ? ">^^^^^>" : "<^^^^^<");
- goesForward = !goesForward;
- }
- char nextMove = moves.charAt(0);
- moves = moves.substring(1);
- return nextMove;
- }
- }
|