Finish graphSearch method in AutomaticMovement.py
This commit is contained in:
parent
e01dfeb85a
commit
7a79ccc9c2
@ -32,33 +32,50 @@ class AutomaticMovement:
|
|||||||
self.actualTarget = None
|
self.actualTarget = None
|
||||||
|
|
||||||
def a_Star(self):
|
def a_Star(self):
|
||||||
# todo: A*!!!
|
|
||||||
fringe = PriorityQueue()
|
fringe = PriorityQueue()
|
||||||
explored = []
|
explored = []
|
||||||
|
|
||||||
startingPos = (self.player.x, self.player.y, self.player.rotation.value)
|
startingState = (self.player.x, self.player.y, self.player.rotation)
|
||||||
startingPriority = 0
|
startingPriority = 0
|
||||||
|
|
||||||
fringe.put((startingPriority, node(None, None)))
|
fringe.put((startingPriority, AStarNode(None, None, startingState)))
|
||||||
while True:
|
while True:
|
||||||
if fringe.empty():
|
if fringe.empty():
|
||||||
# target is unreachable
|
# target is unreachable
|
||||||
self.movesList = None
|
self.movesList = None
|
||||||
self.nextMove = None
|
self.nextMove = None
|
||||||
|
|
||||||
elem = fringe.get()
|
elem: AStarNode = fringe.get()
|
||||||
|
|
||||||
if self.goalTest():
|
if self.goalTest(elem.state):
|
||||||
# TODO : listaRuchow
|
result = []
|
||||||
return None
|
p = elem.parent
|
||||||
|
while p is not None:
|
||||||
|
result.append((elem.parent, elem.action))
|
||||||
|
return result
|
||||||
|
|
||||||
|
explored.append(elem)
|
||||||
|
|
||||||
self.movesList = fringe
|
for (movement, newState) in self.succesor(elem.state):
|
||||||
self.nextMove = self.fringe[0]
|
newNode = AStarNode(elem, movement, newState)
|
||||||
|
newPriority = self.priority(newNode)
|
||||||
|
|
||||||
|
# Check if state is not in fringe queue ...
|
||||||
def succesor(self):
|
if not any(newNode.state == node[1].state for node in fringe.queue):
|
||||||
movesList = [Movement.ROTATE_L, Movement.ROTATE_R]
|
# ... and is not in explored list
|
||||||
|
if not any(newNode.state == node[1].state for node in explored):
|
||||||
|
fringe.put((newPriority, newNode))
|
||||||
|
# If state is in fringe queue ...
|
||||||
|
else:
|
||||||
|
node: AStarNode
|
||||||
|
for (pr, node) in fringe.queue:
|
||||||
|
# Compare nodes
|
||||||
|
if node.state == newNode.state and node.parent is newNode.parent and node.action == newNode.action:
|
||||||
|
# ... and if it has priority > newPriority
|
||||||
|
if pr > newPriority:
|
||||||
|
# Replace it with new priority
|
||||||
|
fringe.queue.remove((pr, node))
|
||||||
|
fringe.put((newPriority, node))
|
||||||
|
|
||||||
def succesor(self, elemState):
|
def succesor(self, elemState):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user