mp_puzzle
Perplexing Puzzles
puzzle.h File Reference

Implementation of puzzle class. More...

Classes

class  PuzzleState
 

Functions

std::vector< PuzzleStatesolveAstar (const PuzzleState &startState, const PuzzleState &desiredState, size_t *iterations=NULL)
 Solves the puzzle using A* with manhattan distance as a heuristic. More...
 
std::vector< PuzzleStatesolveBFS (const PuzzleState &startState, const PuzzleState &desiredState, size_t *iterations=NULL)
 Solves the puzzle using BFS. More...
 

Detailed Description

Implementation of puzzle class.

Function Documentation

◆ solveAstar()

std::vector< PuzzleState > solveAstar ( const PuzzleState startState,
const PuzzleState desiredState,
size_t *  iterations = NULL 
)

Solves the puzzle using A* with manhattan distance as a heuristic.

Parameters
startStateThe starting state of the puzzle
desiredStateThe final goal state of the puzzle after solving
iterationsThe number of iterations it took to solve the puzzle. An iteration is defined as the number of times a state is popped from the data structure (NOTE: this should include the start and desired states, but not any states that are immediately discarded, if applicable). We will use the value stored at this pointer to evaluate efficiency. Ignore if NULL.
Returns
The path to the solution. The first element of the vector is the start state, and the last element is the desired state. Empty if no solution exists.

◆ solveBFS()

std::vector< PuzzleState > solveBFS ( const PuzzleState startState,
const PuzzleState desiredState,
size_t *  iterations = NULL 
)

Solves the puzzle using BFS.

Parameters
startStateThe starting state of the puzzle
desiredStateThe final goal state of the puzzle after solving
iterationsThe number of iterations it took to solve the puzzle. An iteration is defined as the number of times a state is popped from the data structure (NOTE: this should include the start and desired states, but not any states that are immediately discarded, if applicable). We will use the value stored at this pointer to evaluate efficiency. Ignore if NULL.
Returns
The path to the solution. The first element of the vector is the start state, and the last element is the desired state. Empty if no solution exists.