|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /*
- * RumbleBot.
- * Der Rover ist auch mit einem Geschütz ausgestattet, dass nur in Fahrrichtung feuern kann.
- * Der Feuerbefehl ist „f“. Die Reichweite des Geschützes entspricht der Scanreichweite.
- * Wälder, Felsen und Wasser blockieren Schüsse.
- * Der Rover ist beim ersten Treffer zerstört. Wer überlebt am längsten?
- * docker run --rm -p 63187:63187 mediaeng/bots rumble
- */
- public class RumbleBot extends Bot
- {
- private String moves = "";
- private boolean frontIsBlocked, backIsBlocked, leftIsBlocked, rightIsBlocked, trapped;
- public static void main(String[] args)
- {
- Bot rumbleBot = new RumbleBot(args);
- rumbleBot.run();
- }
-
- protected RumbleBot(String[] args) {
- super(args);
- }
-
- //@TODO: add nextMove() logic
- protected char nextMove(View view)
- {
- checkBarriers(view);
- return walk();
- }
-
- //@TODO: add walk() logic
- private char walk()
- {
- if(moves.isEmpty())
- {
- moves += ' ';
- }
- char nextMove = moves.charAt(0);
- moves = moves.substring(1);
- return nextMove;
- }
-
-
- //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
- private boolean inDanger(View ciew)
- {
- return false;
- }
-
- //returns the index number in the string at the specified "coordinate"
- //x is left to right, y is top to bottom
- private int IndexAt(int width, int x, int y)
- {
- return width * y + x;
- }
-
- //resets the list of currently planned moves to be empty. intended for when a change in information necessitates an immediate change in plans
- private void resetMoves()
- {
- moves = "";
- }
-
- //sets several variables based on the bot's current position that help with navigating
- private void checkBarriers(View view)
- {
- int centerCoordinates = view.width / 2;
- int centerIndex = IndexAt(view.width, centerCoordinates, centerCoordinates);
-
- int frontIndex = IndexAt(view.width, centerCoordinates, centerCoordinates - 1);
- int backIndex = IndexAt(view.width, centerCoordinates, centerCoordinates + 1);
- int leftIndex = centerIndex - 1;
- int rightIndex = centerIndex + 1;
-
-
- //these need to be changed to account for obstacles etc.
- frontIsBlocked = view.data.charAt(frontIndex) == '*';
- backIsBlocked = view.data.charAt(backIndex) == '*';
- leftIsBlocked = view.data.charAt(leftIndex) == '*';
- rightIsBlocked = view.data.charAt(rightIndex) == '*';
- trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked;
- }
- }
|