From 7a65079aa2db8c22cd4514a0f1f5904b48527ad0 Mon Sep 17 00:00:00 2001 From: Marcin Dobrowolski Date: Tue, 28 Apr 2020 18:56:50 +0200 Subject: [PATCH] 4th part of AStar implementation --- main.py | 18 +++++++++++------- src/__pycache__/waiter.cpython-38.pyc | Bin 4471 -> 4486 bytes src/waiter.py | 7 ++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 35c974d..4be355f 100644 --- a/main.py +++ b/main.py @@ -43,15 +43,19 @@ if __name__ == "__main__": goal = (x, y) path = waiter.findPath(goal) + print('goal: {}'.format(goal)) if path != []: - temp = path.pop(0) - print(temp) - waiter.travel(temp, graphics) - - #graphics.clear(waiter.X, waiter.Y) - #waiter.update(event, graphics) - #graphics.update(waiter.X, waiter.Y) + print(path) + nextStep = path.pop(0) + print(nextStep) + waiter.travel(nextStep, graphics) + 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() clock.tick(fps) diff --git a/src/__pycache__/waiter.cpython-38.pyc b/src/__pycache__/waiter.cpython-38.pyc index ddb113712aa9cd57e9727fe2662dd56aaf5fbfdf..5807d509d3ec240e8e6ef524f68031ed42acc7db 100644 GIT binary patch delta 1577 zcmaJ>&5ImG6t7p+-P1i^*>!ixOcJBnTpZafM*IZzAYm~Qg04n%FfPs3WM_INvpa8k z69d&Wm?#Jl2Kp*uZV|l59t8gi!CPNE?@93DL4v+lvpX}JHFndlU%mRh_j|9ZUj4QF z)%ohRN~I|1`TP3A&*qnZs-A%bX~c#X7Yu0i4Uq0@Cwmi47u>7+1wv*`82GIGAaF7J z4L*W$_PqT4a)nH}d%L6KHda~p+O5u3JH|O4ly8T;}Y6qwDFAUO8jw4Bn9Io zzVWr_2Kb#R5WVoLp5#WdnftECuCpi%j z(aZC9p(|*9b!@RHvet=yim!{PsAX4LTtM{J`$^bw@==hE>1xvyp6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>&%P&3$$JZJaH5@&*lpx{-USLUsHg!s{tx9 phCAu7W+PqJ0v3F0qsM~7k1>-kS8v|gj(1zNYqV9ScVZfL{{i@ZJlg;O diff --git a/src/waiter.py b/src/waiter.py index 213e8a9..be879b1 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -8,8 +8,8 @@ from .tile import Tile class Waiter(pygame.sprite.Sprite): def __init__(self, graphics): pygame.sprite.Sprite.__init__(self) - self.X = 0 - self.Y = 0 + self.X = 7 + self.Y = 7 self.frame = 0 self.matrix = Matrix(graphics=graphics) self.direction = 'E' @@ -63,6 +63,7 @@ class Waiter(pygame.sprite.Sprite): openList = [] closedList = [] + startNode.parent = None openList.append(startNode) while len(openList) > 0: @@ -125,7 +126,7 @@ class Waiter(pygame.sprite.Sprite): for openNode in openList: if child == openNode and child.startCost > openNode.startCost: perm = 1 - continue + break if perm == 1: perm = 0