Removed "magic numbers" by adding generateLeftSideArray and generateRightSideArray to SnakeBot.java. Added calculateCharIndexFromCoordinates function.
This commit is contained in:
parent
7bfbd6812e
commit
477e16cede
@ -27,12 +27,12 @@ public class EscapeBot extends Bot{
|
||||
protected EscapeBot(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
protected char nextMove(View view){
|
||||
protected char nextMove(View view) {
|
||||
boolean rocketDetected = view.data.contains("o");
|
||||
return rocketDetected ? goToRocket(view) : walkBySpiral(view);
|
||||
}
|
||||
|
||||
private char goToRocket(View view){
|
||||
private char goToRocket(View view) {
|
||||
int rowDifference = findRocketRow(view) - 2;
|
||||
return rowDifference < 0 ? '^' : '<';
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class EscapeBot extends Bot{
|
||||
return view.data.indexOf('o') / view.width;
|
||||
}
|
||||
|
||||
private char walkBySpiral(View view){
|
||||
private char walkBySpiral(View view) {
|
||||
if (moves.isEmpty()) {
|
||||
spiralNumber++;
|
||||
moves += "^".repeat(view.width * spiralNumber) + ">" + "^".repeat(view.width * spiralNumber) + ">";
|
||||
|
@ -21,7 +21,7 @@ public class RumbleBot extends Bot{
|
||||
return walk(); //@TODO: add nextMove() logic
|
||||
}
|
||||
|
||||
private char walk(){
|
||||
private char walk() {
|
||||
if(moves.isEmpty()){
|
||||
moves += ' '; //@TODO: add walk() logic
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class SnakeBot extends Bot{
|
||||
super(args);
|
||||
}
|
||||
//@TODO: find a better way to avoid collectedStones
|
||||
protected char nextMove(View view){
|
||||
protected char nextMove(View view) {
|
||||
boolean stoneDetected = view.data.contains("@");
|
||||
char nextMove;
|
||||
nextMove = (stoneDetected && !ignoreStone) ? goToStone(view) : walkBySpiral(view);
|
||||
@ -68,7 +68,7 @@ public class SnakeBot extends Bot{
|
||||
return count;
|
||||
}
|
||||
|
||||
private char goToStone(View view){
|
||||
private char goToStone(View view) {
|
||||
int rowDifference = findStoneRow(view) - (view.width / 2);
|
||||
return rowDifference < 0 ? '^' : '<';
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class SnakeBot extends Bot{
|
||||
return view.data.indexOf('@') / view.width;
|
||||
}
|
||||
|
||||
private char walkBySpiral(View view){
|
||||
private char walkBySpiral(View view) {
|
||||
if (moves.isEmpty()) {
|
||||
spiralNumber++;
|
||||
moves += "^".repeat(view.width * spiralNumber) + ">" + "^".repeat(view.width * spiralNumber) + ">";
|
||||
|
Loading…
x
Reference in New Issue
Block a user