Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void updateDistances() {
- clearDistances();
- Queue<Cell> q = new LinkedList<>();
- gameBoard[human.getRow()][human.getCol()].setDistance(0);
- q.add(gameBoard[human.getRow()][human.getCol()]);
- while(!q.isEmpty()) {
- Cell curr = q.peek();
- q.remove();
- for(int i = -1; i <= 1; i++) {
- for(int j = -1; j <= 1; j++) {
- if(isValidCell(curr, i, j)) {
- gameBoard[curr.getX() + i][curr.getY() + j].setDistance(curr.getDistance() + 1);
- q.add(gameBoard[curr.getX() + i][curr.getY() + j]);
- }
- }
- }
- }
- }
- private void clearDistances() {
- for(int i = 0; i < BOARD_SIZE; i++)
- for(int j = 0; j < BOARD_SIZE; j++)
- gameBoard[i][j].clearDistance();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement