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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if (inDanger(view))
  26. {
  27. //run away
  28. }
  29. if(moves.isEmpty())
  30. {
  31. moves += ' ';
  32. }
  33. char nextMove = moves.charAt(0);
  34. moves = moves.substring(1);
  35. return nextMove;
  36. }
  37. //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
  38. private boolean inDanger(View ciew)
  39. {
  40. return false;
  41. }
  42. //returns the index number in the string at the specified "coordinate"
  43. //x is left to right, y is top to bottom
  44. private int IndexAt(int width, int x, int y)
  45. {
  46. return width * y + x;
  47. }
  48. //sets several variables based on the bot's current position that help with navigating
  49. private void checkBarriers(View view)
  50. {
  51. int centerCoordinates = view.width / 2;
  52. int centerIndex = IndexAt(view.width, centerCoordinates, centerCoordinates);
  53. int frontIndex = IndexAt(view.width, centerCoordinates, centerCoordinates - 1);
  54. int backIndex = IndexAt(view.width, centerCoordinates, centerCoordinates + 1);
  55. int leftIndex = centerIndex - 1;
  56. int rightIndex = centerIndex + 1;
  57. frontIsBlocked = view.data.charAt(frontIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X' || view.data.charAt(frontIndex) == '^' || view.data.charAt(frontIndex) == '<' || view.data.charAt(frontIndex) == '>' || view.data.charAt(frontIndex) == 'v';
  58. backIsBlocked = view.data.charAt(backIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X' || view.data.charAt(frontIndex) == '^' || view.data.charAt(frontIndex) == '<' || view.data.charAt(frontIndex) == '>' || view.data.charAt(frontIndex) == 'v';
  59. leftIsBlocked = view.data.charAt(leftIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X' || view.data.charAt(frontIndex) == '^' || view.data.charAt(frontIndex) == '<' || view.data.charAt(frontIndex) == '>' || view.data.charAt(frontIndex) == 'v';
  60. rightIsBlocked = view.data.charAt(rightIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X' || view.data.charAt(frontIndex) == '^' || view.data.charAt(frontIndex) == '<' || view.data.charAt(frontIndex) == '>' || view.data.charAt(frontIndex) == 'v';
  61. trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked;
  62. }
  63. }