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