I'm trying to compute the manhattan distance for an 8-puzzle with A*. I realize that I'm doing something wrong with how I compare the current positions with the goal, but I can't figure exactly what I'm doing wrong (I'm pretty new to python). Please help.
def manhattan_distance(self, goal):
dist = 0
x = 0
y = 0
goal = [(0, 0), (1, 0), (2, 0),
(0, 1), (1, 1), (2, 1),
(0, 2), (1, 2), (2, 2)]
for row in range(len(self.board)):
for col in range(len(self.board)):
val = self.board[row][col]
if val != 0:
for x, y in goal:
dist += abs(row - x) + abs(col - y)
return dist
I'm not getting any error message, it just keeps searching through nodes.