Merge branch 'miki_branch' of s444417/ProjektAI into master

This commit is contained in:
Mikołaj Krzymiński 2020-04-05 15:35:02 +00:00 committed by Gogs
commit 90af9e5f73
9 changed files with 213 additions and 33 deletions

View File

@ -2,16 +2,15 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="4be2149b-d9bc-4e21-8365-293320ae7f92" name="Default Changelist" comment=""> <list default="true" id="4be2149b-d9bc-4e21-8365-293320ae7f92" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/components/Drawable.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/images/srcWaiter.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/components/Table.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/managers/MenuManager.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/managers/DrawableCollection.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/managers/TaskManager.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/images/20x20grid.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/images/bigWaiter.jpg" beforeDir="false" afterPath="$PROJECT_DIR$/images/bigWaiter.jpg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/images/waiter.png" beforeDir="false" afterPath="$PROJECT_DIR$/images/waiter.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/GridBoard.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/GridBoard.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/Drawable.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Drawable.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/Table.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Table.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/Waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Waiter.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/Waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Waiter.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/managers/DrawableCollection.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/managers/DrawableCollection.py" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -30,8 +29,11 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component> </component>
<component name="ProjectId" id="1ZSC25l5bE6jvUIMcW31QzsqTTN" /> <component name="ProjectId" id="1ZSC25l5bE6jvUIMcW31QzsqTTN" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="settings.editor.selected.configurable" value="settings.github" /> <property name="settings.editor.selected.configurable" value="settings.github" />
@ -106,6 +108,13 @@
<workItem from="1585939347531" duration="8682000" /> <workItem from="1585939347531" duration="8682000" />
<workItem from="1585948578229" duration="795000" /> <workItem from="1585948578229" duration="795000" />
<workItem from="1585950329643" duration="151000" /> <workItem from="1585950329643" duration="151000" />
<workItem from="1585950592457" duration="1447000" />
<workItem from="1586011803812" duration="407000" />
<workItem from="1586015125508" duration="1424000" />
<workItem from="1586025614413" duration="11394000" />
<workItem from="1586089047557" duration="6590000" />
<workItem from="1586098345503" duration="112000" />
<workItem from="1586098478408" duration="902000" />
</task> </task>
<task id="LOCAL-00001" summary="klasa kelner"> <task id="LOCAL-00001" summary="klasa kelner">
<created>1584889744892</created> <created>1584889744892</created>
@ -135,7 +144,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1585257603366</updated> <updated>1585257603366</updated>
</task> </task>
<option name="localTasksCounter" value="5" /> <task id="LOCAL-00005" summary="dodano manager rysujący wszystkie obiekty, kelner rozpoznaje kolizje ze stołami">
<created>1585950875511</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1585950875511</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -155,10 +171,31 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="klasa kelner" /> <MESSAGE value="klasa kelner" />
<option name="LAST_COMMIT_MESSAGE" value="klasa kelner" /> <MESSAGE value="dodano manager rysujący wszystkie obiekty, kelner rozpoznaje kolizje ze stołami" />
<MESSAGE value="stoły mają 4 stany. Status gotowy do złożenia zamówienia ustawiany jest w nowym wątku w klasie TaskManager co 3 sekundy dla jednego stolika, kelner moze odbierać zamówienia od stolików gotowych do ich złożenia" />
<option name="LAST_COMMIT_MESSAGE" value="stoły mają 4 stany. Status gotowy do złożenia zamówienia ustawiany jest w nowym wątku w klasie TaskManager co 3 sekundy dla jednego stolika, kelner moze odbierać zamówienia od stolików gotowych do ich złożenia" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/managers/DrawableCollection.py</url>
<line>69</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="python-exception">
<properties notifyOnTerminate="true" exception="BaseException">
<option name="notifyOnTerminate" value="true" />
</properties>
</breakpoint>
</default-breakpoints>
</breakpoint-manager>
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/kelner$main.coverage" NAME="main Coverage Results" MODIFIED="1585950468781" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/kelner$main.coverage" NAME="main Coverage Results" MODIFIED="1586100415912" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component> </component>
</project> </project>

BIN
kelner/images/srcWaiter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

View File

