diff --git a/src/EscapeBot.java b/src/EscapeBot.java index 87afc3a..5d69f1c 100644 --- a/src/EscapeBot.java +++ b/src/EscapeBot.java @@ -32,7 +32,7 @@ public class EscapeBot extends Bot{ moves = moves.substring(1); return nextMove; } - private char WalkByCircles(){ + private char walkByCircles(){ if (moves.isEmpty()) { circleNumber++; moves += "^".repeat(5) + ">"; diff --git a/src/RumbleBot.java b/src/RumbleBot.java index 325298b..dfdeb0c 100644 --- a/src/RumbleBot.java +++ b/src/RumbleBot.java @@ -1,7 +1,7 @@ public class RumbleBot extends Bot{ public static void main(String[] args) { - Bot escapeBot = new EscapeBot(args); - escapeBot.run(); + Bot rumbleBot = new RumbleBot(args); + rumbleBot.run(); } protected RumbleBot(String[] args) { super(args); diff --git a/src/SnakeBot.java b/src/SnakeBot.java index b6858e5..cd952b6 100644 --- a/src/SnakeBot.java +++ b/src/SnakeBot.java @@ -1,12 +1,86 @@ +import java.util.Random; + public class SnakeBot extends Bot{ + String moves = ""; + private boolean goesForward = true; + private int circleNumber = 0; + private int spiralNumber = 0; + private boolean ignoreStone = false; public static void main(String[] args) { - Bot escapeBot = new EscapeBot(args); - escapeBot.run(); + Bot snakeBot = new SnakeBot(args); + snakeBot.run(); } protected SnakeBot(String[] args) { super(args); } + //@TODO protected char nextMove(View view){ - return 0; + boolean stoneDetected = view.data.contains("@"); + char nextMove; + nextMove = stoneDetected && !ignoreStone ? goToStone(view) : walkBySpiral(); + + if(nextMove == '^' && view.data.charAt(7) == '*'){ + Random random = new Random(); + nextMove = (random.nextInt(2) % 2 == 0) ? '<' : '>'; + ignoreStone = true; + } + if(countCollectedStones(view) <= 2) ignoreStone = false; + return nextMove; + } + private int countCollectedStones(View view) { + int count = 0; + + for (char c : view.data.toCharArray()) { + if (c == '*') { + count++; + } + } + + return count; + } + private char goToStone(View view){ + int rowDifference = findStoneRow(view) - 2; + return rowDifference < 0 ? '^' : '<'; + } + + private int findStoneRow(View view) { + return view.data.indexOf('@') / 5; + } + private char walkByColumns() { + if(moves.isEmpty()){ + moves = "^".repeat(28); + moves += (goesForward ? ">^^^^^>" : "<^^^^^<"); + goesForward = !goesForward; + } + char nextMove = moves.charAt(0); + moves = moves.substring(1); + return nextMove; + } + private char walkByCircles(){ + if (moves.isEmpty()) { + circleNumber++; + moves += "^".repeat(5) + ">"; + int[] steps = {5, 10, 10, 10}; + + for (int step : steps) { + moves += "^".repeat(step * circleNumber) + ">"; + } + + moves += "^".repeat(5 * circleNumber) + "<"; + } + char nextMove = moves.charAt(0); + moves = moves.substring(1); + return nextMove; + } + private char walkBySpiral(){ + if (moves.isEmpty()) { + spiralNumber++; + moves += "^".repeat(5 * spiralNumber) + ">" + "^".repeat(5 * spiralNumber) + ">"; + } + char nextMove = moves.charAt(0); + moves = moves.substring(1); + + + return nextMove; } }