Companion

object Companion

Companion object containing the methods related to the puzzle state.

Properties

manhattan
Link copied to clipboard
private val manhattan: HashMap<Int, Int>
Maps a state (technically, its hash) to its Manhattan distance vis-à-vis the goal state.

Functions

countInversions
Link copied to clipboard
private fun countInversions(puzzleState: ArrayList<Int>, blankTileMarker: Int): Int
Counts the number of inversions in the puzzle state.
getManhattan
Link copied to clipboard
fun getManhattan(puzzleState: ArrayList<Int>, numColumns: Int, blankTileMarker: Int): Int
Computes the Manhattan distance of the given state vis-à-vis the goal state.
isBlankTile
Link copied to clipboard
private fun isBlankTile(position: Int, puzzleState: ArrayList<Int>, blankTileMarker: Int): Boolean
Checks if the tile specified by the given position is a blank tile.
isSolvable
Link copied to clipboard
fun isSolvable(puzzleState: ArrayList<Int>, blankTileMarker: Int): Boolean
Checks if the shuffled puzzle grid is solvable.
swapTiles
Link copied to clipboard
fun swapTiles(puzzleState: ArrayList<Int>, blankTileMarker: Int)
Swaps a pair of tiles.