Search code examples
algorithmartificial-intelligencea-starn-queens

Using A* algorithm for soving sliding puzzle and N Queens?


I have successfully implemented A* for path finding on a grid on NxM.

I know all the basics of A* and I wanted to know how to implement the same algorithm for the mentioned problems.

Can someone guide me as to what the heuristic function h and the G score is related to in these problems and how to proceed.

-- For example in grid search we add the neighbours to the opened list and then search the lowest F score, and add it to the closed list.

What would be done to follow the same algorithm for solving NQueens and Sliding puzzle?

Thank you :)


Solution

  • You need to define properly your transition function, cost function and heuristic function. Instead of explaining you each example, if you know the basics about A*, you might find useful to take a look of an implementation of the N-Queens problem and the N-Puzzle problem of the Hipster library. If you are not implementing your code in Java don't worry, the code is clear enought to let you know how to do it.

    I hope my answer helps.

    Adrián