Browse Source

minor adjustments to checkBarriers(), now properly checks for obstacles

testing_N
Niklas Katzer 11 months ago
parent
commit
2dc2bc8a88
1 changed files with 9 additions and 11 deletions
  1. 9
    11
      src/RumbleBot.java

+ 9
- 11
src/RumbleBot.java View File

protected char nextMove(View view) protected char nextMove(View view)
{ {
checkBarriers(view); checkBarriers(view);
return walk();
}

//@TODO: add walk() logic
private char walk()
{
if (inDanger(view))
{
//run away
}
if(moves.isEmpty()) if(moves.isEmpty())
{ {
moves += ' '; moves += ' ';
int rightIndex = 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) == '*';
frontIsBlocked = view.data.charAt(frontIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
backIsBlocked = view.data.charAt(backIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
leftIsBlocked = view.data.charAt(leftIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
rightIsBlocked = view.data.charAt(rightIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked; trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked;
} }
} }

Loading…
Cancel
Save