Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void searchCluster(Grid grid){
- Node[][] array = grid.getNodeArray();
- ArrayList<Node> tmpBurnt = new ArrayList();
- LinkedList<Node> tmpSave = new LinkedList();
- Node left;
- Node right;
- Node below;
- for(Node n : array[0]){
- if(n.isSet()){
- tmpBurnt.add(n);
- }
- }
- for(;;){
- if(tmpBurnt.isEmpty()){
- return;
- }
- for(Node n : tmpBurnt){
- //-----check left--------
- if(n.getX() > 0){
- left = array[n.getY()][n.getX() - 1];
- if(left.isSet() && !tmpBurnt.contains(left) && !this.burnt.contains(left)){
- tmpSave.add(left);
- }
- }
- //-----check right--------
- if(n.getX() < array[n.getY()].length - 1){
- right = array[n.getY()][n.getX() + 1];
- if(right.isSet() && !tmpBurnt.contains(right) && !this.burnt.contains(right)){
- tmpSave.add(right);
- }
- }
- //-----check below--------
- if(n.getY() < array.length - 1){
- below = array[n.getY() + 1][n.getX()];
- if(below.isSet() && !tmpBurnt.contains(below) && !this.burnt.contains(below)){
- tmpSave.add(below);
- }
- }
- }
- for(Node n : tmpBurnt){
- this.burnt.add(n);
- }
- tmpBurnt.clear();
- for(Node n : tmpSave){
- tmpBurnt.add(n);
- }
- tmpSave.clear();
- }
- }
Add Comment
Please, Sign In to add comment