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 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * RumbleBot.
  3. * Der Rover ist auch mit einem Geschütz ausgestattet, dass nur in Fahrrichtung feuern kann.
  4. * Der Feuerbefehl ist „f“. Die Reichweite des Geschützes entspricht der Scanreichweite.
  5. * Wälder, Felsen und Wasser blockieren Schüsse.
  6. * Der Rover ist beim ersten Treffer zerstört. Wer überlebt am längsten?
  7. * docker run --rm -p 63187:63187 mediaeng/bots rumble
  8. */
  9. public class RumbleBot extends Bot
  10. {
  11. private String moves = "";
  12. private boolean frontIsBlocked, backIsBlocked, leftIsBlocked, rightIsBlocked, trapped;
  13. public static void main(String[] args)
  14. {
  15. Bot rumbleBot = new RumbleBot(args);
  16. rumbleBot.run();
  17. }
  18. protected RumbleBot(String[] args) {
  19. super(args);
  20. }
  21. //@TODO: add nextMove() logic
  22. protected char nextMove(View view)
  23. {
  24. checkBarriers(view);
  25. return walk();
  26. }
  27. //@TODO: add walk() logic
  28. private char walk()
  29. {
  30. if(moves.isEmpty())
  31. {
  32. moves += ' ';
  33. }
  34. char nextMove = moves.charAt(0);
  35. moves = moves.substring(1);
  36. return nextMove;
  37. }
  38. //checks if we are in the line of fire of other players. returns true if that is the case. bot should try it's best to move away
  39. private boolean inDanger(View ciew)
  40. {
  41. return false;
  42. }
  43. //returns the index number in the string at the specified "coordinate"
  44. //x is left to right, y is top to bottom
  45. private int IndexAt(int width, int x, int y)
  46. {
  47. return width * y + x;
  48. }
  49. //resets the list of currently planned moves to be empty. intended for when a change in information necessitates an immediate change in plans
  50. private void resetMoves()
  51. {
  52. moves = "";
  53. }
  54. //sets several variables based on the bot's current position that help with navigating
  55. private void checkBarriers(View view)
  56. {
  57. int centerCoordinates = view.width / 2;
  58. int centerIndex = IndexAt(view.width, centerCoordinates, centerCoordinates);
  59. int frontIndex = IndexAt(view.width, centerCoordinates, centerCoordinates - 1);
  60. int backIndex = IndexAt(view.width, centerCoordinates, centerCoordinates + 1);
  61. int leftIndex = centerIndex - 1;
  62. int rightIndex = centerIndex + 1;
  63. //these need to be changed to account for obstacles etc.
  64. frontIsBlocked = view.data.charAt(frontIndex) == '*';
  65. backIsBlocked = view.data.charAt(backIndex) == '*';
  66. leftIsBlocked = view.data.charAt(leftIndex) == '*';
  67. rightIsBlocked = view.data.charAt(rightIndex) == '*';
  68. trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked;
  69. }
  70. }