ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
FifteenPuzzle.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File FifteenPuzzle.h --------------------------*/
3/*--------------------------------------------------------------------------*/
50/*--------------------------------------------------------------------------*/
51/*----------------------------- DEFINITIONS --------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54#ifndef __ADS_FifteenPuzzle
55 #define __ADS_FifteenPuzzle
56/* self-identification: #endif constant */
57
58/*--------------------------------------------------------------------------*/
59/*------------------------------ INCLUDES ----------------------------------*/
60/*--------------------------------------------------------------------------*/
61
62#include "ADS/Contract.h"
64
65#include <cstdlib>
66#include <map>
67#include <type_traits>
68#include <optional>
69#include <queue>
70#include <set>
71#include <vector>
72
73/*--------------------------------------------------------------------------*/
74/*--------------------------- NAMESPACE ------------------------------------*/
75/*--------------------------------------------------------------------------*/
76
77namespace ADS
78{
79
81using Board = std::vector< int >;
82
87inline Board puzzleGoal( int n );
88
94inline int manhattan( const Board & B , int n );
95
100inline std::vector< Board > puzzleMoves( const Board & B , int n );
101
106inline Board puzzleSpiralGoal( int n );
107
132inline std::optional< std::vector< Board > >
133puzzleBFS( const Board & B , const Board & goal , int n ,
134 long * visited = nullptr );
135
161inline std::optional< std::vector< Board > >
162puzzleDFS( const Board & B , const Board & goal , int n , int nmax );
163
181inline bool solvable( const Board & B , int n );
182
218template< class Map = std::map< Board , int > >
219std::optional< std::vector< Board > > solvePuzzle( const Board & B , int n ,
220 long * visited = nullptr );
221
222/*--------------------------------------------------------------------------*/
223
224} // end( namespace ADS )
225
226/*--------------------------------------------------------------------------*/
227/*-------------------------- IMPLEMENTATION --------------------------------*/
228/*--------------------------------------------------------------------------*/
229
230#include "ADS/intractable/impl/FifteenPuzzle.tpp"
231
232/*--------------------------------------------------------------------------*/
233
234#endif /* FifteenPuzzle.h included */
235
236/*--------------------------------------------------------------------------*/
237/*------------------------ End File FifteenPuzzle.h ------------------------*/
238/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The PRIORITYQUEUE [see PriorityQueue.h] on a Fibonacci heap, the structure that section 11....
W manhattan(GridCell a, GridCell b, W straight=W(1))
the distance of Manhattan between the cells and , , the least cost of a path of moves to the sides o...
bool solvable(const Board &B, int n)
whether the goal can be reached from
std::vector< Board > puzzleMoves(const Board &B, int n)
the configurations one move away, the hole swapped with the tile above, below, on the left and on the...
Board puzzleSpiralGoal(int n)
the spiral goal on squares: the tiles clockwise from the top left corner, the hole where the spiral ...
std::optional< std::vector< Board > > puzzleDFS(const Board &B, const Board &goal, int n, int nmax)
the configurations from to goal of a solution of at most moves by the backtracking in depth,...
std::optional< std::vector< Board > > solvePuzzle(const Board &B, int n, long *visited=nullptr)
the configurations from to the goal of a shortest solution, or nothing; the number of nodes extracte...
Board puzzleGoal(int n)
the goal on squares, the tiles by rows and the hole last
std::vector< int > Board
a configuration: the tile of each square by rows, 0 the hole
Definition FifteenPuzzle.h:81
std::optional< std::vector< Board > > puzzleBFS(const Board &B, const Board &goal, int n, long *visited=nullptr)
the configurations from to goal of a shortest solution by the visit in breadth, or nothing if goal c...
Definition ADT.h:96