|
enum class | Direction { UP
, DOWN
, LEFT
, RIGHT
} |
|
◆ PuzzleState() [1/2]
PuzzleState::PuzzleState |
( |
| ) |
|
Default constructor for the puzzle state.
This should initialize the puzzle to the solved state.
◆ PuzzleState() [2/2]
PuzzleState::PuzzleState |
( |
const std::array< uint8_t, 16 > |
state | ) |
|
Custom constructor for the puzzle state.
Invalid inputs should initialize the puzzle representing all zeros.
- Parameters
-
state | The starting state of the puzzle. The first entry in the array is the top left tile, then the remaining entries are in row-major order. The following is a depiction of a puzzle where the value of each tile represents its index in the array: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
◆ asArray()
std::array< uint8_t, 16 > PuzzleState::asArray |
( |
| ) |
const |
Convert the puzzle state to an array.
- Returns
- an array representing the state of the puzzle in the same format as described in the constructor.
◆ getNeighbor()
PuzzleState PuzzleState::getNeighbor |
( |
Direction |
direction | ) |
const |
Get the neighbor specified by the direction.
If the direction refers to an invalid neighbor, return PuzzleState representing all zeros.
- Parameters
-
direction | The direction to move a tile (e.x. UP means the empty space should move down). |
◆ getNeighbors()
std::vector< PuzzleState > PuzzleState::getNeighbors |
( |
| ) |
const |
Gets all possible PuzzleStates that result from a single move.
- Returns
- All possible next PuzzleStates in any order
◆ manhattanDistance()
Calculates the "manhattan distance" between the current state and the goal state.
This is the sum of the manhattan distances of each tile's current location to its goal location.
- Parameters
-
desiredState | The state to calculate the distance to |
- Returns
- The manhattan distance between the current and goal states
◆ operator!=()
bool PuzzleState::operator!= |
( |
const PuzzleState & |
rhs | ) |
const |
Overloaded operator!= for the puzzle state.
- Parameters
-
rhs | The puzzle state to compare to |
◆ operator<()
bool PuzzleState::operator< |
( |
const PuzzleState & |
rhs | ) |
const |
Overloaded operator< for the puzzle state.
The PuzzleState with the first tile value less than the corresponding tile in the other PuzzleState is considered less.
- Parameters
-
rhs | The puzzle state to compare to |
◆ operator==()
bool PuzzleState::operator== |
( |
const PuzzleState & |
rhs | ) |
const |
Overloaded operator== for the puzzle state.
Puzzles are equal when the value of each tile is the same.
- Parameters
-
rhs | The puzzle state to compare to |
The documentation for this class was generated from the following file: