add plate to table

This commit is contained in:
s450026 2020-06-09 18:35:00 +02:00
parent 2f76d70270
commit 575a2def45

147
main.py
View File

@ -34,6 +34,7 @@ if __name__ == "__main__":
fromBar = 0 fromBar = 0
barNode = (3, 12) barNode = (3, 12)
node = () node = ()
goalList = [0, 0]
# Marcin Dobrowolski # Marcin Dobrowolski
suggestionTreeRoot = SuggestionTree.buildTree(trainingData) suggestionTreeRoot = SuggestionTree.buildTree(trainingData)
@ -43,6 +44,7 @@ if __name__ == "__main__":
# Maksymilian # Maksymilian
go = 0 go = 0
randGo = 0 randGo = 0
plate = 0
waitPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8], waitPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8],
[8, 2], [8, 5], [8, 8], [12, 3], [12, 7]] [8, 2], [8, 5], [8, 8], [12, 3], [12, 7]]
@ -50,7 +52,7 @@ if __name__ == "__main__":
[8, 2], [8, 5], [8, 8], [12, 3], [12, 7]] [8, 2], [8, 5], [8, 8], [12, 3], [12, 7]]
pltPos = [[2, 3], [2, 6], [2, 9], [4, 4], [4, 8], pltPos = [[2, 3], [2, 6], [2, 9], [4, 4], [4, 8],
[9, 3], [9, 6], [9, 9], [11, 3], [11, 8]] [9, 3], [9, 6], [9, 9], [11, 4], [11, 8]]
plateArr = [] plateArr = []
@ -108,75 +110,6 @@ if __name__ == "__main__":
queue = tree.ReturnQueueList() queue = tree.ReturnQueueList()
tree.print() tree.print()
if event.key == pygame.K_m:
if (not [waiter.X, waiter.Y] in waitPos) or go == 0:
if [waiter.X, waiter.Y] in waitPos:
model = 'waiter_' + waiter.direction
for x in range(-1, 2):
waiterX = waiter.X + (x * 0.1)
graphics.clear(waiterX, waiter.Y - 1)
rand = randrange(9)
# if this plate is exists
print(rand)
if plateArr and len(plateArr) >= rand and plateArr[rand] in plateArr:
randGo = rand
goal = (plateArr[randGo].table[0], plateArr[randGo].table[1])
path = waiter.findPath(goal)
path = waiter.translatePath(path)
print('sec-1')
go = 1
# if this plate is not exists
else:
randTable = random.choice(tabPos)
randIndex = tabPos.index(randTable)
tableCord = tabPos[randIndex]
plateCord = pltPos[randIndex]
print('rand{}'.format(randIndex))
pictureAI = 'test-{}'.format(randIndex)
plateArr.append(Plate(graphics, plateCord, tableCord, 'plate-full.png', pictureAI))
tabPos.pop(randIndex)
pltPos.pop(randIndex)
print(plateArr, pltPos)
goal = (plateArr[len(plateArr) - 1].table[0], plateArr[len(plateArr) - 1].table[1])
randGo = len(plateArr) - 1
path = waiter.findPath(goal)
path = waiter.translatePath(path)
print('sec-2')
go = 1
else:
if plateArr[randGo].checked:
predict = 'CHECKED'
else:
predict = use_model_to_predict(plateArr[randGo].pictureAI)
if predict == 1:
predict = 'EMPTY'
plateArr[randGo].checkPlate()
else:
predict = 'FOOD'
print('sec-3')
text_speech('arialnarrow.ttf', 25, predict, (255, 255, 255), (0, 128, 0),
(waiter.X * 50 + 25), (waiter.Y * 50 - 25), False, False, screen=graphics.screen)
pygame.display.flip()
go = 0
if event.key == pygame.K_a:
newGuests.append(Guest(graphics))
guest = newGuests[len(newGuests) - 1]
goal = [0, 0]
goal[0] = guest.cord[0]
goal[1] = guest.cord[1]
tree.TasksList('order', goal, [waiter.X, waiter.Y])
tree.TasksList('goToBar', goal, [waiter.X, waiter.Y])
queue = tree.ReturnQueueList()
# Marcin Dobrowolski # Marcin Dobrowolski
if event.key == pygame.K_0: if event.key == pygame.K_0:
newGuests.append(Guest(graphics)) newGuests.append(Guest(graphics))
@ -211,6 +144,78 @@ if __name__ == "__main__":
path = waiter.findPath(goal) path = waiter.findPath(goal)
path = waiter.translatePath(path) path = waiter.translatePath(path)
if event.key == pygame.K_a:
if path == '':
newGuests.append(Guest(graphics))
guest = newGuests[len(newGuests) - 1]
goalList[0] = guest.cord[0]
goalList[1] = guest.cord[1]
tree.TasksList('order', goalList, [waiter.X, waiter.Y])
tree.TasksList('goToBar', goalList, [waiter.X, waiter.Y])
queue = tree.ReturnQueueList()
if plate == 1 and (goalList == [waiter.X-1, waiter.Y] or goalList == [waiter.X+1, waiter.Y]):
if (not [waiter.X, waiter.Y] in waitPos) or go == 0:
if [waiter.X, waiter.Y] in waitPos:
model = 'waiter_' + waiter.direction
for x in range(-1, 2):
waiterX = waiter.X + (x * 0.1)
graphics.clear(waiterX, waiter.Y - 1)
rand = randrange(9)
# if this plate is exists
print(rand)
if plateArr and len(plateArr) > rand and plateArr[rand] in plateArr:
randGo = rand
goal = (plateArr[randGo].table[0], plateArr[randGo].table[1])
path = waiter.findPath(goal)
path = waiter.translatePath(path)
print('sec-1')
go = 1
plate = 0
# if this plate is not exists
else:
randTable = goalList
randIndex = pltPos.index(goalList)
tableCord = tabPos[randIndex]
plateCord = pltPos[randIndex]
print('rand{}'.format(randIndex))
pictureAI = 'test-{}'.format(randIndex)
plateArr.append(Plate(graphics, plateCord, tableCord, 'plate-full.png', pictureAI))
tabPos.pop(randIndex)
pltPos.pop(randIndex)
print(plateArr, pltPos)
goal = (plateArr[len(plateArr) - 1].table[0], plateArr[len(plateArr) - 1].table[1])
randGo = len(plateArr) - 1
path = waiter.findPath(goal)
path = waiter.translatePath(path)
print('sec-2')
go = 1
plate = 0
else:
if plateArr[randGo].checked:
predict = 'CHECKED'
else:
predict = use_model_to_predict(plateArr[randGo].pictureAI)
if predict == 1:
predict = 'EMPTY'
plateArr[randGo].checkPlate()
else:
predict = 'FOOD'
print('sec-3')
text_speech('arialnarrow.ttf', 25, predict, (255, 255, 255), (0, 128, 0),
(waiter.X * 50 + 25), (waiter.Y * 50 - 25), False, False, screen=graphics.screen)
pygame.display.flip()
go = 0
plate = 0
# Dominik # Dominik
if queue and path == '' and fromBar == 0: if queue and path == '' and fromBar == 0:
print(queue) print(queue)
@ -221,6 +226,7 @@ if __name__ == "__main__":
if task[0] == "goToBar": if task[0] == "goToBar":
path = waiter.findPath(barNode) path = waiter.findPath(barNode)
fromBar = 1 fromBar = 1
else: else:
path = waiter.findPath(node) path = waiter.findPath(node)
path = waiter.translatePath(path) path = waiter.translatePath(path)
@ -229,6 +235,7 @@ if __name__ == "__main__":
path = waiter.findPath(node) path = waiter.findPath(node)
path = waiter.translatePath(path) path = waiter.translatePath(path)
fromBar = 0 fromBar = 0
plate = 1
# AStar # AStar
if path == '' and actions: if path == '' and actions: