1

I am currently trying to learn how to code a sliding tile puzzle with 8 tiles in Python 3. In one of the resources I've found, the person explains the Manhattan distances heuristic, but then goes on to write the piece of code shown below.

By looking at the h() function, it seems to me like it's actually the 'tiles out of place' heuristic rather than the Manhattan one. Am I correct in thinking this?

The complete, raw code can be found here: LINK

Thank you in advance for your time and help.

    def f(self,start,goal):
    """ Heuristic Function to calculate hueristic value f(x) = h(x) + g(x) """
    return self.h(start.data,goal)+start.level

    def h(self,start,goal):
        """ Calculates the different between the given puzzles """
        temp = 0
        for i in range(0,self.n):
            for j in range(0,self.n):
                if start[i][j] != goal[i][j] and start[i][j] != '_':
                    temp += 1
        return temp

0 Answers0