Skip to content
Solve and test algorithms for N-Puzzle problem with Python
Branch: master
Clone or download
Latest commit 4f50f14 Jan 28, 2017
Permalink
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
README.md Update README.md Jan 28, 2017
pynpuzzle.py Don't start search process if not algorithm is loaded Dec 28, 2016

README.md

pynpuzzle

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.

Installing

Prerequisites

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

Windows

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 pynpuzzle.py from command line: python pynpuzzle.py.

Adding new algorithm

pynpuzzle loads algorithms from algorithms folder next to pynpuzzle.py.
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 (test_algorithm.py):

def search(state, goal_state):
  """
  Test algorithm
  """
  pass
  

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:

Author

Hamidreza Mahdavipanah

License

MIT

You can’t perform that action at this time.