8-puzzle exploration based on a depth-first search strategy
More...
#include <DepthFirstSolver.hpp>
8-puzzle exploration based on a depth-first search strategy
- Author
- Douglas De Rizzo Meneghetti (dougl.nosp@m.asri.nosp@m.zzom@.nosp@m.gmai.nosp@m.l.com)
- Date
- 2017-6-238-puzzle exploration based on a depth-first search strategy
Definition at line 16 of file DepthFirstSolver.hpp.
◆ DepthFirstSolver() [1/2]
DepthFirstSolver::DepthFirstSolver |
( |
| ) |
|
|
inline |
◆ DepthFirstSolver() [2/2]
DepthFirstSolver::DepthFirstSolver |
( |
int |
maxDepth | ) |
|
|
inlineexplicit |
- Parameters
-
maxDepth | the maximum depth allowed for exploration |
Definition at line 28 of file DepthFirstSolver.hpp.
◆ solve()
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.
- Parameters
-
g | A description of the game. |
gs | The initial state of the game. |
- Returns
- list containing all states explored, from the initial state to the goal state.
Implements Solver.
Definition at line 31 of file DepthFirstSolver.hpp.
34 DynamicStack<GameState *> expanded;
36 const clock_t start = clock();
38 int currentMaxDepth = 0;
40 while (! expanded.isEmpty()) {
43 if (currentGame->
getDepth() > currentMaxDepth) {
44 currentMaxDepth = currentGame->
getDepth();
51 if (*game.getGoal() == *currentGame) {
58 LinkedList<GameState *> children =
visit(currentGame);
61 while (! children.isEmpty()) {
62 expanded.push(children.remove(0));
66 throw invalid_argument(
"This game is unsolvable!");
LinkedList< GameState * > endSearch(GameState *currentGame, const clock_t start)
End the search, generating the steps from the initial state to the goal.
LinkedList< GameState * > visit(GameState *current)
Describes a single state in the 8-puzzle.
◆ maxDepth
int DepthFirstSolver::maxDepth |
|
private |
The documentation for this class was generated from the following file: