diff --git a/src/RumbleBot.java b/src/RumbleBot.java index 2379a5e..1944f3c 100644 --- a/src/RumbleBot.java +++ b/src/RumbleBot.java @@ -6,9 +6,12 @@ * 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{ +public class RumbleBot extends Bot +{ private String moves = ""; - public static void main(String[] args) { + private boolean frontIsBlocked, backIsBlocked, leftIsBlocked, rightIsBlocked, trapped; + public static void main(String[] args) + { Bot rumbleBot = new RumbleBot(args); rumbleBot.run(); } @@ -18,17 +21,61 @@ public class RumbleBot extends Bot{ } //@TODO: add nextMove() logic - protected char nextMove(View view){ + protected char nextMove(View view) + { + checkBarriers(view); return walk(); } //@TODO: add walk() logic - private char walk() { - if(moves.isEmpty()){ + 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; + } }