You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EscapeBot.java 1011B

123456789101112131415161718192021222324252627282930313233
  1. public class EscapeBot extends Bot{
  2. String moves = "";
  3. private boolean goesForward = true;
  4. public static void main(String[] args) {
  5. Bot escapeBot = new EscapeBot(args);
  6. escapeBot.run();
  7. }
  8. protected EscapeBot(String[] args) {
  9. super(args);
  10. }
  11. protected char nextMove(View view){
  12. boolean rocketDetected = view.data.contains("o");
  13. return rocketDetected ? goToRocket(view) : randomWalk();
  14. }
  15. private char goToRocket(View view){
  16. int rowDifference = findRocketRow(view) - 2;
  17. return rowDifference < 0 ? '^' : '<';
  18. }
  19. private int findRocketRow(View view) {
  20. return view.data.indexOf('o') / 5;
  21. }
  22. private char randomWalk() {
  23. if(moves.isEmpty()){
  24. moves = "^".repeat(28);
  25. moves += (goesForward ? ">^^^^^>" : "<^^^^^<");
  26. goesForward = !goesForward;
  27. }
  28. char nextMove = moves.charAt(0);
  29. moves = moves.substring(1);
  30. return nextMove;
  31. }
  32. }