2020-04-27 21:56:17 +02:00
|
|
|
import secrets
|
2020-05-22 00:32:20 +02:00
|
|
|
import sys
|
2020-04-06 22:10:21 +02:00
|
|
|
|
2020-05-27 09:13:23 +02:00
|
|
|
from random import randrange
|
2020-05-19 18:19:34 +02:00
|
|
|
from src.decisionTree import *
|
2020-05-24 23:29:17 +02:00
|
|
|
|
2020-06-09 14:13:21 +02:00
|
|
|
from src.plate import *
|
|
|
|
|
2020-05-24 23:29:17 +02:00
|
|
|
from src.SubprojectMaksymilianKierski.PlateRecognition import use_model_to_predict, text_speech
|
2020-04-06 22:10:21 +02:00
|
|
|
|
2020-05-27 09:13:23 +02:00
|
|
|
# Marcin Dobrowolski
|
|
|
|
from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import *
|
|
|
|
from src.SubprojectMarcinDobrowolski.utility import generateTestData, generateTestExample
|
2020-06-08 18:05:05 +02:00
|
|
|
from src.guest import *
|
2020-05-27 09:13:23 +02:00
|
|
|
|
2020-04-06 22:10:21 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# SETUP
|
|
|
|
pygame.init()
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
graphics = Graphics()
|
|
|
|
waiter = Waiter(graphics)
|
2020-05-19 18:28:40 +02:00
|
|
|
tree = DecisionTree()
|
2020-04-06 22:10:21 +02:00
|
|
|
|
2020-05-27 09:13:23 +02:00
|
|
|
# Init functions
|
2020-04-06 22:10:21 +02:00
|
|
|
graphics.drawBackground(waiter.matrix)
|
2020-04-29 11:12:18 +02:00
|
|
|
graphics.update(waiter)
|
2020-04-06 22:10:21 +02:00
|
|
|
|
2020-05-27 09:13:23 +02:00
|
|
|
# AStar
|
2020-04-27 21:56:17 +02:00
|
|
|
goal = None
|
2020-04-29 11:12:18 +02:00
|
|
|
path = ''
|
2020-06-09 14:13:21 +02:00
|
|
|
|
|
|
|
# Dominik
|
2020-06-05 14:18:45 +02:00
|
|
|
check = 0
|
|
|
|
queue = []
|
2020-06-09 14:26:23 +02:00
|
|
|
fromBar = 0
|
|
|
|
barNode = (3, 12)
|
|
|
|
node = ()
|
2020-05-24 23:29:17 +02:00
|
|
|
|
2020-05-27 09:13:23 +02:00
|
|
|
# Marcin Dobrowolski
|
|
|
|
suggestionTreeRoot = SuggestionTree.buildTree(trainingData)
|
2020-06-08 18:05:05 +02:00
|
|
|
newGuests = []
|
|
|
|
actions = []
|
2020-05-27 09:13:23 +02:00
|
|
|
|
2020-05-26 15:02:34 +02:00
|
|
|
# Maksymilian
|
2020-05-25 14:59:50 +02:00
|
|
|
go = 0
|
2020-06-09 14:13:21 +02:00
|
|
|
randGo = 0
|
|
|
|
waitPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8],
|
|
|
|
[8, 2], [8, 5], [8, 8], [12, 3], [12, 7]]
|
|
|
|
|
|
|
|
tabPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8],
|
|
|
|
[8, 2], [8, 5], [8, 8], [12, 3], [12, 7]]
|
|
|
|
|
|
|
|
pltPos = [[2, 3], [2, 6], [2, 9], [4, 4], [4, 8],
|
|
|
|
[9, 3], [9, 6], [9, 9], [11, 3], [11, 8]]
|
|
|
|
|
|
|
|
plateArr = []
|
2020-04-06 22:10:21 +02:00
|
|
|
while True:
|
2020-05-13 09:22:12 +02:00
|
|
|
|
2020-04-06 22:10:21 +02:00
|
|
|
for event in pygame.event.get():
|
2020-05-13 09:22:12 +02:00
|
|
|
# rabbit.check(waiter.matrix, waiter.X, waiter.Y)
|
2020-04-06 22:10:21 +02:00
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit()
|
|
|
|
break
|
|
|
|
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_ESCAPE:
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit()
|
|
|
|
break
|
2020-05-22 00:32:20 +02:00
|
|
|
|
2020-05-19 18:19:34 +02:00
|
|
|
if event.key == pygame.K_s:
|
2020-06-09 14:13:21 +02:00
|
|
|
tree.TasksList('check', [2, 3])
|
2020-06-05 14:18:45 +02:00
|
|
|
tree.TasksList('eat', [9, 6])
|
|
|
|
tree.TasksList('order', [4, 8])
|
|
|
|
tree.TasksList('goToBar', [11, 4])
|
|
|
|
tree.TasksList('check', [2, 9])
|
|
|
|
tree.TasksList('eat', [1, 1])
|
|
|
|
queue = tree.ReturnQueueList()
|
2020-05-19 18:19:34 +02:00
|
|
|
tree.print()
|
2020-06-05 14:18:45 +02:00
|
|
|
check = 1
|
2020-04-06 22:10:21 +02:00
|
|
|
|
2020-05-22 00:32:20 +02:00
|
|
|
if event.key == pygame.K_m:
|
2020-06-09 14:13:21 +02:00
|
|
|
if (not [waiter.X, waiter.Y] in waitPos) or go == 0:
|
|
|
|
if [waiter.X, waiter.Y] in waitPos:
|
2020-05-25 14:59:50 +02:00
|
|
|
model = 'waiter_' + waiter.direction
|
2020-05-26 18:36:02 +02:00
|
|
|
for x in range(-1, 2):
|
2020-05-27 09:20:38 +02:00
|
|
|
waiterX = waiter.X + (x * 0.1)
|
2020-05-26 18:36:02 +02:00
|
|
|
graphics.clear(waiterX, waiter.Y - 1)
|
2020-05-26 15:02:34 +02:00
|
|
|
rand = randrange(9)
|
2020-05-22 00:32:20 +02:00
|
|
|
|
2020-06-09 14:13:21 +02:00
|
|
|
# if this plate is exists
|
|
|
|
print('check{}{}{}'.format(plateArr, len(plateArr), 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:
|
2020-05-25 14:59:50 +02:00
|
|
|
|
2020-06-09 14:13:21 +02:00
|
|
|
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
|
2020-05-22 00:32:20 +02:00
|
|
|
else:
|
2020-06-09 14:13:21 +02:00
|
|
|
predict = use_model_to_predict(plateArr[randGo].pictureAI)
|
2020-05-25 14:59:50 +02:00
|
|
|
|
2020-05-24 23:29:17 +02:00
|
|
|
if predict == 1:
|
2020-05-25 14:59:50 +02:00
|
|
|
predict = 'EMPTY'
|
2020-05-24 23:29:17 +02:00
|
|
|
else:
|
2020-05-25 14:59:50 +02:00
|
|
|
predict = 'FOOD'
|
2020-06-09 14:13:21 +02:00
|
|
|
print('sec-3')
|
2020-05-25 14:59:50 +02:00
|
|
|
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
|
2020-05-27 09:13:23 +02:00
|
|
|
|
|
|
|
# Marcin Dobrowolski
|
|
|
|
if event.key == pygame.K_0:
|
2020-06-08 18:05:05 +02:00
|
|
|
newGuests.append(Guest(graphics))
|
2020-05-27 09:13:23 +02:00
|
|
|
|
|
|
|
# Marcin Dobrowolski
|
|
|
|
if event.key == pygame.K_1:
|
2020-06-08 18:05:05 +02:00
|
|
|
guest = newGuests[0]
|
|
|
|
goal = [0, 0]
|
2020-05-27 09:13:23 +02:00
|
|
|
|
2020-06-08 18:05:05 +02:00
|
|
|
if guest.cord[0] == 2 or guest.cord[1] == 9:
|
|
|
|
goal[0] = guest.cord[0] - 1
|
|
|
|
goal[1] = guest.cord[1]
|
|
|
|
else:
|
|
|
|
goal[0] = guest.cord[0] + 1
|
|
|
|
goal[1] = guest.cord[1]
|
2020-05-27 09:13:23 +02:00
|
|
|
|
2020-06-08 18:05:05 +02:00
|
|
|
actions.append(('takeOrder', goal))
|
|
|
|
print(actions)
|
2020-05-27 09:13:23 +02:00
|
|
|
|
|
|
|
# AStar
|
2020-04-27 21:56:17 +02:00
|
|
|
if event.key == pygame.K_r:
|
|
|
|
temp = False
|
|
|
|
while not temp:
|
|
|
|
x = secrets.randbelow(graphics.width)
|
|
|
|
y = secrets.randbelow(graphics.height)
|
2020-05-22 00:32:20 +02:00
|
|
|
print(x, y)
|
2020-04-27 21:56:17 +02:00
|
|
|
|
|
|
|
if waiter.matrix.matrix[x][y].walk_through == 1:
|
|
|
|
temp = True
|
|
|
|
|
|
|
|
goal = (x, y)
|
|
|
|
path = waiter.findPath(goal)
|
2020-04-29 11:12:18 +02:00
|
|
|
path = waiter.translatePath(path)
|
2020-06-09 14:13:21 +02:00
|
|
|
|
2020-06-05 14:18:45 +02:00
|
|
|
# Dominik
|
2020-06-09 14:26:23 +02:00
|
|
|
if path == '' and fromBar == 0 and check == 1:
|
2020-06-05 14:18:45 +02:00
|
|
|
task = queue.pop(0)
|
2020-06-09 14:26:23 +02:00
|
|
|
tree.RemoveTask()
|
|
|
|
node = (task[2][0], task[2][1])
|
|
|
|
if task[0] == "goToBar":
|
|
|
|
path = waiter.findPath(barNode)
|
|
|
|
fromBar = 1
|
|
|
|
else:
|
|
|
|
path = waiter.findPath(node)
|
2020-06-05 14:18:45 +02:00
|
|
|
path = waiter.translatePath(path)
|
2020-06-09 14:26:23 +02:00
|
|
|
if fromBar == 1:
|
|
|
|
check = 0
|
2020-06-05 14:18:45 +02:00
|
|
|
|
2020-06-09 14:26:23 +02:00
|
|
|
if path == '' and fromBar == 1:
|
|
|
|
path = waiter.findPath(node)
|
|
|
|
path = waiter.translatePath(path)
|
|
|
|
fromBar = 0
|
|
|
|
|
|
|
|
|
|
|
|
if path != '':
|
|
|
|
nextStep = path[0]
|
|
|
|
path = path[1:]
|
|
|
|
waiter.travel(nextStep, graphics)
|
|
|
|
|
|
|
|
if len(queue) != 0 and check == 0 and path == '' and fromBar == 0:
|
2020-06-05 14:18:45 +02:00
|
|
|
check = 1
|
2020-04-27 21:56:17 +02:00
|
|
|
|
2020-05-27 09:13:23 +02:00
|
|
|
# AStar
|
2020-06-08 18:05:05 +02:00
|
|
|
if path == '' and actions:
|
|
|
|
print('Goal: {}'.format(actions[0][1]))
|
|
|
|
path = waiter.findPath(actions[0][1])
|
|
|
|
print('Path: {}'.format(path))
|
|
|
|
path = waiter.translatePath(path)
|
|
|
|
print('Translated path: {}'.format(path))
|
|
|
|
|
2020-04-29 11:12:18 +02:00
|
|
|
if path != '':
|
|
|
|
nextStep = path[0]
|
|
|
|
path = path[1:]
|
2020-04-28 18:56:50 +02:00
|
|
|
waiter.travel(nextStep, graphics)
|
2020-06-08 18:05:05 +02:00
|
|
|
if path == '':
|
2020-06-09 14:13:21 +02:00
|
|
|
print('')
|
|
|
|
# action = actions.pop(0)
|
|
|
|
# if action[0] == 'takeOrder':
|
|
|
|
# guest = newGuests.pop(0)
|
|
|
|
# waiter.takeOrder(suggestionTreeRoot, guest)
|
|
|
|
# graphics.clearGuest(guest)
|
|
|
|
# tables.append(guest.cord)
|
2020-04-28 18:56:50 +02:00
|
|
|
|
2020-04-06 22:10:21 +02:00
|
|
|
pygame.display.flip()
|
2020-05-13 09:22:12 +02:00
|
|
|
clock.tick(graphics.fps)
|