@ -1,9 +1,10 @@
import pygame import pygame
from src.components.GridBoard import GridBoard from src.components.GridBoard import GridBoard
from src.managers.DrawableCollection import DrawableCollection from src.managers.DrawableCollection import DrawableCollection
from src.managers.MenuManager import MenuManager
from src.components.Waiter import Waiter from src.components.Waiter import Waiter
from src.components.Table import Table from src.components.Table import Table
from src.managers.TaskManager import TaskManager
#create screen consts #create screen consts
CellSize = 50 #pixel size of 1 square cell in the grid CellSize = 50 #pixel size of 1 square cell in the grid
@ -18,17 +19,30 @@ gridBoard = GridBoard(ScreenWidth, ScreenHeight, CellSize)
#initialize drawable objects manager #initialize drawable objects manager
drawableManager = DrawableCollection() drawableManager = DrawableCollection()
#initialize menu manager
menuManager = MenuManager()
#initialize waiter component #initialize waiter component
waiter = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize) waiter = Waiter(0, 0, 0, GridCountX - 1, 0, GridCountY - 1, CellSize)
#adds waiter to drawable collection
drawableManager.add(waiter)
#initialize a number of tables given in range #initialize a number of tables given in range
for i in range(1, 15): for i in range(1, 20):
table = Table(0, GridCountX - 1, 0, GridCountY - 1, CellSize) table = Table(0, GridCountX - 1, 0, GridCountY - 1, CellSize)
drawableManager.generatePosition(table) drawableManager.generatePosition(table)
drawableManager.add(table) drawableManager.add(table)
#main loop #main loop
doRepaint = True
#object that controlls repainting of changed objects
doRepaint = [True]
#new thread
task = TaskManager(drawableManager, menuManager, doRepaint)
task.start()
running = True running = True
while running: while running:
@ -54,13 +68,13 @@ while running:
# checks if new waiter's position down is not occupied by other object # checks if new waiter's position down is not occupied by other object
if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() + 1): if drawableManager.isPositionAvailable(waiter.getX(), waiter.getY() + 1):
waiter.moveDown() waiter.moveDown()
doRepaint = True doRepaint[0] = True
# repaints all objects to the screen # repaints all objects to the screen
#is set only on initial paint or after keyboard event # is set only on initial paint or after keyboard event
if doRepaint: if doRepaint[0]:
gridBoard.reinitialize() gridBoard.reinitialize()
gridBoard.draw(drawableManager) gridBoard.draw(drawableManager)
gridBoard.draw(waiter) gridBoard.udpdate()
gridBoard.udpdate() doRepaint[0] = False
doRepaint = False drawableManager.collectOrders()

View File

@ -1,8 +1,9 @@
class Drawable: class Drawable:
BLUE = (0, 0, 255) GREY = (128, 128, 128)
GREEN = (0, 255, 0) YELLOW = (255, 255, 0)
RED = (255, 0, 0) RED = (255, 0, 0)
GREEN = (0, 255, 0)
def __init__(self, x, y, minX, maxX, minY, maxY, ratio): def __init__(self, x, y, minX, maxX, minY, maxY, ratio):
self.__minX = minX self.__minX = minX

View File

