TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
A class defining EightPuzzle/15-Puzzle game. More...
Public Member Functions | |
uint32_t | get (size_t i, size_t j) const |
get the value from i units from right and j units from left side of the board | |
std::array< std::array< uint32_t, N >, N > | get_state () |
Returns the current state of the board. | |
size_t | get_size () const |
returns the size of the EightPuzzle (number of row / column) | |
EightPuzzle () | |
Default constructor for EightPuzzle. | |
EightPuzzle (const std::array< std::array< uint32_t, N >, N > &init) | |
Parameterized Constructor for EightPuzzle. | |
EightPuzzle (const EightPuzzle< N > &A) | |
Copy constructor. | |
EightPuzzle (const EightPuzzle< N > &&A) noexcept | |
Move constructor. | |
~EightPuzzle ()=default | |
Destructor of EightPuzzle. | |
EightPuzzle & | operator= (const EightPuzzle &A) |
Copy assignment operator. | |
EightPuzzle & | operator= (EightPuzzle &&A) noexcept |
Move assignment operator. | |
std::vector< EightPuzzle< N > > | generate_possible_moves () |
Find all possible states after processing all possible moves, given the current state of the puzzle. | |
bool | operator== (const EightPuzzle< N > &check) const |
check whether two boards are equal | |
bool | operator< (const EightPuzzle< N > &check) const |
check whether one board is lexicographically smaller | |
bool | operator<= (const EightPuzzle< N > &check) const |
check whether one board is lexicographically smaller or equal | |
Private Member Functions | |
std::pair< uint32_t, uint32_t > | find_zero () |
A helper array to evaluate the next state from current state;. | |
bool | in_range (const uint32_t value) const |
check whether the index value is bounded within the puzzle area | |
Private Attributes | |
std::array< std::array< uint32_t, N >, N > | board |
std::vector< std::pair< int8_t, int8_t > > | moves |
N x N array to store the current state of the Puzzle. | |
Friends | |
std::ostream & | operator<< (std::ostream &op, const EightPuzzle< N > &SomeState) |
friend operator to display EightPuzzle<> | |
A class defining EightPuzzle/15-Puzzle game.
A well known 3 x 3 puzzle of the form 1 2 3 4 5 6 7 8 0
where 0
represents an empty space in the puzzle Given any random state, the goal is to achieve the above configuration (or any other configuration if possible)
N | size of the square Puzzle, default is set to 3 (since it is EightPuzzle) |
Definition at line 60 of file a_star_search.cpp.
|
inline |
Default constructor for EightPuzzle.
Definition at line 121 of file a_star_search.cpp.
|
inlineexplicit |
Parameterized Constructor for EightPuzzle.
init | a 2-dimensional array denoting a puzzle configuration |
Definition at line 132 of file a_star_search.cpp.
|
inline |
Copy constructor.
A | a reference of an EightPuzzle |
Definition at line 139 of file a_star_search.cpp.
|
inlinenoexcept |
Move constructor.
A | a reference of an EightPuzzle |
Definition at line 145 of file a_star_search.cpp.
|
inlineprivate |
A helper array to evaluate the next state from current state;.
Finds an empty space in puzzle (in this case; a zero)
Definition at line 75 of file a_star_search.cpp.
|
inline |
Find all possible states after processing all possible moves, given the current state of the puzzle.
Definition at line 176 of file a_star_search.cpp.
|
inline |
get the value from i units from right and j units from left side of the board
i | integer denoting ith row |
j | integer denoting column |
Definition at line 102 of file a_star_search.cpp.
|
inline |
returns the size of the EightPuzzle (number of row / column)
Definition at line 117 of file a_star_search.cpp.
|
inline |
Returns the current state of the board.
Definition at line 111 of file a_star_search.cpp.
|
inlineprivate |
check whether the index value is bounded within the puzzle area
value | index for the current board |
true
if index is within the board, else false
Definition at line 90 of file a_star_search.cpp.
|
inline |
check whether one board is lexicographically smaller
true
if this->state is lexicographically smaller than check.state
, else false
Definition at line 218 of file a_star_search.cpp.
|
inline |
check whether one board is lexicographically smaller or equal
true
if this->state is lexicographically smaller than check.state
or same, else false
Definition at line 233 of file a_star_search.cpp.
|
inline |
Copy assignment operator.
A | a reference of an EightPuzzle |
Definition at line 156 of file a_star_search.cpp.
|
inlinenoexcept |
Move assignment operator.
A | a reference of an EightPuzzle |
Definition at line 165 of file a_star_search.cpp.
|
inline |
check whether two boards are equal
true
if check.state is equal to this->state
, else false
Definition at line 200 of file a_star_search.cpp.
|
friend |
friend operator to display EightPuzzle<>
op | ostream object |
SomeState | a certain state. |
Definition at line 250 of file a_star_search.cpp.
|
private |
Definition at line 62 of file a_star_search.cpp.
|
private |
N x N array to store the current state of the Puzzle.
Definition at line 64 of file a_star_search.cpp.