This is a C++ program that solves the NxN puzzle game using two different search algorithms, A*
and IDA*
.
This project was developed as a final project for CSE 202.
To run the program, you need to have a GCC C++ or Clang compiler and CMake installed on your system.
Firstly, for users using homebrew, you can install CMake by running the following command:
brew install cmake
(Optional) Note that for macOS, we recommend using Clang as your preferred compiler. Also, to ensure coding style consistency, we suggest installing clang-format using brew.
Next, to compile the program, follow these steps:
- Create a build folder
mkdir build && cd build
- Configure the project
export CC=clang
export CXX=clang++
cmake -DCMAKE_BUILD_TYPE=Release ..
- Build the project
cmake --build .
The program can be used with the following arguments:
Usage: puzzle_solver [--help] [--version] [--algorithm VAR] --k VAR --NxN-puzzle VAR --input_file VAR
Optional arguments:
-h, --help shows help message and exits
-v, --version prints version information and exits
-a, --algorithm specify the algorithm to use. The available algorithms are: Astar and IDAstar. The default algorithm is Astar. [default: "Astar"]
-k, --k specify the parameter of the heuristic function [required]
-n, --NxN-puzzle specify the dimension of puzzle grid [required]
-i, --input_file specify the input file. The input file should be in the format of NxN puzzle grid, with each row separated by a newline character, and each number separated by a comma. The number 0 represents the empty slot. [required]
An example usage case is provided in example_run.sh
. To generate files with random input status for a given puzzle grid dimension, a Python script genInput.py is included in the ./res
folder.