Skip to content

The goal of this project is to solve the N-puzzle game using the A*search algorithm or one of its variants.

Notifications You must be signed in to change notification settings

aallali/N-Puzzle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

n-puzzle 1337 @ aallali

███╗   ██╗      ██████╗ ██╗   ██╗███████╗███████╗██╗     ███████╗
████╗  ██║      ██╔══██╗██║   ██║╚══███╔╝╚══███╔╝██║     ██╔════╝
██╔██╗ ██║█████╗██████╔╝██║   ██║  ███╔╝   ███╔╝ ██║     █████╗  
██║╚██╗██║╚════╝██╔═══╝ ██║   ██║ ███╔╝   ███╔╝  ██║     ██╔══╝  
██║ ╚████║      ██║     ╚██████╔╝███████╗███████╗███████╗███████╗
╚═╝  ╚═══╝      ╚═╝      ╚═════╝ ╚══════╝╚══════╝╚══════╝╚══════╝
by : 
┌─┐┌┐ ┌┬┐┌─┐┬  ┬  ┌─┐┬ ┬  ┌─┐┬  ┬  ┌─┐┬  ┬
├─┤├┴┐ ││├┤ │  │  ├─┤├─┤  ├─┤│  │  ├─┤│  │
┴ ┴└─┘─┴┘└─┘┴─┘┴─┘┴ ┴┴ ┴  ┴ ┴┴─┘┴─┘┴ ┴┴─┘┴
usage: npuzzle.py [-h] 
                  [-g] [-u] 
                  [-f {hamming,gaschnig,manhattan,conflicts,euclidean,diagonal}]
                  [-s {zero_first,zero_last,snail}] 
                  [-v] 
                  [-t T] 
                  [--fast]
                  file

n-puzzle @ 42 aallali

positional arguments:
  file                  input file

optional arguments:
  -h, --help            show this help message and exit
  -g                    greedy search
  -u                    uniform-cost search
  -f {hamming,gaschnig,manhattan,conflicts,euclidean,diagonal}
                        heuristic function
  -s {zero_first,zero_last,snail}
                        snail
  -v                    gui visualizer
  -t T                  Solution replay on terminal, animation speed time value required
                        (Disabled default)
  --fast                fast search

search:

default search is A*

  • fast and efficient
  • memory heavy

input puzzle configurations:

-s zero_first (blank tile first)

3
0  1  2
3  4  5
6  7  8

-s zero_last (blank tile last)

3
1  2  3
4  5  6
7  8  0

-s snail (default, spiral pattern)

3
1  2  3
8  0  4
7  6  5

heuristics:

-f hamming hamming distance aka "tiles out of place"

-f gaschnig performs better than hamming distance

-f manhattan manhattan distance heuristic (default)

-f conflicts linear conflicts usually more informed than manhattan distance

-f euclidean euclidean distance heuristic (not good as manhattan)

-f diagonal euclidean distance heuristic (not good as manhattan)

miscellaneous:

-g greedy search: ignores the g(n) in A* formula f(n) = g(n) + h(n), quickly finds a suboptimal solution

-u uniform cost search: discards the h(n) in A* formula (turns off heuristics and becomes dijkstra's, slow)

-v replay solution steps in graphical visualizer

-t replay solution steps in terminal with colorized outprint

--fast use a faster search alogrithm but add more moves to goal

Ready command for terminal (windows):

py -2 .\generator.py -s -i 1000 3 > test && cls && py -3 .\npuzzle.py .\test -f conflicts -v

View from GUI Visualation :

gui

GIF from GUI Visualation :

gui

View from Terminal :

terminal

About

The goal of this project is to solve the N-puzzle game using the A*search algorithm or one of its variants.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages