Added drafts for SnakeBot and RumbleBot
This commit is contained in:
parent
f7ae380baa
commit
cdb894c428
@ -32,7 +32,7 @@ public class EscapeBot extends Bot{
|
|||||||
moves = moves.substring(1);
|
moves = moves.substring(1);
|
||||||
return nextMove;
|
return nextMove;
|
||||||
}
|
}
|
||||||
private char WalkByCircles(){
|
private char walkByCircles(){
|
||||||
if (moves.isEmpty()) {
|
if (moves.isEmpty()) {
|
||||||
circleNumber++;
|
circleNumber++;
|
||||||
moves += "^".repeat(5) + ">";
|
moves += "^".repeat(5) + ">";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
public class RumbleBot extends Bot{
|
public class RumbleBot extends Bot{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Bot escapeBot = new EscapeBot(args);
|
Bot rumbleBot = new RumbleBot(args);
|
||||||
escapeBot.run();
|
rumbleBot.run();
|
||||||
}
|
}
|
||||||
protected RumbleBot(String[] args) {
|
protected RumbleBot(String[] args) {
|
||||||
super(args);
|
super(args);
|
||||||
|
@ -1,12 +1,86 @@
|
|||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class SnakeBot extends Bot{
|
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) {
|
public static void main(String[] args) {
|
||||||
Bot escapeBot = new EscapeBot(args);
|
Bot snakeBot = new SnakeBot(args);
|
||||||
escapeBot.run();
|
snakeBot.run();
|
||||||
}
|
}
|
||||||
protected SnakeBot(String[] args) {
|
protected SnakeBot(String[] args) {
|
||||||
super(args);
|
super(args);
|
||||||
}
|
}
|
||||||
|
//@TODO
|
||||||
protected char nextMove(View view){
|
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…
x
Reference in New Issue
Block a user