ZNAJDUJE TARGET
This commit is contained in:
parent
7622e735a7
commit
8926837419
60
board
60
board
@ -82,9 +82,6 @@ def kb_listen(objectArray, gridLength):
|
|||||||
print(objectArray[0].yPos)
|
print(objectArray[0].yPos)
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def validField():
|
|
||||||
print("sda")
|
|
||||||
|
|
||||||
fieldQueue = []
|
fieldQueue = []
|
||||||
isGoalAchieved = False
|
isGoalAchieved = False
|
||||||
@ -95,19 +92,28 @@ def startQueue(agentX, agentY, fieldList, gridNum):
|
|||||||
currentIndex = currentY * gridNum + currentX
|
currentIndex = currentY * gridNum + currentX
|
||||||
|
|
||||||
fieldQueue.append(fieldList[currentIndex])
|
fieldQueue.append(fieldList[currentIndex])
|
||||||
|
|
||||||
|
checkFlag = False
|
||||||
|
|
||||||
while not checkGoal(currentIndex, fieldList, currentIndex):
|
while not checkFlag:
|
||||||
print("")
|
result = checkGoal(fieldList, gridNum)
|
||||||
|
if result:
|
||||||
|
checkFlag = True
|
||||||
|
print("NEXT CHECK GOAL")
|
||||||
|
return result
|
||||||
|
|
||||||
def checkGoal(index, fieldList, currentIndex):
|
def checkGoal(fieldList, gridNum):
|
||||||
currentField = fieldQueue.pop(0)
|
currentField = fieldQueue.pop(0)
|
||||||
|
currentY = currentField.yPos
|
||||||
|
currentX = currentField.xPos
|
||||||
|
currentIndex = currentY * gridNum + currentX
|
||||||
print("POPPED!!!")
|
print("POPPED!!!")
|
||||||
print(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
|
||||||
if currentField.xPos == objectArray[1].xPos and currentField.yPos == objectArray[1].yPos:
|
if currentField.xPos == objectArray[1].xPos - 1 and currentField.yPos == objectArray[1].yPos - 1:
|
||||||
return True
|
return currentField
|
||||||
|
|
||||||
## SPRAWDZAMY CZY DANE POLE ZOSTALO JUZ WCZESNIEJ ODWIEDZONE - JEZELI NIE TO USTAWIAMY STATUS
|
## SPRAWDZAMY CZY DANE POLE ZOSTALO JUZ WCZESNIEJ ODWIEDZONE - JEZELI NIE TO USTAWIAMY STATUS
|
||||||
if not currentField.visited:
|
if not currentField.visited:
|
||||||
@ -117,35 +123,30 @@ def checkGoal(index, fieldList, currentIndex):
|
|||||||
if currentIndex + 15 <= 224:
|
if currentIndex + 15 <= 224:
|
||||||
fieldQueue.append(fieldList[currentIndex + 15])
|
fieldQueue.append(fieldList[currentIndex + 15])
|
||||||
fieldList[currentIndex + 15].parent = fieldList[currentIndex]
|
fieldList[currentIndex + 15].parent = fieldList[currentIndex]
|
||||||
print("APPENDED!!!")
|
print("APPENDED DOWN!!!")
|
||||||
print(fieldList[currentIndex + 15].printXandY())
|
fieldList[currentIndex + 15].printXandY()
|
||||||
if currentIndex - 15 >= 0:
|
if currentIndex - 15 > -1:
|
||||||
fieldQueue.append(fieldList[currentIndex - 15])
|
fieldQueue.append(fieldList[currentIndex - 15])
|
||||||
fieldList[currentIndex - 15].parent = fieldList[currentIndex]
|
fieldList[currentIndex - 15].parent = fieldList[currentIndex]
|
||||||
print("APPENDED!!!")
|
print("APPENDED UP!!!")
|
||||||
print(fieldList[currentIndex + 15].printXandY())
|
fieldList[currentIndex - 15].printXandY()
|
||||||
if (currentIndex + 1) % 15 != 0:
|
if (currentIndex + 1) % 15 != 0:
|
||||||
fieldQueue.append(fieldList[currentIndex + 1])
|
fieldQueue.append(fieldList[currentIndex + 1])
|
||||||
fieldList[currentIndex + 1].parent = fieldList[currentIndex]
|
fieldList[currentIndex + 1].parent = fieldList[currentIndex]
|
||||||
print("APPENDED!!!")
|
print("APPENDED RIGHT!!!")
|
||||||
print(fieldList[currentIndex + 15].printXandY())
|
fieldList[currentIndex + 1].printXandY()
|
||||||
if (currentIndex - 1) % 15 != 14 or currentIndex - 1 >= 0:
|
if (currentIndex - 1) % 15 != 14 or not currentIndex - 1 < 0:
|
||||||
fieldQueue.append(fieldList[currentIndex - 1])
|
fieldQueue.append(fieldList[currentIndex - 1])
|
||||||
fieldList[currentIndex - 1].parent = fieldList[currentIndex]
|
fieldList[currentIndex - 1].parent = fieldList[currentIndex]
|
||||||
print("APPENDED!!!")
|
print("APPENDED LEFT!!!")
|
||||||
print(fieldList[currentIndex + 15].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", 1, 1)
|
agent = Object("smieciarka", 5, 5)
|
||||||
target = Object("cel", 10, 10)
|
target = Object("cel", 1, 1)
|
||||||
objectArray.append(agent)
|
objectArray.append(agent)
|
||||||
objectArray.append(target)
|
objectArray.append(target)
|
||||||
|
|
||||||
@ -162,8 +163,11 @@ if __name__ == '__main__':
|
|||||||
newField = Field(x, y)
|
newField = Field(x, y)
|
||||||
newField.printXandY()
|
newField.printXandY()
|
||||||
fields.append(newField)
|
fields.append(newField)
|
||||||
|
|
||||||
startQueue(objectArray[0].xPos, objectArray[0].yPos, fields, 15)
|
result = startQueue(objectArray[0].xPos, objectArray[0].yPos, fields, 15)
|
||||||
|
|
||||||
|
print("RESULT IS: ")
|
||||||
|
result.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