protected EscapeBot(String[] args) { | protected EscapeBot(String[] args) { | ||||
super(args); | super(args); | ||||
} | } | ||||
protected char nextMove(View view){ | |||||
protected char nextMove(View view) { | |||||
boolean rocketDetected = view.data.contains("o"); | boolean rocketDetected = view.data.contains("o"); | ||||
return rocketDetected ? goToRocket(view) : walkBySpiral(view); | return rocketDetected ? goToRocket(view) : walkBySpiral(view); | ||||
} | } | ||||
private char goToRocket(View view){ | |||||
private char goToRocket(View view) { | |||||
int rowDifference = findRocketRow(view) - 2; | int rowDifference = findRocketRow(view) - 2; | ||||
return rowDifference < 0 ? '^' : '<'; | return rowDifference < 0 ? '^' : '<'; | ||||
} | } | ||||
return view.data.indexOf('o') / view.width; | return view.data.indexOf('o') / view.width; | ||||
} | } | ||||
private char walkBySpiral(View view){ | |||||
private char walkBySpiral(View view) { | |||||
if (moves.isEmpty()) { | if (moves.isEmpty()) { | ||||
spiralNumber++; | spiralNumber++; | ||||
moves += "^".repeat(view.width * spiralNumber) + ">" + "^".repeat(view.width * spiralNumber) + ">"; | moves += "^".repeat(view.width * spiralNumber) + ">" + "^".repeat(view.width * spiralNumber) + ">"; |
return walk(); //@TODO: add nextMove() logic | return walk(); //@TODO: add nextMove() logic | ||||
} | } | ||||
private char walk(){ | |||||
private char walk() { | |||||
if(moves.isEmpty()){ | if(moves.isEmpty()){ | ||||
moves += ' '; //@TODO: add walk() logic | moves += ' '; //@TODO: add walk() logic | ||||
} | } |
super(args); | super(args); | ||||
} | } | ||||
//@TODO: find a better way to avoid collectedStones | //@TODO: find a better way to avoid collectedStones | ||||
protected char nextMove(View view){ | |||||
protected char nextMove(View view) { | |||||
boolean stoneDetected = view.data.contains("@"); | boolean stoneDetected = view.data.contains("@"); | ||||
char nextMove; | char nextMove; | ||||
nextMove = (stoneDetected && !ignoreStone) ? goToStone(view) : walkBySpiral(view); | nextMove = (stoneDetected && !ignoreStone) ? goToStone(view) : walkBySpiral(view); | ||||
return count; | return count; | ||||
} | } | ||||
private char goToStone(View view){ | |||||
private char goToStone(View view) { | |||||
int rowDifference = findStoneRow(view) - (view.width / 2); | int rowDifference = findStoneRow(view) - (view.width / 2); | ||||
return rowDifference < 0 ? '^' : '<'; | return rowDifference < 0 ? '^' : '<'; | ||||
} | } | ||||
return view.data.indexOf('@') / view.width; | return view.data.indexOf('@') / view.width; | ||||
} | } | ||||
private char walkBySpiral(View view){ | |||||
private char walkBySpiral(View view) { | |||||
if (moves.isEmpty()) { | if (moves.isEmpty()) { | ||||
spiralNumber++; | spiralNumber++; | ||||
moves += "^".repeat(view.width * spiralNumber) + ">" + "^".repeat(view.width * spiralNumber) + ">"; | moves += "^".repeat(view.width * spiralNumber) + ">" + "^".repeat(view.width * spiralNumber) + ">"; |