Guest User

Untitled

a guest
Jan 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public void searchCluster(Grid grid){
  2. Node[][] array = grid.getNodeArray();
  3. ArrayList<Node> tmpBurnt = new ArrayList();
  4. LinkedList<Node> tmpSave = new LinkedList();
  5. Node left;
  6. Node right;
  7. Node below;
  8.  
  9. for(Node n : array[0]){
  10. if(n.isSet()){
  11. tmpBurnt.add(n);
  12. }
  13. }
  14.  
  15. for(;;){
  16. if(tmpBurnt.isEmpty()){
  17. return;
  18. }
  19. for(Node n : tmpBurnt){
  20. //-----check left--------
  21. if(n.getX() > 0){
  22. left = array[n.getY()][n.getX() - 1];
  23. if(left.isSet() && !tmpBurnt.contains(left) && !this.burnt.contains(left)){
  24. tmpSave.add(left);
  25. }
  26. }
  27. //-----check right--------
  28. if(n.getX() < array[n.getY()].length - 1){
  29. right = array[n.getY()][n.getX() + 1];
  30. if(right.isSet() && !tmpBurnt.contains(right) && !this.burnt.contains(right)){
  31. tmpSave.add(right);
  32. }
  33. }
  34. //-----check below--------
  35. if(n.getY() < array.length - 1){
  36. below = array[n.getY() + 1][n.getX()];
  37. if(below.isSet() && !tmpBurnt.contains(below) && !this.burnt.contains(below)){
  38. tmpSave.add(below);
  39. }
  40. }
  41. }
  42. for(Node n : tmpBurnt){
  43. this.burnt.add(n);
  44. }
  45. tmpBurnt.clear();
  46. for(Node n : tmpSave){
  47. tmpBurnt.add(n);
  48. }
  49. tmpSave.clear();
  50. }
  51. }
Add Comment
Please, Sign In to add comment