diff --git a/src/SnakeBot.java b/src/SnakeBot.java index 5da9612..9e2485a 100644 --- a/src/SnakeBot.java +++ b/src/SnakeBot.java @@ -20,13 +20,32 @@ public class SnakeBot extends Bot{ nextMove = stoneDetected && !ignoreStone ? goToStone(view) : walkBySpiral(); if(nextMove == '^' && view.data.charAt(7) == '*'){ - Random random = new Random(); - nextMove = (random.nextInt(2) % 2 == 0) ? '<' : '>'; + nextMove = (countCollectedStonesLeft(view) <= countCollectedStonesRight(view)) ? '<' : '>'; ignoreStone = true; } if(countCollectedStones(view) <= 2) ignoreStone = false; return nextMove; } + private int countCollectedStonesLeft(View view) { + int[] leftStones = {0, 1, 5, 6, 10, 11, 15, 16, 20, 21}; + int stones = 0; + for (int stone: leftStones) { + if(view.data.charAt(stone) == '*'){ + stones++; + } + } + return stones; + } + private int countCollectedStonesRight(View view) { + int[] rightStones = {3, 4, 8, 9, 13, 14, 18, 19, 23, 24}; + int stones = 0; + for (int stone: rightStones) { + if(view.data.charAt(stone) == '*'){ + stones++; + } + } + return stones; + } private int countCollectedStones(View view) { int count = 0;