From 1bdef8cc5655075bfe6b3885f4ad92059361d2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz?= Date: Wed, 14 Apr 2021 14:34:57 +0200 Subject: [PATCH] graphserach v0.6.4 --- .idea/AI_PRO2.iml | 2 +- .idea/misc.xml | 2 +- FindPath.py | 42 ++++++++++++++++++++++++++---------------- main.py | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.idea/AI_PRO2.iml b/.idea/AI_PRO2.iml index 12188ff..8388dbc 100644 --- a/.idea/AI_PRO2.iml +++ b/.idea/AI_PRO2.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 43a1e8a..d56657a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/FindPath.py b/FindPath.py index 6467a9c..510650d 100644 --- a/FindPath.py +++ b/FindPath.py @@ -28,6 +28,7 @@ def whichStateLookingFor(tractor, TillageUnit): searching_field = "toFertilize" return searching_field + def nearestLookingField(board, tractor, TillageUnit): end_horizontal_index = 0 end_vertical_index = 0 @@ -39,8 +40,10 @@ def nearestLookingField(board, tractor, TillageUnit): end_horizontal_index = field.horizontal_index end_vertical_index = field.vertical_index break + return end_horizontal_index, end_vertical_index + def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored): start_horizontal_index = tractor.horizontal_index start_vertical_index = tractor.vertical_index @@ -59,8 +62,8 @@ def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored): if goaltest(elem, end_state): break - #TODO - #return droga ktora musi pokonac traktor + # TODO + # return droga ktora musi pokonac traktor else: explored.append(elem) elem = succ(start_state, end_state, tractor) @@ -68,36 +71,43 @@ def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored): def goaltest(elem, end_state): + print('element: ',elem,' stan koncowy; ', end_state) if elem == end_state: + print("heeee") + return True else: return False + def succ(start_state, end_state, tractor): + print(tractor.horizontal_index, ' ', tractor.vertical_index) + a = input() if start_state[1] < end_state[1]: if tractor.direction == "RIGHT": tractor.drive() + print("przesunalem sie w prawo") else: tractor.direction = "RIGHT" - print("przesunalem sie w prawo") + elif start_state[1] > end_state[1]: if tractor.direction == "LEFT": tractor.drive() + print("przesunalem sie w lewo") else: tractor.direction = "LEFT" - print("przesunalem sie w lewo") - else: - if start_state[0] < end_state[0]: - if tractor.direction == "DOWN": - tractor.drive() - else: - tractor.direction = "DOWN" + + elif start_state[0] < end_state[0]: + if tractor.direction == "DOWN": + tractor.drive() print("przesunalem sie w dol") - elif start_state[0] > end_state[0]: - if tractor.direction == "UP": - tractor.drive() - else: - tractor.direction = "UP" + else: + tractor.direction = "DOWN" + elif start_state[0] > end_state[0]: + if tractor.direction == "UP": + tractor.drive() print("przesunalem sie w gore") else: - return tractor.horizontal_index, tractor.horizontal_index \ No newline at end of file + tractor.direction = "UP" + else: + return tractor.horizontal_index, tractor.horizontal_index \ No newline at end of file diff --git a/main.py b/main.py index 1d4a8f2..069ca00 100644 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ while working: clock.tick(FPS) -graphsearch(tractor, board, TillageUnit, Queue(), list()) + graphsearch(tractor, board, TillageUnit, Queue(), list()) pygame.quit() quit()