Browse Source

Added drafts for SnakeBot and RumbleBot

testing_N
Illia Soloviov 11 months ago
parent
commit
cdb894c428
3 changed files with 80 additions and 6 deletions
  1. 1
    1
      src/EscapeBot.java
  2. 2
    2
      src/RumbleBot.java
  3. 77
    3
      src/SnakeBot.java

+ 1
- 1
src/EscapeBot.java View File

@@ -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) + ">";

+ 2
- 2
src/RumbleBot.java View File

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

+ 77
- 3
src/SnakeBot.java View File

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

Loading…
Cancel
Save