Initial setup of some basic methods
This commit is contained in:
parent
d041826164
commit
4aa86b4553
@ -6,9 +6,12 @@
|
||||
* Der Rover ist beim ersten Treffer zerstört. Wer überlebt am längsten?
|
||||
* docker run --rm -p 63187:63187 mediaeng/bots rumble
|
||||
*/
|
||||
public class RumbleBot extends Bot{
|
||||
public class RumbleBot extends Bot
|
||||
{
|
||||
private String moves = "";
|
||||
public static void main(String[] args) {
|
||||
private boolean frontIsBlocked, backIsBlocked, leftIsBlocked, rightIsBlocked, trapped;
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Bot rumbleBot = new RumbleBot(args);
|
||||
rumbleBot.run();
|
||||
}
|
||||
@ -18,17 +21,61 @@ public class RumbleBot extends Bot{
|
||||
}
|
||||
|
||||
//@TODO: add nextMove() logic
|
||||
protected char nextMove(View view){
|
||||
protected char nextMove(View view)
|
||||
{
|
||||
checkBarriers(view);
|
||||
return walk();
|
||||
}
|
||||
|
||||
//@TODO: add walk() logic
|
||||
private char walk() {
|
||||
if(moves.isEmpty()){
|
||||
private char walk()
|
||||
{
|
||||
if(moves.isEmpty())
|
||||
{
|
||||
moves += ' ';
|
||||
}
|
||||
char nextMove = moves.charAt(0);
|
||||
moves = moves.substring(1);
|
||||
return nextMove;
|
||||
}
|
||||
|
||||
|
||||
//checks if we are in the line of fire of other players. returns true if that is the case. bot should try it's best to move away
|
||||
private boolean inDanger(View ciew)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//returns the index number in the string at the specified "coordinate"
|
||||
//x is left to right, y is top to bottom
|
||||
private int IndexAt(int width, int x, int y)
|
||||
{
|
||||
return width * y + x;
|
||||
}
|
||||
|
||||
//resets the list of currently planned moves to be empty. intended for when a change in information necessitates an immediate change in plans
|
||||
private void resetMoves()
|
||||
{
|
||||
moves = "";
|
||||
}
|
||||
|
||||
//sets several variables based on the bot's current position that help with navigating
|
||||
private void checkBarriers(View view)
|
||||
{
|
||||
int centerCoordinates = view.width / 2;
|
||||
int centerIndex = IndexAt(view.width, centerCoordinates, centerCoordinates);
|
||||
|
||||
int frontIndex = IndexAt(view.width, centerCoordinates, centerCoordinates - 1);
|
||||
int backIndex = IndexAt(view.width, centerCoordinates, centerCoordinates + 1);
|
||||
int leftIndex = centerIndex - 1;
|
||||
int rightIndex = centerIndex + 1;
|
||||
|
||||
|
||||
//these need to be changed to account for obstacles etc.
|
||||
frontIsBlocked = view.data.charAt(frontIndex) == '*';
|
||||
backIsBlocked = view.data.charAt(backIndex) == '*';
|
||||
leftIsBlocked = view.data.charAt(leftIndex) == '*';
|
||||
rightIsBlocked = view.data.charAt(rightIndex) == '*';
|
||||
trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user