Browse Source

Initial setup of some basic methods

testing_N
Niklas Katzer 11 months ago
parent
commit
4aa86b4553
1 changed files with 52 additions and 5 deletions
  1. 52
    5
      src/RumbleBot.java

+ 52
- 5
src/RumbleBot.java View File

* Der Rover ist beim ersten Treffer zerstört. Wer überlebt am längsten? * Der Rover ist beim ersten Treffer zerstört. Wer überlebt am längsten?
* docker run --rm -p 63187:63187 mediaeng/bots rumble * docker run --rm -p 63187:63187 mediaeng/bots rumble
*/ */
public class RumbleBot extends Bot{
public class RumbleBot extends Bot
{
private String moves = ""; 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); Bot rumbleBot = new RumbleBot(args);
rumbleBot.run(); rumbleBot.run();
} }
} }


//@TODO: add nextMove() logic //@TODO: add nextMove() logic
protected char nextMove(View view){
protected char nextMove(View view)
{
checkBarriers(view);
return walk(); return walk();
} }


//@TODO: add walk() logic //@TODO: add walk() logic
private char walk() {
if(moves.isEmpty()){
private char walk()
{
if(moves.isEmpty())
{
moves += ' '; moves += ' ';
} }
char nextMove = moves.charAt(0); char nextMove = moves.charAt(0);
moves = moves.substring(1); moves = moves.substring(1);
return nextMove; 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…
Cancel
Save