15Slide
|
Helps with movement of tiles, saving/loading, and other management features for a Grid. More...
Functions | |
void | swapTile (const std::uint8_t tileY, const std::uint8_t tileX, Grid &grid) |
Swaps the tile at the given coordinates with the no tile of a Grid. More... | |
void | swapTile (const std::uint8_t tileNum, Grid &grid) |
Swaps the tile given with the no tile of a Grid. More... | |
bool | validMove (const std::uint8_t tileNum, const Grid &grid) |
Checks if the tile movement will be valid between a tile and the no tile of a Grid. More... | |
bool | validMove (const std::uint8_t tileY, const std::uint8_t tileX, const Grid &grid) |
Checks if the tile movement will be valid between a tile and the no tile of a Grid. More... | |
bool | hasWon (const Grid &grid) |
Checks if a Grid is won. More... | |
bool | validGridArray (const Grid::gridArray_t &grid) |
Checks if a grid array is valid. More... | |
bool | validIndex (const Grid::gridArray_t &grid, const Grid::index_t &index) |
Checks if an index is valid. More... | |
void | safeCopy (const Grid::gridArray_t &newGrid, Grid &grid) |
Copies a Grid. Better than Grid::setGrid because it ensures validation and also creates a new index. More... | |
void | safeCopy (const Grid &newGrid, Grid &grid) |
Copies a Grid. Better than Grid::setGrid because it ensures validation of the grid array and the index. More... | |
bool | validGrid (const Grid &grid) |
Checks if a Grid is valid, including grid array and index. More... | |
Grid15::Grid::gridArray_t | generateRandomGridArray () |
Creates a new, random, and solvable grid array. More... | |
Grid | generateRandomGrid () |
Creates a new, random, and solvable Grid. More... | |
bool | solvableGrid (const Grid::gridArray_t &gridArray) |
Checks if a grid is solvable or not. More... | |
bool | solvableGrid (const Grid &grid) |
Checks if a grid is solvable or not. More... | |
void | save (const std::string &saveFile, const Grid &grid) |
Saves a Grid to disk (not the index) More... | |
void | load (const std::string &saveFile, Grid &grid) |
Loads a Grid from disk (and recreates the index) More... | |
void | reIndex (Grid &grid) |
Reads the grid array of a Grid and updates its index. More... | |
Helps with movement of tiles, saving/loading, and other management features for a Grid.
Because of the way initilizer lists are in C++, and because this issue as noticed long into development, Y coordinates are switched with X in GridHelp.
This effects the order of function parameters, loops (i == y, j == x ) and arrays in both this library and other 15Slide code that uses it.
See https://github.com/JZJisawesome/15Slide/issues/22 for details and possible changes to this.
Grid Grid15::GridHelp::generateRandomGrid | ( | ) |
Grid::gridArray_t Grid15::GridHelp::generateRandomGridArray | ( | ) |
Creates a new, random, and solvable grid array.
bool Grid15::GridHelp::hasWon | ( | const Grid & | grid | ) |
Checks if a Grid is won.
grid | The Grid to use |
std::invalid_argument | If the grid array is not valid |
void Grid15::GridHelp::load | ( | const std::string & | saveFile, |
Grid & | grid | ||
) |
void Grid15::GridHelp::reIndex | ( | Grid & | grid | ) |
void Grid15::GridHelp::safeCopy | ( | const Grid::gridArray_t & | newGrid, |
Grid & | grid | ||
) |
Copies a Grid. Better than Grid::setGrid because it ensures validation and also creates a new index.
newGrid | The new grid array to use |
grid | The Grid to copy to |
std::invalid_argument | If the new Grid is invalid |
Copies a Grid. Better than Grid::setGrid because it ensures validation of the grid array and the index.
newGrid | The new grid to |
grid | The Grid to copy to |
std::invalid_argument | If the new Grid is invalid |
void Grid15::GridHelp::save | ( | const std::string & | saveFile, |
const Grid & | grid | ||
) |
bool Grid15::GridHelp::solvableGrid | ( | const Grid::gridArray_t & | gridArray | ) |
Checks if a grid is solvable or not.
This function never contained any licenceless code: it was always 15Slide source, so the false comment that was here has been removed
gridArray | The grid array to check |
std::invalid_argument | If the new Grid is invalid (index and/or grid array) |
bool Grid15::GridHelp::solvableGrid | ( | const Grid & | grid | ) |
Checks if a grid is solvable or not.
This function is a rewrite of the previous, unlicenced code, which I wanted to remove because I am worried about legal problems. I wrote it with information from https://www.cs.bham.ac.uk/~mdr/teaching/modules04/java2/TilesSolvability.html, from scratch to be clear.
grid | The Grid to check |
std::invalid_argument | If the new Grid is invalid (index and/or grid array) |
void Grid15::GridHelp::swapTile | ( | const std::uint8_t | tileY, |
const std::uint8_t | tileX, | ||
Grid & | grid | ||
) |
void Grid15::GridHelp::swapTile | ( | const std::uint8_t | tileNum, |
Grid & | grid | ||
) |
bool Grid15::GridHelp::validGrid | ( | const Grid & | grid | ) |
bool Grid15::GridHelp::validGridArray | ( | const Grid::gridArray_t & | grid | ) |
Checks if a grid array is valid.
grid | The grid array to check |
bool Grid15::GridHelp::validIndex | ( | const Grid::gridArray_t & | grid, |
const Grid::index_t & | index | ||
) |
Checks if an index is valid.
grid | The grid array to compare the index to |
index | The index |
std::invalid_argument | If the gridArray (not the index) is invalid |
bool Grid15::GridHelp::validMove | ( | const std::uint8_t | tileNum, |
const Grid & | grid | ||
) |
bool Grid15::GridHelp::validMove | ( | const std::uint8_t | tileY, |
const std::uint8_t | tileX, | ||
const Grid & | grid | ||
) |