#include "solver.h" //#include #include #include #include using namespace std; Solver::Solver( Clock& toSolve ) { puzzle = toSolve; } int Solver::solve( int configuration ) { int result; // Holds path to queue< int > q; vector< int > pathsSeen; q.push( configuration ); // Add the initial configuration to the queue while( q.size() != 0 && q.front() != puzzle.getEnd() ) { // Get next item from the queue int current = q.back(); // Make a list of seen paths pathsSeen.push_back( current ); // Create a temporary vector of possible paths vector< int > neighbors = puzzle.getPaths( current ); for( int i = 0; i < neighbors.size(); i++ ) { // Check if the neighbor has already been seen bool seen = false; for( int j = 0; j < pathsSeen.size() && !seen; j++ ) { if( pathsSeen[j] == neighbors[i] ) { seen = true; } } // If it hasn't been seen, add it to the queue if( !seen ) { q.push( neighbors[i] ); } } } //Ends when queue is empty or if answer found return result; }