Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Node bfs() {
- try {
- Queue<Node> q = new LinkedList<Node>();
- q.add(root);
- while(!q.isEmpty()) {
- Node node = q.poll();
- node.setCount(counter);
- //node.getBoard().printBoard();
- if(this.checkGoal(node)) {
- //System.out.println("Nodes expanded = " + counter);
- //System.out.println("Solution: " + node.getMoves());
- counter = 0;
- return node;
- }
- ArrayList<Node> children = node.expand();
- counter++;
- //System.out.println(node.getLevel());
- for(Node c : children) {
- q.add(c);
- }
- }
- System.out.println("No solutions found");
- System.out.println("Nodes expanded = " + counter);
- counter = 0;
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement