from Constants import ROWS, COLS from Engine.BfsPathFinder import BfsPathFinder from Engine.Node import Node from Engine.Point import Point from queue import PriorityQueue class PathFinder(BfsPathFinder): def __init__(self, board): super().__init__(board) self.board = board self.openList = [] self.cameFrom = {} self.gScore = {} self.fScore = {} def findBomb(self, startState): x = Node(startState, None) self.openList.append(x) self.gScore[x] = 0 self.fScore[x] = 0 cameFrom = dict() cameFrom[x] = None while not self.openList: current = self.minKey(self.fScore, self.openList) if self.checkGoal(current): return self.constructActions(current, startState) for next in self.getNeighbour(current): tentativeGScore = self.gScore.get(self.current) + current.state.getPoint().distance(next.state.getPoint()) if tentativeGScore < self.gScore.get(next, 10000): cameFrom[next] = current next.parent = current self.gScore[next] = tentativeGScore self.fScore[next] = next.state.getPoint().distance(startState.getPoint()) if next not in self.openList: self.openList.append(next) return [] def minKey(self, fscore, openlist): minkey = Node minValue = float('inf') for node in openlist: value = fscore.get(node, 10000) if value < minValue: minValue = value minkey = node return minkey