Solving The 8 Puzzle With A* Algorithm

后端 未结 3 1462
忘了有多久
忘了有多久 2021-02-03 11:11

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

相关标签:
3条回答
  • 2021-02-03 11:33

    A* is a lot like Djikstra's algorithm except it includes a heuristic. You might want to read that wiki or read about single-source shortest path algorithms in general.

    A lot of the basic stuff is important but obvious. You'll need to represent the board and create a method for generating the possible next states.

    The base score for any position will obviously be the minimum number of actual moves to arrive at it. For A* to work, you need a heuristic that can help you pick the best option of possible next states. One heuristic might be the number of pieces in the correct position.

    0 讨论(0)
  • 2021-02-03 11:37

    Check http://olympiad.cs.uct.ac.za/presentations/camp1_2004/heuristics.pdf it describes ways of tackling this very problem.

    0 讨论(0)
  • 2021-02-03 11:39

    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.

    0 讨论(0)
提交回复
热议问题