Add plate class, showin plate on table, predict by plate class
This commit is contained in:
parent
9f44a715cf
commit
35d84146d9
74
main.py
74
main.py
@ -4,6 +4,8 @@ import sys
|
||||
from random import randrange
|
||||
from src.decisionTree import *
|
||||
|
||||
from src.plate import *
|
||||
|
||||
from src.SubprojectMaksymilianKierski.PlateRecognition import use_model_to_predict, text_speech
|
||||
|
||||
# Marcin Dobrowolski
|
||||
@ -27,7 +29,7 @@ if __name__ == "__main__":
|
||||
goal = None
|
||||
path = ''
|
||||
|
||||
#Dominik
|
||||
# Dominik
|
||||
check = 0
|
||||
queue = []
|
||||
|
||||
@ -38,7 +40,17 @@ if __name__ == "__main__":
|
||||
|
||||
# Maksymilian
|
||||
go = 0
|
||||
rand = 0
|
||||
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 = []
|
||||
while True:
|
||||
|
||||
for event in pygame.event.get():
|
||||
@ -55,7 +67,7 @@ if __name__ == "__main__":
|
||||
break
|
||||
|
||||
if event.key == pygame.K_s:
|
||||
tree.TasksList('check', [2,3])
|
||||
tree.TasksList('check', [2, 3])
|
||||
tree.TasksList('eat', [9, 6])
|
||||
tree.TasksList('order', [4, 8])
|
||||
tree.TasksList('goToBar', [11, 4])
|
||||
@ -66,34 +78,53 @@ if __name__ == "__main__":
|
||||
check = 1
|
||||
|
||||
if event.key == pygame.K_m:
|
||||
|
||||
tabPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8],
|
||||
[8, 2], [8, 5], [8, 8], [12, 3], [12, 7]]
|
||||
|
||||
if not [waiter.X, waiter.Y] in tabPos or go == 0:
|
||||
if [waiter.X, waiter.Y] in tabPos:
|
||||
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)
|
||||
print(waiterX)
|
||||
graphics.clear(waiterX, waiter.Y - 1)
|
||||
rand = randrange(9)
|
||||
x = tabPos[rand][0]
|
||||
y = tabPos[rand][1]
|
||||
|
||||
goal = (x, y)
|
||||
# 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:
|
||||
predict = use_model_to_predict('test-{}'.format(rand))
|
||||
|
||||
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:
|
||||
predict = use_model_to_predict(plateArr[randGo].pictureAI)
|
||||
|
||||
if predict == 1:
|
||||
predict = 'EMPTY'
|
||||
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()
|
||||
@ -160,12 +191,13 @@ if __name__ == "__main__":
|
||||
path = path[1:]
|
||||
waiter.travel(nextStep, graphics)
|
||||
if path == '':
|
||||
action = actions.pop(0)
|
||||
if action[0] == 'takeOrder':
|
||||
guest = newGuests.pop(0)
|
||||
waiter.takeOrder(suggestionTreeRoot, guest)
|
||||
graphics.clearGuest(guest)
|
||||
tables.append(guest.cord)
|
||||
print('')
|
||||
# action = actions.pop(0)
|
||||
# if action[0] == 'takeOrder':
|
||||
# guest = newGuests.pop(0)
|
||||
# waiter.takeOrder(suggestionTreeRoot, guest)
|
||||
# graphics.clearGuest(guest)
|
||||
# tables.append(guest.cord)
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick(graphics.fps)
|
||||
|
BIN
resources/images/plate-empty.png
Normal file
BIN
resources/images/plate-empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
resources/images/plate-full.png
Normal file
BIN
resources/images/plate-full.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
Binary file not shown.
@ -26,7 +26,10 @@ class Graphics:
|
||||
'guest_front': pygame.image.load(relative_path + 'guest-front.png'),
|
||||
'guest_back': pygame.image.load(relative_path + 'guest-back.png'),
|
||||
'guest_left': pygame.image.load(relative_path + 'guest-left.png'),
|
||||
'guest_right': pygame.image.load(relative_path + 'guest-right.png')
|
||||
'guest_right': pygame.image.load(relative_path + 'guest-right.png'),
|
||||
#
|
||||
# 'plate-empty': pygame.image.load(relative_path + 'plate-empty.png'),
|
||||
# 'plate-full': pygame.image.load(relative_path + 'plate-full.png')
|
||||
|
||||
}
|
||||
self.fps = 2
|
||||
@ -73,3 +76,16 @@ class Graphics:
|
||||
self.image['chair_front'], (guest.cord[0] * self.block_size, (guest.cord[1] + 1) * self.block_size))
|
||||
self.screen.blit(
|
||||
self.image['chair_back'], (guest.cord[0] * self.block_size, (guest.cord[1] - 1) * self.block_size))
|
||||
|
||||
def drawFullPlate(self, x, y, picture):
|
||||
self.screen.blit(pygame.image.load(relative_path + picture),
|
||||
(x * self.block_size, y * self.block_size))
|
||||
def drawEmptyPlate(self, x, y):
|
||||
self.screen.blit(self.image['table'],
|
||||
(x * self.block_size, y * self.block_size))
|
||||
self.screen.blit(self.image['plate-full'],
|
||||
(x * self.block_size, y * self.block_size))
|
||||
def clearPlate(self, x, y):
|
||||
self.screen.blit(self.image['table'],
|
||||
(x * self.block_size, y * self.block_size))
|
||||
|
||||
|
13
src/plate.py
Normal file
13
src/plate.py
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
class Plate:
|
||||
def __init__(self, graphics, plate, table, picture, pictureAI):
|
||||
self.plate = plate
|
||||
self.table = table
|
||||
self.picture = picture
|
||||
self.pictureAI = pictureAI
|
||||
graphics.drawFullPlate(self.plate[0], self.plate[1], picture)
|
||||
|
||||
|
||||
def changePlate(self):
|
||||
print('keep')
|
||||
|
Loading…
Reference in New Issue
Block a user