8-puzzle

What can be the efficient approach to solve the 8 puzzle problem?

只愿长相守 提交于 2019-12-03 04:43:53
问题 The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the game is to begin with an arbitrary configuration of tiles, and move them so as to get the numbered tiles arranged in ascending order either running around the perimeter of the board or ordered from

Manhattan distance in A*

…衆ロ難τιáo~ 提交于 2019-11-30 20:10:06
I am implementing a NxN puzzle solver using A* search algorithm and using Manhattan distance as a heuristic and I've run into a curious bug (?) which I can't wrap my head around. Consider these puzzles (0 element being blank space): (initial) 1 0 2 7 5 4 8 6 3 (goal) 1 2 3 4 5 6 7 8 0 The minumum number of moves to reach solution from initial state is 11. However, my solver, reaches goal in 17 moves. And therein lies the problem - my puzzle solver mostly solves the solvable puzzles in a correct (minimum) number of moves but for this particular puzzle, my solver overshoots the minimum number of

8-puzzle has a solution in prolog using manhattan distance

不羁岁月 提交于 2019-11-27 15:25:03
问题 The 8-puzzle will be represented by a 3x3 list of lists positions where the empty box will be represented by the value 9, as shown below: [[9,1,3],[5,2,6],[4,7,8]] Possibility Solution: Only half of the initial positions of the 8-puzzle are solvable. There is a formula that allows to know from the beginning if you can solve the puzzle.To determine whether an 8-puzzle is solvable, for each square containing a value N is calculated how many numbers less than N there after the current cell. For