Added stones count in SnakeBot.java

This commit is contained in:
Illia Soloviov 2024-01-06 23:47:07 +01:00
parent 667eb1e2f7
commit 3ace2a44d9

View File

@ -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;