All pastes #720839 Raw Edit

Blah

public text v1 · immutable
#720839 ·published 2007-09-30 19:00 UTC
rendered paste body
#include "solver.h"

//#include <cstdlib>
#include <iostream>
#include <vector>
#include <queue>

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;
}