Coder Social home page Coder Social logo

n-puzzle-problem's Introduction

n-puzzle-problem

Solving classical problem the 8 puzzle problem using A* algorithm. Developed initially for 8-puzzle problem and then modified to work with n-puzzle problem. The heuristic used in this case is number of misplaced tiles. This heuristic does not over estimates and hence it is admissible. The A* search algorithm is optimal and always finds a path with the minimum cost.

The program stores the states in a data structure

state_node{ 
	state 	- the state of the puzzle
	id 		- an unique number given to this state
	h 		- the heuristic
	g 		- actual cost from the starting point to this node 
	f 		- f = g+h(as in A*algorithm)
}

n Puzzle problem have many states which are unsolvable. Such states cannot be solved by legal moves of the puzzle. The program identifies such by generating all the possible unsolvable states in n puzzle problem board then comparing every state generated by the solver to this list.

The program also checks for validity of the puzzle given to solve by verifying it as a n x n matrix. The goal state is not hard coded in the program. The program generates the goal state for any n puzzle depending on the value of n.

How to compile and run

[1]> (load "/npuzzle.lisp")

[2]> (solve-npuzzle '#(0 1 3 4 2 5 7 8 6))

Output comes here

Contact Information

Name: Rohit Sinha

Email id: [email protected]

n-puzzle-problem's People

Contributors

rohitsinha54 avatar

Stargazers

 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.