This commit is contained in:
barmal4 2021-04-27 22:01:31 +02:00
parent 39717d8860
commit 9b71d67b33

View File

@ -1,4 +1,4 @@
from Constants import ROWS, COLS
from Constants import ROWS, COLS, MOVE
from Engine.BfsPathFinder import BfsPathFinder
from Engine.Node import Node
from Engine.Point import Point
@ -30,18 +30,19 @@ class PathFinder(BfsPathFinder):
return self.constructActions(current, startState)
self.openList.remove(current)
for next in self.getNeighbour(current):
tentativeGScore = self.gScore.get(current) + current.state.getPoint().distance(next.state.getPoint())
tentativeGScore = self.gScore.get(current) + self.weight(next)
if tentativeGScore < self.gScore.get(next, 10000):
self.cameFrom[next] = current
next.parent = current
self.gScore[next] = tentativeGScore
self.fScore[next] = tentativeGScore + next.state.getPoint().distance(startState.getPoint())
self.fScore[next] = tentativeGScore + self.heuristic(startState, next)
if next not in self.openList:
self.openList.append(next)
return []
def heuristic(self,startState,next):
return next.state.getPoint().distance(startState.getPoint())
def minKey(self, fscore, openlist):
minkey = Node
@ -53,6 +54,12 @@ class PathFinder(BfsPathFinder):
minkey = node
return minkey
def weight(self, next):
if next.state.getPoint() in self.board.moodMap and next.action == MOVE:
return 5
return 1