Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving The 8 Puzzle With A* Algorithm

Tags:

java

algorithm

I would like to solve/implement the 8 puzzle problem using the A* algorithm in Java. Am asking if someone can help me by explaining to me the steps i must follow to solve it. I have read on the net how the A* works but i don't know how to begin the implementation in Java.

I will be very grateful if you guys can help me and give me the guidelines so that i can implement it myself in Java. I really want to do it to be able to understand it, so i just need the guidelines to start.


I will use priority queues and will read the initial configuration from a text file which looks like for example this:

4  3  6
1  2  5
7  8  

Pointers to other sites for more explanation/tutorials are welcome.

like image 229
Kap Avatar asked Nov 22 '10 23:11

Kap


People also ask

Which algorithm is used in 8-puzzle problem?

Solver for the 8-puzzle problem using the following algorithms: BestFS (using Manhattan's distance as a heuristic function) , DFS and BFS.

What is the A * algorithm?

A * algorithm is a searching algorithm that searches for the shortest path between the initial and the final state. It is used in various applications, such as maps. In maps the A* algorithm is used to calculate the shortest distance between the source (initial state) and the destination (final state).

How do you solve the 8th puzzle with best first search?

Best-first search. First, insert the initial state (the initial board, 0 moves, and a null previous state) into a priority queue. Then, delete from the priority queue the state with the minimum priority, and insert onto the priority queue all neighboring states (those that can be reached in one move).


1 Answers

I'd begin with deciding how you want to represent the game board states, then implement the operators (eg. move (blank) tile up, move (blank) tile down, ...). Typically you will have a data structure to represent the open list (ie. those states discovered but as yet unexplored (ie. compared with goal state) and another for the closed list (ie. those states discovered and explored and found not to be the goal state). You seed the open list with the starting state, and repeatedly take the "next" state to be explored from the open list, apply the operators to it to generate new possible states and so on ...

There is a tutorial I prepared many years ago at:

http://www.cs.rmit.edu.au/AI-Search/

It is far from the definitive word on state space searching though, it is simply an educational tool for those brand new to the concept.

like image 179
Peter G. McDonald Avatar answered Sep 22 '22 14:09

Peter G. McDonald