Giter VIP home page Giter VIP logo

eight-puzzle-solver's Introduction

Eight-Puzzle Solver

Introduction

This is a 8-puzzle solver that utilizes A* algorithm to solve the problem. This solver also includes implementations of WA* and Greedy Best First algorithms.

This code requires the following nonstandard libraries:

  • numpy
    • pip3 install numpy (If you don’t have it installed)
  • distance
    • pip3 install distance (If you don’t have it installed)

The program consists of two files: eightpuzzlesolver.py and eightpuzzlesolver_test.py. You can run eightpuzzlesolver.py by itself, it’ll print out results in one of the following forms:

True, [iteration, running_time, len(self.visited), len(self.unvisited), len(backtrace)
False, [iteration, running_time]

Where True/False denotes whether the run terminated in the given iteration limits.

You can also uncomment the print statements from the code and get more detailed description. Additionally, if you give print_trace=True to the EightPuzzleSolver class as a parameter, the solver will print the steps to reach the goal form the initial state.

eightpuzzlesolver_test.py will generate csv file from the tests that it runs. It’ll run every single algorithm: a*, wa* (weights: 5, 10, 15, 20) and greedy best first with every possible tile amounts. For every tile variation, the tester runs 10 random solvers with the given parameters and calculates their average statistics.

The tester runs 6 parallel processes to decrease the execution time.

The code folder also includes an excel file of the tester output for your convenience.

Results

The a_star_stats_excel.xlsx contains the other WA* runs.

WA* with weight = 10 results in the best steps to running time combo. A* is the best considering the shortness of the total steps. Greedy best first on the other hand results in poor performance when the number of tiles is larger, given the scarcity of successful runs, i.e. the runs that terminated in the given iteration limits.

It seems that greedy best first tends to open a lot of nodes, but cannot differentiate between better and worse ones because it does not care about the spent moves. Occasionally it gets lucky and finds the solution quickly.

eight-puzzle-solver's People

Contributors

anttip1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.