Skip to content
Solve and test algorithms for N-Puzzle problem with Python
Branch: master
Clone or download
Latest commit 4f50f14 Jan 28, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
algorithms Don't count the blank tile Dec 24, 2016
.gitignore Ignore python cache files and folders Dec 23, 2016
LICENSE Add license file Dec 22, 2016 Update Jan 28, 2017 Don't start search process if not algorithm is loaded Dec 28, 2016


pynpuzzle is an application that helps you to solve n-puzzle problem and also to test your algorithms for n-puzzle problem. It is written in Python and uses tkinter for it's graphical interface.



Debian Linux (Ubuntu)

Open terminal and install these packages:

sudo apt-get install python3.5 python3-tk python3-psutil

Now you can run pynpuzzle from terminal: ./pynpuzzle


Download and install Python's installer (version 3.5 or higher) from it's official website. After installing python, open command line and install psutil package using pip: pip install psutil. Now you can run from command line: python

Adding new algorithm

pynpuzzle loads algorithms from algorithms folder next to
All python files (.py) inside this folder (./algorithms/*.py) are considered as algorithms and pynpuzzle tries to load them.
An algorithm module should have a search function that accepts two arguments.
First argument is the n-puzzle's current state and the second one is the goal state.
Each of the arguments are two dimensional lists that represnt a n-puzzle. For example (

def search(state, goal_state):
  Test algorithm

Docstring of the function will be presented as the name of the algorithm in app's algorithms combobox (if function has no docstring, module's filename will be used. test_algorithm in this case.).
And finally, function should return an m*n*n three dimensional list which represents a set of paths from state to goal_state.

Logs about algorithm's modules can be seen from menubar's Show logs item.

These algorithms are included in the app and can be used as code examples for adding new and more complex algorithms:


Hamidreza Mahdavipanah



You can’t perform that action at this time.