Package com.gonzales.mark.n_puzzle

Package containing all the Kotlin classes, resources, and Gradle files for configuring and running the application.

About the Project

8-Puzzle is a sliding puzzle game that features a walkthrough of the optimal solution and allows users to customize the tiles using photos selected from their Gallery. In finding the optimal path from the current puzzle state to the goal state, the system employs the informed search algorithm A* and uses Manhattan distance as an admissible and consistent heuristic to estimate the cost.

Inspired by an exercise in our Mobile Development class, I started creating this app during our university break, after finishing my second year of undergraduate studies. As one of my first personal projects, working on this was an opportunity to synthesize concepts and practices that I learned from our sophomore courses, such as:

  • Exploration of language features (Advanced Programming and Theory of Programming Languages)

  • Program optimization (Algorithms and Complexity)

  • Artificial intelligence and search algorithms (Introduction to Intelligent Systems)

  • Quality assurance and unit testing (Introduction to Software Engineering)

This project also utilizes a continuous integration/continuous delivery (CI/CD) pipeline — which is the focus of our third-year class Advanced Software Engineering.

Types

AnimationUtil
Link copied to clipboard
class AnimationUtil
Utility class providing constants related to timing the animations in the app.
FlingDetector
Link copied to clipboard
class FlingDetector
Class providing the constants and methods for identifying the direction of a fling gesture.
FlingDirection
Link copied to clipboard
enum FlingDirection : Enum<FlingDirection>
Enumeration class containing the directions of the fling gestures registered by the app (namely, the four cardinal directions) and an INVALID entry for unrecognized directions.
GridViewGesture
Link copied to clipboard
class GridViewGesture : GridView
Class extending GridView to register fling gestures.
ImageUtil
Link copied to clipboard
class ImageUtil
Utility class providing constants and methods for manipulating the puzzle image.
Key
Link copied to clipboard
enum Key : Enum<Key>
Enumeration class containing the keys used in handling bundles and shared preferences.
MoveUtil
Link copied to clipboard
class MoveUtil
Utility class providing methods for moving the tiles in the puzzle grid.
Node
Link copied to clipboard
data class Node(puzzleStatePair: StatePair, parent: Node?, g: Int, h: Int)
Data class corresponding to a node.
NodeByF
Link copied to clipboard
class NodeByF : Comparator<Node>
Comparator for nodes based on their f-values (in reference to the A* algorithm).
NPuzzleActivity
Link copied to clipboard
class NPuzzleActivity : AppCompatActivity
Class handling the core functionalities of this 8-puzzle app, including the actual gameplay.
OnFlingListener
Link copied to clipboard
interface OnFlingListener
Interface for responding to detected fling gestures.
PuzzleImage
Link copied to clipboard
enum PuzzleImage(drawableId: Int) : Enum<PuzzleImage>
Enumeration class containing the puzzle images that come with the app.
PuzzleUtil
Link copied to clipboard
class PuzzleUtil
Utility class providing methods related to the puzzle state.
RequestCode
Link copied to clipboard
enum RequestCode : Enum<RequestCode>
Class containing the codes used in requesting permissions related to launching activities related to the Gallery of the device.
ShuffleRunnable
Link copied to clipboard
class ShuffleRunnable(handler: Handler, tilePosition: Int, numTiles: Int) : Runnable
Runnable class related to shuffling the puzzle tiles.
ShuffleUtil
Link copied to clipboard
class ShuffleUtil
Utility class providing methods for shuffling the puzzle tiles.
SolveStatus
Link copied to clipboard
enum SolveStatus(successMessageId: Int) : Enum<SolveStatus>
Enumeration class containing the possible game statuses depending on whether user solves the puzzle or opts to play the solution walkthrough instead.
SolveUtil
Link copied to clipboard
class SolveUtil
Utility class providing constants and methods related to solving an 8-puzzle.
SpinnerAdapter
Link copied to clipboard
class SpinnerAdapter(context: Context?, textViewResourceId: Int, objects: Array<String?>?) : ArrayAdapter<String?>
Adapter for the spinner that handles the selection of the puzzle image.
SplashScreenActivity
Link copied to clipboard
class SplashScreenActivity : AppCompatActivity
Class handling the display of the splash screen and the loading of initial resources needed during app startup.
StatePair
Link copied to clipboard
data class StatePair(puzzleState: ArrayList<Int>, blankTilePos: Int)
Pair representing a puzzle state (flattened into one dimension, following row-major order) alongside the position of the blank tile in the puzzle grid (zero-based, following row-major order).
TileAdapter
Link copied to clipboard
class TileAdapter(tileImages: ArrayList<ImageButton>, tileWidth: Int, tileHeight: Int) : BaseAdapter
Adapter for GridViewGesture that handles the tiles in the puzzle grid.
TimeUtil
Link copied to clipboard
class TimeUtil
Utility class providing constants and methods related to the app's timer.
UploadUtil
Link copied to clipboard
class UploadUtil
Utility class providing methods for choosing a photo from the Gallery as the custom puzzle image.