Browse Source

Added stones count in SnakeBot.java

testing_N
Illia Soloviov 4 months ago
parent
commit
3ace2a44d9
1 changed files with 21 additions and 2 deletions
  1. 21
    2
      src/SnakeBot.java

+ 21
- 2
src/SnakeBot.java 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;


Loading…
Cancel
Save