문제

I'm trying to write 8-puzzle solver but I couldn't yet: I use Manhattan priority function and I wonder, how to make choice between descendant board arrangements if they have the equal priority values.

For example:

this is initial board arrangement:

           8 1 3
           4   2
           7 6 5

and its descendants board arrangements:

I              

  8 1 3  
  4 6 2                
  7   5  

Manhattan distance + move Number = 10

 II

  8   3   
  4 1 2   
  7 6 5 

Manhattan distance + move Number = 12

III

  8 1 3
  4 2  
  7 6 5  

Manhattan distance + move Number = 10

which board arrangement should program choose? I or III ???

도움이 되었습니까?

해결책

You should sum Manhattan distance for every single number (Manhattan distance to get 1 into place plus Manhattan distance to get 2 into place ... plus Manhattan distance to get 8 into place). If you use some heuristic algorithm (such as A*) you expand first board with lowest sum. If two boards have the same sum value it doesn't matter which one you choose to expand first. States you've visited earlier should be saved as closed somewhere (so you don't get to recurrent cycle) and not considered at all.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top