An implementation of A* algorithm to solve the N Puzzle problem. N Puzzle is a generalization of the famous 15 Puzzle problem. Both Python and C++ implementations are provided.
Please note that the puzzle is solved when a "snail" state is achieved, which is different from the goal state in the original statement of the problem. Here are examples
You can choose one of the following admissible heuristic functions (in order of increasing efficiency)
- Hamming
- Euclidian
- Manhattan
- Manhattan with linear conflicts
In addition, the Python implementation can accept multiple search modes:
- A* (optimal)
- greedy (fast when N is large)
- uniform
To generate puzzles,
python3 npuzzle_gen.py --help
To run Python version,
python3 -m pip install -r requirements.txt
python3 solver.py --help
python3 solver.py < "your-puzzle-file"
To run C++ version,
make
./solver --help
./solver < "your-puzzle-file"
- The
npuzzle_gen.py
script was shipped with the assignment and is courtesy of School 42 - Explanation of heuristics, esp. linear conflicts
- Multiple articles from geeksforgeeks.org that have helped me enormously when writing C++ code.