Advertisement
madopew

Untitled

May 11th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. private void updateDistances() {
  2.         clearDistances();
  3.         Queue<Cell> q = new LinkedList<>();
  4.         gameBoard[human.getRow()][human.getCol()].setDistance(0);
  5.         q.add(gameBoard[human.getRow()][human.getCol()]);
  6.         while(!q.isEmpty()) {
  7.             Cell curr = q.peek();
  8.             q.remove();
  9.             for(int i = -1; i <= 1; i++) {
  10.                 for(int j = -1; j <= 1; j++) {
  11.                     if(isValidCell(curr, i, j)) {
  12.                         gameBoard[curr.getX() + i][curr.getY() + j].setDistance(curr.getDistance() + 1);
  13.                         q.add(gameBoard[curr.getX() + i][curr.getY() + j]);
  14.                     }
  15.                 }
  16.             }
  17.         }
  18.     }
  19.     private void clearDistances() {
  20.         for(int i = 0; i < BOARD_SIZE; i++)
  21.             for(int j = 0; j < BOARD_SIZE; j++)
  22.                 gameBoard[i][j].clearDistance();
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement