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

This commit is contained in:
Niklas Katzer 2024-01-18 15:48:23 +01:00
parent d5abecb35d
commit 2dc2bc8a88

View File

@ -24,12 +24,10 @@ public class RumbleBot extends Bot
protected char nextMove(View view) protected char nextMove(View view)
{ {
checkBarriers(view); checkBarriers(view);
return walk(); if (inDanger(view))
}
//@TODO: add walk() logic
private char walk()
{ {
//run away
}
if(moves.isEmpty()) if(moves.isEmpty())
{ {
moves += ' '; moves += ' ';
@ -66,11 +64,11 @@ public class RumbleBot extends Bot
int rightIndex = centerIndex + 1; int rightIndex = centerIndex + 1;
//these need to be changed to account for obstacles etc.
frontIsBlocked = view.data.charAt(frontIndex) == '*'; frontIsBlocked = view.data.charAt(frontIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
backIsBlocked = view.data.charAt(backIndex) == '*'; backIsBlocked = view.data.charAt(backIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
leftIsBlocked = view.data.charAt(leftIndex) == '*'; leftIsBlocked = view.data.charAt(leftIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
rightIsBlocked = view.data.charAt(rightIndex) == '*'; rightIsBlocked = view.data.charAt(rightIndex) == '~' || view.data.charAt(frontIndex) == '#' || view.data.charAt(frontIndex) == 'X';
trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked; trapped = frontIsBlocked && backIsBlocked && leftIsBlocked && rightIsBlocked;
} }
} }