aboutsummaryrefslogtreecommitdiff
path: root/Week6/src/Solver.java
blob: 137646c7bf25c72d81211a02df307c94b991b8a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Queue;


/**
 * A class that implements a breadth-first search algorithm
 * for finding the Configurations for which the isSolution predicate holds
 * @author Pieter Koopman, Sjaak Smetsers
 * @version 1.3
 * @date 28-02-2013
 */
public class Solver
{
    // A queue for maintaining graphs that are not visited yet.
    Queue<Configuration> toExamine;

    public Solver(Configuration g) {
        throw new UnsupportedOperationException("Solver: not supported yet.");        
    }
    
    /* A skeleton implementation of the solver
     * @return a string representation of the solution
     */
    public String solve () {
        while (! toExamine.isEmpty() ) {
            Configuration next = toExamine.remove();
            if ( next.isSolution() ) {
                return "Success!";
            } else {
                for ( Configuration succ: next.successors() ) {
                    toExamine.add  (succ);
                }
            }
        }
        return "Failure!";
    }
    
}