2020-03-22 02:01:57 +01:00
|
|
|
import pygame
|
2020-04-20 23:19:13 +02:00
|
|
|
from kelner.src.components.GridBoard import GridBoard
|
|
|
|
from kelner.src.components.Waiter import Waiter
|
|
|
|
from kelner.src.components.Table import Table
|
2020-05-11 20:42:17 +02:00
|
|
|
from kelner.src.components.Kitchen import Kitchen
|
2020-04-20 23:19:13 +02:00
|
|
|
from kelner.src.managers.DrawableCollection import DrawableCollection
|
|
|
|
from kelner.src.managers.MenuManager import MenuManager
|
|
|
|
from kelner.src.managers.TableManager import TableManager
|
|
|
|
from kelner.src.managers.WaiterManager import WaiterManager
|
2020-05-10 00:04:33 +02:00
|
|
|
from kelner.src.algorithms.DecisionTree import Tree_Builder
|
2020-05-14 23:22:30 +02:00
|
|
|
from kelner.src.managers.KitchenManager import KitchenManager
|
2020-05-16 12:08:02 +02:00
|
|
|
from kelner.src.algorithms.CNN.PrepareData import LoadModelThread
|
|
|
|
import kelner.src.settings as settings
|
|
|
|
import time
|
2020-05-07 18:36:20 +02:00
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# create screen consts
|
2020-05-13 01:59:34 +02:00
|
|
|
Scale = 2 # scale for all images used within project
|
|
|
|
CellSize = round(50 * Scale) # pixel size of 1 square cell in the grid
|
|
|
|
PaintOffset = CellSize # pixel size of paint offset for all drawables
|
|
|
|
GridCountX = 15 # number of columns in grid
|
|
|
|
GridCountY = 9 # number of rows in grid
|
|
|
|
ScreenWidth = CellSize * GridCountX + 2 * PaintOffset # screen width in pixels
|
2020-04-20 23:19:13 +02:00
|
|
|
ScreenHeight = CellSize * GridCountY + 2 * PaintOffset # screen height in pixels
|
2020-05-16 12:08:02 +02:00
|
|
|
running_tasks = {'table': [], 'waiter': []}
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# initialize background
|
|
|
|
gridBoard = GridBoard(ScreenWidth, ScreenHeight)
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-05-16 12:08:02 +02:00
|
|
|
# start loading prediction model
|
|
|
|
settings.init()
|
|
|
|
load_model_thread = LoadModelThread()
|
|
|
|
|
|
|
|
load_model_thread.start()
|
|
|
|
# joining this thread to main thread. Man thread will be started after this finish
|
|
|
|
load_model_thread.join()
|
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# initialize drawable objects manager
|
2020-04-03 23:54:29 +02:00
|
|
|
drawableManager = DrawableCollection()
|
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# initialize menu manager
|
2020-04-05 17:27:11 +02:00
|
|
|
menuManager = MenuManager()
|
|
|
|
|
2020-05-10 00:04:33 +02:00
|
|
|
##TESTING THE DECISION TREE
|
2020-05-13 01:59:34 +02:00
|
|
|
# Testing Data
|
2020-05-10 00:04:33 +02:00
|
|
|
testing_db = [
|
|
|
|
[1, 0, 0, 0, "Kurczak"],
|
|
|
|
[0, 1, 0, 0, "Piwo"],
|
|
|
|
[0, 0, 1, 0, "Pizza"],
|
|
|
|
[0, 0, 0, 1, "Salad"],
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2020-05-13 01:59:34 +02:00
|
|
|
# Building a decision tree
|
2020-05-10 00:04:33 +02:00
|
|
|
Test_Tree = Tree_Builder.build_tree(testing_db)
|
|
|
|
|
2020-05-13 01:59:34 +02:00
|
|
|
# Testing the tree
|
2020-05-10 00:04:33 +02:00
|
|
|
if Tree_Builder.zgadnij(testing_db[0], Test_Tree) == "Kurczak":
|
|
|
|
print("test1: passed")
|
|
|
|
else:
|
|
|
|
print("test1: fail")
|
|
|
|
|
|
|
|
if Tree_Builder.zgadnij(testing_db[1], Test_Tree) == "Piwo":
|
|
|
|
print("test2: passed")
|
|
|
|
else:
|
|
|
|
print("test2: fail")
|
|
|
|
|
|
|
|
if Tree_Builder.zgadnij(testing_db[2], Test_Tree) == "Pizza":
|
|
|
|
print("test3: passed")
|
|
|
|
else:
|
|
|
|
print("test3: fail")
|
|
|
|
|
|
|
|
if Tree_Builder.zgadnij(testing_db[3], Test_Tree) == "Salad":
|
|
|
|
print("test4: passed")
|
|
|
|
else:
|
|
|
|
print("test4: fail")
|
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# initialize waiter component
|
2020-04-27 12:22:19 +02:00
|
|
|
waiter1 = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
2020-05-11 20:42:17 +02:00
|
|
|
# waiter2 = Waiter(0, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
|
|
|
# waiter3 = Waiter(GridCountX - 1, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
|
|
|
# waiter4 = Waiter(GridCountX - 1, GridCountY - 1, 0, GridCountX - 1, 0, GridCountY - 1, CellSize, PaintOffset)
|
2020-04-03 23:54:29 +02:00
|
|
|
|
2020-05-07 18:36:20 +02:00
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# adds waiter to drawable collection
|
2020-04-27 12:22:19 +02:00
|
|
|
drawableManager.add(waiter1)
|
2020-05-11 20:42:17 +02:00
|
|
|
# drawableManager.add(waiter2)
|
|
|
|
# drawableManager.add(waiter3)
|
|
|
|
# drawableManager.add(waiter4)
|
|
|
|
|
|
|
|
|
2020-05-13 01:59:34 +02:00
|
|
|
kitchen = Kitchen(5, GridCountX - 5, 5, GridCountY - 5, CellSize, PaintOffset)
|
2020-05-12 10:52:56 +02:00
|
|
|
drawableManager.add(kitchen)
|
2020-05-14 23:22:30 +02:00
|
|
|
kitchenManager = KitchenManager(drawableManager, gridBoard)
|
|
|
|
|
2020-05-13 01:59:34 +02:00
|
|
|
# My comment
|
2020-04-20 23:19:13 +02:00
|
|
|
# initialize a number of tables given in range
|
2020-05-03 01:19:34 +02:00
|
|
|
for i in range(0, 40):
|
|
|
|
table = Table(1, GridCountX - 2, 1, GridCountY - 2, CellSize, PaintOffset)
|
2020-04-27 12:22:19 +02:00
|
|
|
if drawableManager.generatePosition(table):
|
|
|
|
drawableManager.add(table)
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# new thread controlling tables
|
|
|
|
tableTask = TableManager(drawableManager, menuManager)
|
|
|
|
tableTask.start()
|
2020-05-16 12:08:02 +02:00
|
|
|
running_tasks['table'].append(tableTask)
|
2020-04-05 17:27:11 +02:00
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# new thread controlling waiter
|
2020-05-16 12:08:02 +02:00
|
|
|
waiter1Task = WaiterManager(drawableManager, [waiter1], kitchenManager, menuManager, tableTask)
|
2020-04-27 12:22:19 +02:00
|
|
|
waiter1Task.start()
|
2020-05-16 12:08:02 +02:00
|
|
|
running_tasks['waiter'].append(tableTask)
|
2020-04-27 12:22:19 +02:00
|
|
|
|
2020-05-11 20:42:17 +02:00
|
|
|
# waiter2Task = WaiterManager(drawableManager, [waiter2])
|
|
|
|
# waiter2Task.start()
|
|
|
|
#
|
|
|
|
# waiter3Task = WaiterManager(drawableManager, [waiter3])
|
|
|
|
# waiter3Task.start()
|
|
|
|
#
|
|
|
|
# waiter4Task = WaiterManager(drawableManager, [waiter4])
|
|
|
|
# waiter4Task.start()
|
2020-04-05 17:27:11 +02:00
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# main loop
|
2020-03-22 02:01:57 +01:00
|
|
|
running = True
|
|
|
|
while running:
|
|
|
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
2020-04-20 23:19:13 +02:00
|
|
|
tableTask.stop()
|
2020-04-27 12:22:19 +02:00
|
|
|
waiter1Task.stop()
|
2020-05-11 20:42:17 +02:00
|
|
|
# waiter2Task.stop()
|
|
|
|
# waiter3Task.stop()
|
|
|
|
# waiter4Task.stop()
|
2020-03-22 02:01:57 +01:00
|
|
|
running = False
|
|
|
|
|
2020-04-20 23:19:13 +02:00
|
|
|
# handles keyboard events
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
2020-04-20 23:19:13 +02:00
|
|
|
# checks if new waiter's position to the left is not occupied by other object
|
2020-04-27 12:22:19 +02:00
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX() - 1, waiter1.getY()):
|
|
|
|
waiter1.moveLeft()
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.key == pygame.K_RIGHT:
|
2020-04-03 23:54:29 +02:00
|
|
|
# checks if new waiter's position to the right is not occupied by other object
|
2020-04-27 12:22:19 +02:00
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX() + 1, waiter1.getY()):
|
|
|
|
waiter1.moveRight()
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.key == pygame.K_UP:
|
2020-04-03 23:54:29 +02:00
|
|
|
# checks if new waiter's position up is not occupied by other object
|
2020-04-27 12:22:19 +02:00
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX(), waiter1.getY() - 1):
|
|
|
|
waiter1.moveUp()
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.key == pygame.K_DOWN:
|
2020-04-03 23:54:29 +02:00
|
|
|
# checks if new waiter's position down is not occupied by other object
|
2020-04-27 12:22:19 +02:00
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX(), waiter1.getY() + 1):
|
|
|
|
waiter1.moveDown()
|
|
|
|
|
|
|
|
if event.key == pygame.K_w:
|
|
|
|
# checks if new waiter's position to the left is not occupied by other object
|
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX() - 1, waiter1.getY() - 1):
|
|
|
|
waiter1.moveLeft()
|
|
|
|
waiter1.moveUp()
|
|
|
|
if event.key == pygame.K_d:
|
|
|
|
# checks if new waiter's position to the right is not occupied by other object
|
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX() + 1, waiter1.getY() - 1):
|
|
|
|
waiter1.moveRight()
|
|
|
|
waiter1.moveUp()
|
|
|
|
if event.key == pygame.K_s:
|
|
|
|
# checks if new waiter's position up is not occupied by other object
|
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX() + 1, waiter1.getY() + 1):
|
|
|
|
waiter1.moveDown()
|
|
|
|
waiter1.moveRight()
|
|
|
|
if event.key == pygame.K_a:
|
|
|
|
# checks if new waiter's position down is not occupied by other object
|
|
|
|
if drawableManager.isPositionAvailable(waiter1.getX() - 1, waiter1.getY() + 1):
|
|
|
|
waiter1.moveDown()
|
|
|
|
waiter1.moveLeft()
|
2020-04-20 23:19:13 +02:00
|
|
|
drawableManager.forceRepaint()
|
2020-03-22 21:52:12 +01:00
|
|
|
|
2020-04-05 17:27:11 +02:00
|
|
|
# repaints all objects to the screen
|
2020-04-20 23:19:13 +02:00
|
|
|
# is set only on initial paint or after keyboard event or call to forceRepaint()
|
|
|
|
if drawableManager.mustRepaint():
|
2020-05-14 23:22:30 +02:00
|
|
|
if not kitchenManager.is_running():
|
|
|
|
gridBoard.reinitialize()
|
|
|
|
gridBoard.draw(drawableManager)
|
|
|
|
gridBoard.udpdate()
|