4th part of AStar implementation
This commit is contained in:
parent
0fa109ef35
commit
7a65079aa2
18
main.py
18
main.py
@ -43,15 +43,19 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
goal = (x, y)
|
goal = (x, y)
|
||||||
path = waiter.findPath(goal)
|
path = waiter.findPath(goal)
|
||||||
|
print('goal: {}'.format(goal))
|
||||||
|
|
||||||
if path != []:
|
if path != []:
|
||||||
temp = path.pop(0)
|
print(path)
|
||||||
print(temp)
|
nextStep = path.pop(0)
|
||||||
waiter.travel(temp, graphics)
|
print(nextStep)
|
||||||
|
waiter.travel(nextStep, graphics)
|
||||||
#graphics.clear(waiter.X, waiter.Y)
|
|
||||||
#waiter.update(event, graphics)
|
|
||||||
#graphics.update(waiter.X, waiter.Y)
|
|
||||||
|
|
||||||
|
print('{} {} current position'.format(waiter.X, waiter.Y))
|
||||||
|
'''
|
||||||
|
graphics.clear(waiter.X, waiter.Y)
|
||||||
|
waiter.update(event, graphics)
|
||||||
|
graphics.update(waiter.X, waiter.Y)
|
||||||
|
'''
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(fps)
|
clock.tick(fps)
|
||||||
|
Binary file not shown.
@ -8,8 +8,8 @@ from .tile import Tile
|
|||||||
class Waiter(pygame.sprite.Sprite):
|
class Waiter(pygame.sprite.Sprite):
|
||||||
def __init__(self, graphics):
|
def __init__(self, graphics):
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.X = 0
|
self.X = 7
|
||||||
self.Y = 0
|
self.Y = 7
|
||||||
self.frame = 0
|
self.frame = 0
|
||||||
self.matrix = Matrix(graphics=graphics)
|
self.matrix = Matrix(graphics=graphics)
|
||||||
self.direction = 'E'
|
self.direction = 'E'
|
||||||
@ -63,6 +63,7 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
openList = []
|
openList = []
|
||||||
closedList = []
|
closedList = []
|
||||||
|
|
||||||
|
startNode.parent = None
|
||||||
openList.append(startNode)
|
openList.append(startNode)
|
||||||
|
|
||||||
while len(openList) > 0:
|
while len(openList) > 0:
|
||||||
@ -125,7 +126,7 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
for openNode in openList:
|
for openNode in openList:
|
||||||
if child == openNode and child.startCost > openNode.startCost:
|
if child == openNode and child.startCost > openNode.startCost:
|
||||||
perm = 1
|
perm = 1
|
||||||
continue
|
break
|
||||||
|
|
||||||
if perm == 1:
|
if perm == 1:
|
||||||
perm = 0
|
perm = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user