So I am trying to plan a path on a 9x9 grid, so boardSize is 9. The while loop should stop path list has a length of 81 or more so why is it possible that it can get to a length of 3531when the creature is at 7,5 and the goal is at 5,2 and elevations are 0? Is my while loop wrong or do you think it might be elsewhere?
def planPath(self, creature, goal, board):
print("in the path")
path = [board[creature.x][creature.y]]
while goal not in path or len(path) < self.boardSize ** 2:
print("path length")
print(len(path))
nextPossible = {}
for neighbor in path[-1].neighbors:
if type(neighbor) is not Land.Water:
nextPossible[neighbor] = abs(neighbor.location[0] - goal.location[0]) + abs(neighbor.location[1] - goal.location[1]) + abs(neighbor.elevation - goal.elevation)
path.append(min(nextPossible, key=nextPossible.get))
return path