Add plate class, showin plate on table, predict by plate class
This commit is contained in:
parent
9f44a715cf
commit
35d84146d9
84
main.py
84
main.py
@ -4,6 +4,8 @@ import sys
|
|||||||
from random import randrange
|
from random import randrange
|
||||||
from src.decisionTree import *
|
from src.decisionTree import *
|
||||||
|
|
||||||
|
from src.plate import *
|
||||||
|
|
||||||
from src.SubprojectMaksymilianKierski.PlateRecognition import use_model_to_predict, text_speech
|
from src.SubprojectMaksymilianKierski.PlateRecognition import use_model_to_predict, text_speech
|
||||||
|
|
||||||
# Marcin Dobrowolski
|
# Marcin Dobrowolski
|
||||||
@ -26,8 +28,8 @@ if __name__ == "__main__":
|
|||||||
# AStar
|
# AStar
|
||||||
goal = None
|
goal = None
|
||||||
path = ''
|
path = ''
|
||||||
|
|
||||||
#Dominik
|
# Dominik
|
||||||
check = 0
|
check = 0
|
||||||
queue = []
|
queue = []
|
||||||
|
|
||||||
@ -38,7 +40,17 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Maksymilian
|
# Maksymilian
|
||||||
go = 0
|
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:
|
while True:
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@ -55,7 +67,7 @@ if __name__ == "__main__":
|
|||||||
break
|
break
|
||||||
|
|
||||||
if event.key == pygame.K_s:
|
if event.key == pygame.K_s:
|
||||||
tree.TasksList('check', [2,3])
|
tree.TasksList('check', [2, 3])
|
||||||
tree.TasksList('eat', [9, 6])
|
tree.TasksList('eat', [9, 6])
|
||||||
tree.TasksList('order', [4, 8])
|
tree.TasksList('order', [4, 8])
|
||||||
tree.TasksList('goToBar', [11, 4])
|
tree.TasksList('goToBar', [11, 4])
|
||||||
@ -66,34 +78,53 @@ if __name__ == "__main__":
|
|||||||
check = 1
|
check = 1
|
||||||
|
|
||||||
if event.key == pygame.K_m:
|
if event.key == pygame.K_m:
|
||||||
|
if (not [waiter.X, waiter.Y] in waitPos) or go == 0:
|
||||||
tabPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8],
|
if [waiter.X, waiter.Y] in waitPos:
|
||||||
[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:
|
|
||||||
model = 'waiter_' + waiter.direction
|
model = 'waiter_' + waiter.direction
|
||||||
for x in range(-1, 2):
|
for x in range(-1, 2):
|
||||||
waiterX = waiter.X + (x * 0.1)
|
waiterX = waiter.X + (x * 0.1)
|
||||||
print(waiterX)
|
|
||||||
graphics.clear(waiterX, waiter.Y - 1)
|
graphics.clear(waiterX, waiter.Y - 1)
|
||||||
rand = randrange(9)
|
rand = randrange(9)
|
||||||
x = tabPos[rand][0]
|
|
||||||
y = tabPos[rand][1]
|
|
||||||
|
|
||||||
goal = (x, y)
|
# if this plate is exists
|
||||||
path = waiter.findPath(goal)
|
print('check{}{}{}'.format(plateArr, len(plateArr), rand))
|
||||||
path = waiter.translatePath(path)
|
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
|
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:
|
else:
|
||||||
predict = use_model_to_predict('test-{}'.format(rand))
|
predict = use_model_to_predict(plateArr[randGo].pictureAI)
|
||||||
|
|
||||||
if predict == 1:
|
if predict == 1:
|
||||||
predict = 'EMPTY'
|
predict = 'EMPTY'
|
||||||
else:
|
else:
|
||||||
predict = 'FOOD'
|
predict = 'FOOD'
|
||||||
|
print('sec-3')
|
||||||
text_speech('arialnarrow.ttf', 25, predict, (255, 255, 255), (0, 128, 0),
|
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)
|
(waiter.X * 50 + 25), (waiter.Y * 50 - 25), False, False, screen=graphics.screen)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
@ -132,7 +163,7 @@ if __name__ == "__main__":
|
|||||||
goal = (x, y)
|
goal = (x, y)
|
||||||
path = waiter.findPath(goal)
|
path = waiter.findPath(goal)
|
||||||
path = waiter.translatePath(path)
|
path = waiter.translatePath(path)
|
||||||
|
|
||||||
# Dominik
|
# Dominik
|
||||||
if check == 1:
|
if check == 1:
|
||||||
task = queue.pop(0)
|
task = queue.pop(0)
|
||||||
@ -160,12 +191,13 @@ if __name__ == "__main__":
|
|||||||
path = path[1:]
|
path = path[1:]
|
||||||
waiter.travel(nextStep, graphics)
|
waiter.travel(nextStep, graphics)
|
||||||
if path == '':
|
if path == '':
|
||||||
action = actions.pop(0)
|
print('')
|
||||||
if action[0] == 'takeOrder':
|
# action = actions.pop(0)
|
||||||
guest = newGuests.pop(0)
|
# if action[0] == 'takeOrder':
|
||||||
waiter.takeOrder(suggestionTreeRoot, guest)
|
# guest = newGuests.pop(0)
|
||||||
graphics.clearGuest(guest)
|
# waiter.takeOrder(suggestionTreeRoot, guest)
|
||||||
tables.append(guest.cord)
|
# graphics.clearGuest(guest)
|
||||||
|
# tables.append(guest.cord)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(graphics.fps)
|
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_front': pygame.image.load(relative_path + 'guest-front.png'),
|
||||||
'guest_back': pygame.image.load(relative_path + 'guest-back.png'),
|
'guest_back': pygame.image.load(relative_path + 'guest-back.png'),
|
||||||
'guest_left': pygame.image.load(relative_path + 'guest-left.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
|
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.image['chair_front'], (guest.cord[0] * self.block_size, (guest.cord[1] + 1) * self.block_size))
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
self.image['chair_back'], (guest.cord[0] * self.block_size, (guest.cord[1] - 1) * self.block_size))
|
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