Search algorithms for the 8-puzzle solution
|
Implementation of a hill-climbing optimization algorithm for the 8-puzzle. More...
#include <HillClimbingSolver.hpp>
Public Member Functions | |
HillClimbingSolver (Heuristic *h) | |
Initializes a regular hill-climbing 8-puzzle solver. More... | |
HillClimbingSolver (Heuristic *h, bool steepest) | |
Initializes a hill-climbing 8-puzzle solver. More... | |
~HillClimbingSolver () | |
LinkedList< GameState * > | solve (Game &game, GameState &g0) |
Explores the game tree in search of the goal state. More... | |
![]() | |
double | getSecondsToSolve () const |
int | getVisitedNodes () const |
int | getMaxDepth () const |
int | getSolutionDepth () const |
bool | isSolved () |
Solver () | |
string | to_string () |
Generates a string containing useful information from the solver run. More... | |
Static Public Member Functions | |
static int | compare (GameState *a, GameState *b) |
Compares two states using the available heuristic. More... | |
Private Attributes | |
Heuristic * | heuristic |
bool | steepest |
Additional Inherited Members | |
![]() | |
bool | isVisited (GameState &g) |
Checks whether a node has already been visited by the solver. More... | |
LinkedList< GameState * > | visit (GameState *current) |
LinkedList< GameState * > | visit (GameState *current, bool keepVisited) |
Visit a game state, adding it to the list of visited states and returning its valid child states. More... | |
LinkedList< GameState * > | endSearch (GameState *currentGame, const clock_t start) |
End the search, generating the steps from the initial state to the goal. More... | |
![]() | |
OrderedList< GameState * > | visited = OrderedList<GameState *>(compare) |
int | visitedNodes |
int | maxDepth |
int | solutionDepth |
float | secondsToSolve |
bool | solved |
Implementation of a hill-climbing optimization algorithm for the 8-puzzle.
Definition at line 15 of file HillClimbingSolver.hpp.
|
inlineexplicit |
Initializes a regular hill-climbing 8-puzzle solver.
h | the heuristic to be minimized |
Definition at line 25 of file HillClimbingSolver.hpp.
|
inlineexplicit |
Initializes a hill-climbing 8-puzzle solver.
h | the heuristic to be minimized |
steepest | if true, always look for the best among all child states, otherwise choose the first one that is better than the parent state. |
Definition at line 32 of file HillClimbingSolver.hpp.
|
inline |
Definition at line 35 of file HillClimbingSolver.hpp.
Compares two states using the available heuristic.
The state that has the lowest heuristic is considered a more promising exploration candidate.
a | |
b |
Definition at line 44 of file HillClimbingSolver.hpp.
Explores the game tree in search of the goal state.
Exploration is done by applying one of the four valid actions of the 8-puzzle to intermediate, non-goal states until the goal state is reached.
g | A description of the game. |
gs | The initial state of the game. |
Implements Solver.
Definition at line 54 of file HillClimbingSolver.hpp.
|
private |
Definition at line 18 of file HillClimbingSolver.hpp.
|
private |
Definition at line 19 of file HillClimbingSolver.hpp.