.
.
This commit is contained in:
parent
a920f446b5
commit
2dadd020c6
114
board
114
board
@ -56,17 +56,8 @@ def draw(square_num, objectArr, pathToTarget, num):
|
|||||||
|
|
||||||
circleX = objectArr[0].xPos * square + square + square / 2
|
circleX = objectArr[0].xPos * square + square + square / 2
|
||||||
circleY = objectArr[0].yPos * square + square / 2
|
circleY = objectArr[0].yPos * square + square / 2
|
||||||
|
|
||||||
a = (10 + circleX, 5 + circleY)
|
|
||||||
b = (20 + circleX, 5 + circleY)
|
|
||||||
c = (15 + circleX, 20 + circleY)
|
|
||||||
|
|
||||||
|
|
||||||
polygon = pygame.draw.polygon(screen, (0, 0, 255), (b, a, c))
|
|
||||||
print(polygon)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pygame.draw.circle(screen, (0, 0, 255), (circleX + 15, circleY + 15), 8)
|
||||||
|
|
||||||
circleX = objectArray[1].xPos * square + square * 2
|
circleX = objectArray[1].xPos * square + square * 2
|
||||||
circleY = objectArr[1].yPos * square + square
|
circleY = objectArr[1].yPos * square + square
|
||||||
@ -110,7 +101,6 @@ 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")
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -120,9 +110,6 @@ 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!!!")
|
|
||||||
# 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
|
# 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 and currentField.yPos == objectArray[1].yPos:
|
||||||
@ -136,28 +123,19 @@ def checkGoal(fieldList, gridNum):
|
|||||||
if currentIndex + 15 <= 224 and fieldList[currentIndex + 15].visited == False and fieldList[currentIndex + 15].isBlock == False:
|
if currentIndex + 15 <= 224 and fieldList[currentIndex + 15].visited == False and fieldList[currentIndex + 15].isBlock == 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!!!")
|
|
||||||
# fieldList[currentIndex + 15].printXandY()
|
|
||||||
if currentIndex - 15 > -1 and fieldList[currentIndex - 15].visited == False and fieldList[currentIndex - 15].isBlock == False:
|
if currentIndex - 15 > -1 and fieldList[currentIndex - 15].visited == False and fieldList[currentIndex - 15].isBlock == 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!!!")
|
|
||||||
# fieldList[currentIndex - 15].printXandY()
|
|
||||||
if (currentIndex + 1) % 15 != 0 and fieldList[currentIndex + 1].visited == False and fieldList[currentIndex + 1].isBlock == False:
|
if (currentIndex + 1) % 15 != 0 and fieldList[currentIndex + 1].visited == False and fieldList[currentIndex + 1].isBlock == 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!!!")
|
|
||||||
# fieldList[currentIndex + 1].printXandY()
|
|
||||||
if (currentIndex - 1) % 15 != 14 and not currentIndex - 1 < 0 and fieldList[currentIndex - 1].visited == False and fieldList[currentIndex - 1].isBlock == False:
|
if (currentIndex - 1) % 15 != 14 and not currentIndex - 1 < 0 and fieldList[currentIndex - 1].visited == False and fieldList[currentIndex - 1].isBlock == 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!!!")
|
|
||||||
# fieldList[currentIndex - 1].printXandY()
|
|
||||||
|
|
||||||
def generateStartEndPos():
|
def generateStartEndPos():
|
||||||
startX = random.randint(0, 14)
|
startX = random.randint(0, 14)
|
||||||
startY = random.randint(0, 14)
|
startY = random.randint(0, 14)
|
||||||
print(startX)
|
|
||||||
targetX = None
|
targetX = None
|
||||||
targetY = None
|
targetY = None
|
||||||
|
|
||||||
@ -167,23 +145,40 @@ def generateStartEndPos():
|
|||||||
|
|
||||||
return [startX, startY, targetX, targetY]
|
return [startX, startY, targetX, targetY]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def drawFull(index):
|
||||||
|
c = (255, 255, 255)
|
||||||
|
screen.fill(c)
|
||||||
|
|
||||||
|
for node in pathToTarget:
|
||||||
|
if node == pathToTarget[0] or node == pathToTarget[-1]:
|
||||||
|
continue
|
||||||
|
if pathToTarget.index(node) <= index:
|
||||||
|
continue
|
||||||
|
green = (0, 255, 0)
|
||||||
|
pygame.draw.circle(screen, green, ((node.xPos + 1)
|
||||||
|
* 500 / 15 + 30, (node.yPos + 1) * 500 / 15), 5)
|
||||||
|
draw(15, objectArray, pathToTarget, 1)
|
||||||
|
|
||||||
|
for node in fields:
|
||||||
|
if node.isBlock == True:
|
||||||
|
black = (0, 0, 0)
|
||||||
|
pygame.draw.rect(screen, black, pygame.Rect((node.xPos + 1) * 500 / 15 + 30, (node.yPos + 1) * 500 / 15 - 10, 10, 10))
|
||||||
|
|
||||||
|
kb_listen(objectArray, 15)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pygame.init() # inicjalizacja modułów, na razie niepotrzebna
|
pygame.init()
|
||||||
|
|
||||||
width = 600
|
width = 600
|
||||||
height = 530
|
height = 530
|
||||||
screen = pygame.display.set_mode(
|
screen = pygame.display.set_mode(
|
||||||
(width, height)) # ustalanie rozmiarów okna
|
(width, height))
|
||||||
|
|
||||||
# OBLICZANIE RANDOMOWYCH POL START I END
|
|
||||||
[sX, sY, eX, eY] = generateStartEndPos()
|
[sX, sY, eX, eY] = generateStartEndPos()
|
||||||
|
|
||||||
print(sX)
|
|
||||||
print(sY)
|
|
||||||
print(sX)
|
|
||||||
print(eY)
|
|
||||||
|
|
||||||
# GENEROWANIE WSZYSTKICH POL - FIELDS
|
|
||||||
fields = []
|
fields = []
|
||||||
for y in range(15):
|
for y in range(15):
|
||||||
for x in range(15):
|
for x in range(15):
|
||||||
@ -191,14 +186,11 @@ if __name__ == '__main__':
|
|||||||
newField = Field(x, y, True)
|
newField = Field(x, y, True)
|
||||||
else:
|
else:
|
||||||
newField = Field(x, y, False)
|
newField = Field(x, y, False)
|
||||||
# newField.printXandY()
|
|
||||||
fields.append(newField)
|
fields.append(newField)
|
||||||
|
|
||||||
agent = Object("AGENT", sX, sY)
|
agent = Object("AGENT", sX, sY)
|
||||||
target = Object("TARGET", eX, eY)
|
target = Object("TARGET", eX, eY)
|
||||||
|
|
||||||
# if fields[agent.getX - 1 *
|
|
||||||
|
|
||||||
objectArray.append(agent)
|
objectArray.append(agent)
|
||||||
objectArray.append(target)
|
objectArray.append(target)
|
||||||
|
|
||||||
@ -226,25 +218,37 @@ if __name__ == '__main__':
|
|||||||
for node in pathToTarget:
|
for node in pathToTarget:
|
||||||
node.printXandY()
|
node.printXandY()
|
||||||
|
|
||||||
while 1:
|
print("PRINTING ACTIONS TO TAKE TO GET TO THE TARGET ============================")
|
||||||
# tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie
|
for node in pathToTarget:
|
||||||
c = (255, 255, 255)
|
currentNode = node
|
||||||
screen.fill(c)
|
parentNode = node.parent
|
||||||
|
direction = None
|
||||||
|
|
||||||
|
index = pathToTarget.index(node)
|
||||||
|
|
||||||
|
if parentNode == None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if currentNode.xPos != parentNode.xPos:
|
||||||
|
if currentNode.xPos > parentNode.xPos:
|
||||||
|
direction = "E"
|
||||||
|
objectArray[0].xPos = objectArray[0].xPos + 1
|
||||||
|
else:
|
||||||
|
direction = "W"
|
||||||
|
objectArray[0].xPos = objectArray[0].xPos - 1
|
||||||
|
else:
|
||||||
|
if currentNode.yPos > parentNode.yPos:
|
||||||
|
direction = "S"
|
||||||
|
objectArray[0].yPos = objectArray[0].yPos + 1
|
||||||
|
else:
|
||||||
|
direction = "N"
|
||||||
|
objectArray[0].yPos = objectArray[0].yPos - 1
|
||||||
|
time.sleep(1)
|
||||||
|
print("NEXT DIRECTION: " + direction)
|
||||||
|
|
||||||
draw(15, objectArray, pathToTarget, 1)
|
draw(15, objectArray, pathToTarget, 1)
|
||||||
|
pygame.display.update()
|
||||||
|
print(index)
|
||||||
|
drawFull(index)
|
||||||
|
quit()
|
||||||
|
|
||||||
# TUTAJ RYSUJEMY SCIEZKE
|
|
||||||
for node in pathToTarget:
|
|
||||||
if node == pathToTarget[0] or node == pathToTarget[-1]:
|
|
||||||
continue
|
|
||||||
green = (0, 255, 0)
|
|
||||||
pygame.draw.circle(screen, green, ((node.xPos + 1)
|
|
||||||
* 500 / 15 + 30, (node.yPos + 1) * 500 / 15), 5)
|
|
||||||
|
|
||||||
for node in fields:
|
|
||||||
## DRAWING BLOCKS
|
|
||||||
if node.isBlock == True:
|
|
||||||
black = (0, 0, 0)
|
|
||||||
pygame.draw.rect(screen, black, pygame.Rect((node.xPos + 1) * 500 / 15 + 30, (node.yPos + 1) * 500 / 15 - 10, 10, 10))
|
|
||||||
|
|
||||||
kb_listen(objectArray, 15)
|
|
||||||
pygame.display.update() # by krata pojawiła się w okienku - update powierzchni
|
|
||||||
|
Loading…
Reference in New Issue
Block a user