04/03/2022
This commit is contained in:
parent
8f00d5f087
commit
5287243362
47
board
47
board
@ -1,4 +1,5 @@
|
|||||||
from asyncio.windows_events import NULL
|
from asyncio.windows_events import NULL
|
||||||
|
from collections import deque
|
||||||
from lib2to3.pgen2.token import CIRCUMFLEX
|
from lib2to3.pgen2.token import CIRCUMFLEX
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
import sys
|
import sys
|
||||||
@ -99,7 +100,7 @@ def startQueue(agentX, agentY, fieldList, gridNum):
|
|||||||
result = checkGoal(fieldList, gridNum)
|
result = checkGoal(fieldList, gridNum)
|
||||||
if result:
|
if result:
|
||||||
checkFlag = True
|
checkFlag = True
|
||||||
print("NEXT CHECK GOAL")
|
# print("NEXT CHECK GOAL")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def checkGoal(fieldList, gridNum):
|
def checkGoal(fieldList, gridNum):
|
||||||
@ -107,8 +108,8 @@ def checkGoal(fieldList, gridNum):
|
|||||||
currentY = currentField.yPos
|
currentY = currentField.yPos
|
||||||
currentX = currentField.xPos
|
currentX = currentField.xPos
|
||||||
currentIndex = currentY * gridNum + currentX
|
currentIndex = currentY * gridNum + currentX
|
||||||
print("POPPED!!!")
|
# print("POPPED!!!")
|
||||||
currentField.printXandY()
|
# currentField.printXandY()
|
||||||
##print(str(currentField.xPos) + " " + str(objectArray[1].xPos) + " " + str(currentField.yPos) + " " + str(objectArray[1].yPos))
|
##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
|
## 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:
|
if currentIndex + 15 <= 224 and fieldList[currentIndex + 15].visited == False:
|
||||||
fieldQueue.append(fieldList[currentIndex + 15])
|
fieldQueue.append(fieldList[currentIndex + 15])
|
||||||
fieldList[currentIndex + 15].parent = fieldList[currentIndex]
|
fieldList[currentIndex + 15].parent = fieldList[currentIndex]
|
||||||
print("APPENDED DOWN!!!")
|
# print("APPENDED DOWN!!!")
|
||||||
fieldList[currentIndex + 15].printXandY()
|
# fieldList[currentIndex + 15].printXandY()
|
||||||
if currentIndex - 15 > -1 and fieldList[currentIndex - 15].visited == False:
|
if currentIndex - 15 > -1 and fieldList[currentIndex - 15].visited == False:
|
||||||
fieldQueue.append(fieldList[currentIndex - 15])
|
fieldQueue.append(fieldList[currentIndex - 15])
|
||||||
fieldList[currentIndex - 15].parent = fieldList[currentIndex]
|
fieldList[currentIndex - 15].parent = fieldList[currentIndex]
|
||||||
print("APPENDED UP!!!")
|
# print("APPENDED UP!!!")
|
||||||
fieldList[currentIndex - 15].printXandY()
|
# fieldList[currentIndex - 15].printXandY()
|
||||||
if (currentIndex + 1) % 15 != 0 and fieldList[currentIndex + 1].visited == False:
|
if (currentIndex + 1) % 15 != 0 and fieldList[currentIndex + 1].visited == False:
|
||||||
fieldQueue.append(fieldList[currentIndex + 1])
|
fieldQueue.append(fieldList[currentIndex + 1])
|
||||||
fieldList[currentIndex + 1].parent = fieldList[currentIndex]
|
fieldList[currentIndex + 1].parent = fieldList[currentIndex]
|
||||||
print("APPENDED RIGHT!!!")
|
# print("APPENDED RIGHT!!!")
|
||||||
fieldList[currentIndex + 1].printXandY()
|
# fieldList[currentIndex + 1].printXandY()
|
||||||
if (currentIndex - 1) % 15 != 14 and not currentIndex - 1 < 0 and fieldList[currentIndex - 1].visited == False:
|
if (currentIndex - 1) % 15 != 14 and not currentIndex - 1 < 0 and fieldList[currentIndex - 1].visited == False:
|
||||||
fieldQueue.append(fieldList[currentIndex - 1])
|
fieldQueue.append(fieldList[currentIndex - 1])
|
||||||
fieldList[currentIndex - 1].parent = fieldList[currentIndex]
|
fieldList[currentIndex - 1].parent = fieldList[currentIndex]
|
||||||
print("APPENDED LEFT!!!")
|
# print("APPENDED LEFT!!!")
|
||||||
fieldList[currentIndex - 1].printXandY()
|
# fieldList[currentIndex - 1].printXandY()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pygame.init() #inicjalizacja modułów, na razie niepotrzebna
|
pygame.init() #inicjalizacja modułów, na razie niepotrzebna
|
||||||
|
|
||||||
#Tworzymy nowego playera, czy tam agenta
|
#Tworzymy nowego playera, czy tam agenta
|
||||||
agent = Object("smieciarka", 15, 15)
|
agent = Object("smieciarka", 5, 6)
|
||||||
target = Object("cel", 1, 2)
|
target = Object("cel", 1, 2)
|
||||||
objectArray.append(agent)
|
objectArray.append(agent)
|
||||||
objectArray.append(target)
|
objectArray.append(target)
|
||||||
@ -161,25 +162,33 @@ if __name__ == '__main__':
|
|||||||
for y in range(15):
|
for y in range(15):
|
||||||
for x in range(15):
|
for x in range(15):
|
||||||
newField = Field(x, y)
|
newField = Field(x, y)
|
||||||
newField.printXandY()
|
# newField.printXandY()
|
||||||
fields.append(newField)
|
fields.append(newField)
|
||||||
|
|
||||||
result = startQueue(objectArray[0].xPos - 1, objectArray[0].yPos - 1, fields, 15)
|
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()
|
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))
|
print("X: " + str(objectArray[0].xPos - 1) + " Y: " + str(objectArray[0].yPos - 1))
|
||||||
|
|
||||||
|
|
||||||
result_parent = result.parent
|
result_parent = result.parent
|
||||||
|
|
||||||
print("CHECKING PARENTS ===========")
|
currentIndex = (objectArray[0].yPos - 1) * 15 + objectArray[0].xPos - 1
|
||||||
## FINDING THE MAIN PARENT
|
pathToTarget = deque()
|
||||||
while input("enter message") != "finish":
|
pathToTarget.appendleft(result)
|
||||||
result_parent.printXandY()
|
|
||||||
|
while result_parent.parent != None:
|
||||||
|
pathToTarget.appendleft(result_parent)
|
||||||
result_parent = result_parent.parent
|
result_parent = result_parent.parent
|
||||||
|
pathToTarget.appendleft(fields[currentIndex])
|
||||||
|
|
||||||
|
print("PRINTING PATH TO TARGET ============================")
|
||||||
|
for node in pathToTarget:
|
||||||
|
node.printXandY()
|
||||||
|
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie
|
c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie
|
||||||
|
Loading…
Reference in New Issue
Block a user