Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public Node bfs() {
  2. try {
  3. Queue<Node> q = new LinkedList<Node>();
  4. q.add(root);
  5.  
  6. while(!q.isEmpty()) {
  7.  
  8. Node node = q.poll();
  9. node.setCount(counter);
  10. //node.getBoard().printBoard();
  11.  
  12. if(this.checkGoal(node)) {
  13. //System.out.println("Nodes expanded = " + counter);
  14. //System.out.println("Solution: " + node.getMoves());
  15. counter = 0;
  16. return node;
  17. }
  18.  
  19. ArrayList<Node> children = node.expand();
  20.  
  21.  
  22.  
  23. counter++;
  24. //System.out.println(node.getLevel());
  25. for(Node c : children) {
  26.  
  27. q.add(c);
  28. }
  29. }
  30.  
  31. System.out.println("No solutions found");
  32. System.out.println("Nodes expanded = " + counter);
  33. counter = 0;
  34. return null;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement