From 52872433624bddbe597aabd3a0dbd5564c554e78 Mon Sep 17 00:00:00 2001 From: ddamiankowalski Date: Sun, 3 Apr 2022 22:40:55 +0200 Subject: [PATCH] 04/03/2022 --- board | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/board b/board index 9da2d6e..fc8e52d 100644 --- a/board +++ b/board @@ -1,4 +1,5 @@ from asyncio.windows_events import NULL +from collections import deque from lib2to3.pgen2.token import CIRCUMFLEX from queue import Queue import sys @@ -99,7 +100,7 @@ def startQueue(agentX, agentY, fieldList, gridNum): result = checkGoal(fieldList, gridNum) if result: checkFlag = True - print("NEXT CHECK GOAL") + # print("NEXT CHECK GOAL") return result def checkGoal(fieldList, gridNum): @@ -107,8 +108,8 @@ def checkGoal(fieldList, gridNum): currentY = currentField.yPos currentX = currentField.xPos currentIndex = currentY * gridNum + currentX - print("POPPED!!!") - currentField.printXandY() + # print("POPPED!!!") + # currentField.printXandY() ##print(str(currentField.xPos) + " " + str(objectArray[1].xPos) + " " + str(currentField.yPos) + " " + str(objectArray[1].yPos)) ## SPRAWDZAMY CZY DANE POLE JEST POLEM W KTORYM ZNAJDUJE SIE NASZ CEL @@ -123,29 +124,29 @@ def checkGoal(fieldList, gridNum): if currentIndex + 15 <= 224 and fieldList[currentIndex + 15].visited == False: fieldQueue.append(fieldList[currentIndex + 15]) fieldList[currentIndex + 15].parent = fieldList[currentIndex] - print("APPENDED DOWN!!!") - fieldList[currentIndex + 15].printXandY() + # print("APPENDED DOWN!!!") + # fieldList[currentIndex + 15].printXandY() if currentIndex - 15 > -1 and fieldList[currentIndex - 15].visited == False: fieldQueue.append(fieldList[currentIndex - 15]) fieldList[currentIndex - 15].parent = fieldList[currentIndex] - print("APPENDED UP!!!") - fieldList[currentIndex - 15].printXandY() + # print("APPENDED UP!!!") + # fieldList[currentIndex - 15].printXandY() if (currentIndex + 1) % 15 != 0 and fieldList[currentIndex + 1].visited == False: fieldQueue.append(fieldList[currentIndex + 1]) fieldList[currentIndex + 1].parent = fieldList[currentIndex] - print("APPENDED RIGHT!!!") - fieldList[currentIndex + 1].printXandY() + # print("APPENDED RIGHT!!!") + # fieldList[currentIndex + 1].printXandY() if (currentIndex - 1) % 15 != 14 and not currentIndex - 1 < 0 and fieldList[currentIndex - 1].visited == False: fieldQueue.append(fieldList[currentIndex - 1]) fieldList[currentIndex - 1].parent = fieldList[currentIndex] - print("APPENDED LEFT!!!") - fieldList[currentIndex - 1].printXandY() + # print("APPENDED LEFT!!!") + # fieldList[currentIndex - 1].printXandY() if __name__ == '__main__': pygame.init() #inicjalizacja modułów, na razie niepotrzebna #Tworzymy nowego playera, czy tam agenta - agent = Object("smieciarka", 15, 15) + agent = Object("smieciarka", 5, 6) target = Object("cel", 1, 2) objectArray.append(agent) objectArray.append(target) @@ -161,25 +162,33 @@ if __name__ == '__main__': for y in range(15): for x in range(15): newField = Field(x, y) - newField.printXandY() + # newField.printXandY() fields.append(newField) result = startQueue(objectArray[0].xPos - 1, objectArray[0].yPos - 1, fields, 15) - print("RESULT TARGET IS: ") + print("RED DOT X AND Y POSITION ============================") result.printXandY() - print("RESULT TRUCK IS: ") + print("TRUCK X AND Y POSITION ============================") print("X: " + str(objectArray[0].xPos - 1) + " Y: " + str(objectArray[0].yPos - 1)) result_parent = result.parent - print("CHECKING PARENTS ===========") - ## FINDING THE MAIN PARENT - while input("enter message") != "finish": - result_parent.printXandY() + currentIndex = (objectArray[0].yPos - 1) * 15 + objectArray[0].xPos - 1 + pathToTarget = deque() + pathToTarget.appendleft(result) + + while result_parent.parent != None: + pathToTarget.appendleft(result_parent) result_parent = result_parent.parent + pathToTarget.appendleft(fields[currentIndex]) + + print("PRINTING PATH TO TARGET ============================") + for node in pathToTarget: + node.printXandY() + while 1: c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie