public class EscapeBot extends Bot { int unitsMoved; int unitsToMove; int timesTurned; protected EscapeBot(String[] args) { super(args); unitsMoved = 0; unitsToMove = 5; timesTurned = 0; } public static void main(String[] args) { Bot bot = new EscapeBot(args); bot.run(); } @Override protected char nextMove(View view) throws Exception { //boolean found = false; if (unitsMoved % 5 == 0) { char c = checkView(view); switch (c) { case '0': break; case '1': throw new Exception("found!"); default: return c; } } if (unitsMoved < unitsToMove) { unitsMoved++; return '^'; } else if (unitsMoved == unitsToMove) { unitsMoved = 0; timesTurned++; if (timesTurned % 2 == 0) { unitsToMove += 5; } return '>'; } throw new Exception(); } private char checkView(View view) { if (view.data.contains("o")) { int spaceship = view.data.indexOf("o") + 1; if (spaceship == 13) { return '1'; } else if (spaceship <= 10) { return '^'; } else if (spaceship >= 15) { return 'v'; } else if (spaceship%5 < 3) { return '<'; } else if (spaceship%5 > 3) { return '>'; } } return '0'; } }