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.

RumbleBot.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. public class RumbleBot extends Bot {
  2. boolean foundShip = false;
  3. boolean offByOne = true;
  4. int currentStepCount = 0;
  5. int steps = 0;
  6. public static void main(String[] args) {
  7. Bot bot = new RumbleBot(args);
  8. bot.run();
  9. }
  10. protected RumbleBot(String[] args) {
  11. super(args);
  12. }
  13. @Override
  14. protected char nextMove(View view) throws Exception {
  15. String data = view.data;
  16. int width = view.width;
  17. int height = data.length() / view.width;
  18. data = data.replace('^', '*');
  19. data = data.replace('<', '*');
  20. data = data.replace('>', '*');
  21. data = data.replace('V', '*');
  22. System.out.println();
  23. if (data.contains("*")) {
  24. int index = data.indexOf('*');
  25. if (index < width * height / 2 && index % width == 4) {
  26. return 'f';
  27. } else if (index < width * height / 2 && !(index > width * height / 2 + 1)) {
  28. return safeMove(data);
  29. } else if (index % 5 < 2) {
  30. return '<';
  31. } else if (index % 5 > 2) {
  32. return '>';
  33. }
  34. return ' ';
  35. } else if (steps == 0) {
  36. currentStepCount += 1;
  37. if (offByOne) {
  38. currentStepCount += 1;
  39. }
  40. offByOne = !offByOne;
  41. steps = currentStepCount;
  42. return '>';
  43. } else {
  44. steps -= 1;
  45. return safeMove(data);
  46. }
  47. }
  48. protected char safeMove(String data) {
  49. if ("~#X".contains("" + data.charAt(35))) {
  50. currentStepCount = 2;
  51. return '>';
  52. } else {
  53. return '^';
  54. }
  55. }
  56. }