/* * 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); if (inDanger(view)) { //run away } 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; } //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; 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'; 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'; 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'; 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'; trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked; } }