Giter Club home page Giter Club logo

ai-n-puzzle's Introduction

AI-n-puzzle

A solver for n-puzzle board games given an arbitrary starting configuration

The N-puzzle is a sliding puzzle that consists of a board holding N = m^2 − 1 (m = 3, 4, 5, ...) distinct movable tiles, plus an empty space. The tiles are numbers from the set {1, …, m^2 − 1} and the empty space may be swapped with any tile horizontally or vertically ('Up', 'Down', 'Left', 'Right').

Given an initial state of the board, the combinatorial search problem is to find a sequence of moves that transitions this state to the goal state; that is, the configuration with all tiles arranged in ascending order ⟨0, 1, …, m^2 − 1⟩. The search space is the set of all possible states reachable from the initial state.

8-Puzzle Game Example

Three algorithms are implemented:

  1. Breadth-First Search (bfs): Expand shallowest node; explore all neighbors at present depth of the tree before moving down (FIFO queue implementation)
  2. Depth-First Search (dfs): Expand deepest node; explore along the current branch as deep as possible before backtracing (LIFO queue implementation)
  3. A-Star Search (ast): Minimize total estimated solution cost (Priority queue implementation)

Running the Puzzle Solver:

$ python3 driver.py dfs 1,2,5,3,4,0,6,7,8

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.