I'm trying to code a 8-puzzle game solver in C++, but I'm having a lot of problems while doing it. The program is currently working, but it takes too much steps to solve the puzzle. I mean, sometimes it can find the optimal solution, sometimes it takes as much as 400 steps to solve it. My main doubt is the following.. Imagine I have this diagram(this is just a draft):
I'm using Manhattan Distance as the heuristic function. After the first step we have two states where f(n)=5, so I expanded the tree. After expanding I still got two states where f(n)=2. Here is my doubt.. Do I still need to expand the tree till I got a unique lowest f(n)?
Thanks in advance!