From 563b638f0a36721d039abe373916f82e2de23df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Fri, 15 May 2020 19:51:11 +0200 Subject: [PATCH] naprawa poruszania --- .idea/vcs.xml | 6 ++++++ .idea/workspace.xml | 25 +++++++++++++++++++++- __pycache__/functions.cpython-37.pyc | Bin 2995 -> 3005 bytes functions.py | 15 +++++++++++++- main.py | 30 ++++++++++++++++++++------- 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c7dcbe6..95a134d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,12 @@ - + + + + + + + + + + @@ -98,14 +108,27 @@ + + + + + \ No newline at end of file diff --git a/__pycache__/functions.cpython-37.pyc b/__pycache__/functions.cpython-37.pyc index 6677df74e218eabb3ca1bf9a8f5ae43f2a713473..76f91aa33d5dee2c66750a5f5caeafc1f260f76c 100644 GIT binary patch delta 327 zcmdlizE_;jiI#*rD`b~~zGu+(87Qo1u zIQcfaG^4}hHEfcb1vr|RY%GCZEV2a=HXyRv^L>L|6a`P1Yi15L*dE*nkKD5CJkwlc`7?#I~J$gG-(< cck&M|OGf+2M%?afb|7K<$@SdU%+?&d0FPZs%m4rY diff --git a/functions.py b/functions.py index c18a05d..f4c5fb7 100644 --- a/functions.py +++ b/functions.py @@ -67,6 +67,7 @@ def a_star(start_field, goal_field, board): field.g = 0 field.h = 0 field.f = 0 + field.previous = None return path @@ -133,4 +134,16 @@ def change_turn(agent, next_field): agent.turn_right() - +# def execute_step(agent, next_step, board, path): +# if check_turn(agent, next_step): +# agent.move_forward(board) +# if len(path) != 0: +# next_step = path.pop() +# else: +# next_step = None +# for row in board: +# for field in row: +# if not field.is_shelf: +# field.image = pygame.image.load('img/Field.png') +# else: +# change_turn(agent, next_step) diff --git a/main.py b/main.py index fcd7be7..63bd66d 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import time from agent import Agent from settings import Settings from board import create_board, draw_board +from random import randint # Inicjalizacja programu i utworzenie obiektu ekrany @@ -21,9 +22,8 @@ def run(): for field in row: print(field.cost_of_travel) - path = functions.a_star(board[agent.y][agent.x], board[5][7], board) - path.pop(len(path) - 1) - next_step = path.pop(len(path) - 1) + path = [] + next_step = None # Rozpoczęcie głównej pętli programu while True: # functions.check_events(agent, board) @@ -39,18 +39,34 @@ def run(): agent.turn_left() elif event.key == pygame.K_UP: agent.move_forward(board) + print(agent.x, agent.y) + elif event.key == pygame.K_SPACE: + field = board[randint(0, 9)][randint(0, 9)] + if not field.is_shelf: + path = functions.a_star(board[agent.y][agent.x], field, board) + path.pop(len(path) - 1) + next_step = path.pop(len(path) - 1) - if len(path) >= 0: + if next_step is not None: time.sleep(0.5) + if functions.check_turn(agent, next_step): agent.move_forward(board) if len(path) != 0: next_step = path.pop() + else: + next_step = None + print(next_step, path) + for row in board: + for field in row: + if not field.is_shelf: + field.image = pygame.image.load('img/Field.png') + for row in board: + for field in row: + print(field.g, field.h, field.f, field.previous) else: functions.change_turn(agent, next_step) - print(agent.position_x, agent.position_y) - - + print(agent.x, agent.y) draw_board(board) agent.blitme()