@ -1,5 +1,5 @@
import pygame import pygame
import random from enum import Enum
from .Drawable import Drawable from .Drawable import Drawable
class Table(Drawable): class Table(Drawable):
@ -7,8 +7,44 @@ class Table(Drawable):
def __init__(self, minX, maxX, minY, maxY, ratio): def __init__(self, minX, maxX, minY, maxY, ratio):
#call base class constructor #call base class constructor
Drawable.__init__(self, 0, 0, minX, maxX, minY, maxY, ratio) Drawable.__init__(self, 0, 0, minX, maxX, minY, maxY, ratio)
self.__order = []
self.__status = Status.NotReady
#sets table color based on it's status
def getColor(self):
color = None
if self.__status == Status.NotReady:
color = self.GREY
elif self.__status == Status.Ready:
color = self.YELLOW
elif self.__status == Status.Waiting:
color = self.RED
elif self.__status == Status.Served:
color = self.GREEN
return color
def draw(self, screen): def draw(self, screen):
pygame.draw.circle(screen, self.GREEN, ((self.getX() * self.getRatio()) + (self.getRatio() // 2), pygame.draw.circle(screen, self.getColor(), ((self.getX() * self.getRatio()) + (self.getRatio() // 2),
(self.getY() * self.getRatio()) + (self.getRatio() // 2)), (self.getY() * self.getRatio()) + (self.getRatio() // 2)),
(self.getRatio() // 3)) (self.getRatio() // 3))
def setOrder(self, order):
self.__order = order
def getOrder(self):
return self.__order
def delOrder(self):
self.setOrder([])
def isStatus(self, status):
return status == self.__status
def setStatus(self, status):
self.__status = status
#status of the table
class Status(Enum):
NotReady = 0
Ready = 1
Waiting = 2
Served = 3

View File

@ -7,6 +7,7 @@ class Waiter(Drawable):
#call base class constructor #call base class constructor
Drawable.__init__(self, x, y, minX, maxX, minY, maxY, ratio) Drawable.__init__(self, x, y, minX, maxX, minY, maxY, ratio)
self.__image = self.__loadImg('./images/waiter.png') self.__image = self.__loadImg('./images/waiter.png')
self.__acceptedOrders = []
def moveUp(self): def moveUp(self):
if self.getY() > self.getMinY(): if self.getY() > self.getMinY():
@ -36,6 +37,10 @@ class Waiter(Drawable):
else: else:
return False return False
#accepts orders from the table and stores them in queue
def addOrder(self, table):
self.__acceptedOrders += [(table, table.getOrder())]
def __loadImg(self, filePath): def __loadImg(self, filePath):
return pygame.image.load(filePath) return pygame.image.load(filePath)

View File

@ -1,9 +1,11 @@
import random import random
from src.components.Table import Table, Status
from src.components.Waiter import Waiter
#drawable objects manager #drawable objects manager
class DrawableCollection: class DrawableCollection:
#const, minimal distance between objects #const, minimal distance between objects
__MinDistance = 1 __MinDistance = 0
def __init__(self): def __init__(self):
#collection that holds all drawable objects #collection that holds all drawable objects
@ -13,7 +15,7 @@ class DrawableCollection:
def add(self, drawable): def add(self, drawable):
self.__drawables.append(drawable) self.__drawables.append(drawable)
#generates and sets random x, y and cheks if it's not occupied by other object #generates and sets random (x, y) and cheks if it's not occupied by other object
def generatePosition(self, drawable): def generatePosition(self, drawable):
isPositionUnique = False isPositionUnique = False
while not isPositionUnique: while not isPositionUnique:
@ -41,3 +43,30 @@ class DrawableCollection:
isPositionAvailable = False isPositionAvailable = False
break break
return isPositionAvailable return isPositionAvailable
#gets all tables by status from collection
def getTables(self, status):
result = []
for item in self.__drawables:
if isinstance(item, Table) and item.isStatus(status):
result += [item]
return result
#gets all waiters from collection
def getWaites(self):
result = []
for item in self.__drawables:
if isinstance(item, Waiter):
result += [item]
return result
#waiter collects order from the nearest table
def collectOrders(self):
waiters = self.getWaites()
for waiter in waiters:
tables = self.getTables(Status.Ready)
for table in tables:
if (table.getX() == waiter.getX() and abs(table.getY() - waiter.getY()) == 1) or (table.getY() == waiter.getY() and abs(table.getX() - waiter.getX()) == 1):
table.setStatus(Status.Waiting)
waiter.addOrder(table)
table.delOrder()

View File

@ -0,0 +1,33 @@
import random
#contains all dishes and generates random order for the table
class MenuManager:
#consts, min and max dishes oredered by the people sitting by the same table
__MinDishes = 1
__MaxDishes = 3
def __init__(self):
self.__menuCard = ["PORK",
"FRENCH FRIES",
"PIZZA",
"CHICKEN",
"RIBS",
"FISH",
"SPAGHETTI",
"BEEF",
"STEAK",
"SALAD",
"GRILLED VEGETABLES",
"VEAL",
"CHOPS",
"EMPTY PLATE",
"BEER",
"CAKE"]
#generator
def generateOrder(self):
count = random.randint(self.__MinDishes, self.__MaxDishes)
order = []
for i in range(0, count):
order += [(self.__menuCard[random.randint(0, len(self.__menuCard) - 1)])]
return order

View File

@ -0,0 +1,25 @@
import threading
import time
import random
from src.components.Table import Status
#creates new threads
class TaskManager (threading.Thread):
def __init__(self, drawableManager, menuManager, doRepaintObject):
threading.Thread.__init__(self)
self.__drawableManager = drawableManager
self.__menuManager = menuManager
self.__doRepaintObject = doRepaintObject
#changes the status of a random table from NotReady to Ready
def run(self):
while True:
time.sleep(3)
tables = self.__drawableManager.getTables(Status.NotReady)
if tables != []:
tableIndex = random.randint(0, len(tables) - 1)
table = tables[tableIndex]
table.setStatus(Status.Ready)
table.setOrder(self.__menuManager.generateOrder())
self.__doRepaintObject[0] = True