Compare commits

...

10 Commits

Author SHA1 Message Date
Arkadiusz
b213393734 Teraz wszystko 2019-06-05 01:32:59 +01:00
Arkadiusz
4b20e617b4 Koniec wygladu planszy 2019-06-05 01:19:55 +01:00
Arkadiusz
818eb2e8df Wizerunki stolikow 2019-06-05 00:09:16 +01:00
Arkadiusz
615cf534af zrzut scieżki do pliku ale bez stanu mapy itp. 2019-05-21 11:18:40 +01:00
Arkadiusz
6b6341d7c3 Dodano komentarze 2019-05-19 23:05:16 +01:00
Arkadiusz
a51cc452fc BFS I DSF z Visited 2019-05-19 21:46:37 +01:00
Arkadiusz
f7e3227185 BFS 2019-05-15 10:35:42 +01:00
Arkadiusz
129ad65d56 DFS cały działa 2019-05-08 00:24:04 +01:00
Arkadiusz
fe478e5ff8 DFS znajduje wszystkie mozliwe sciezki 2019-05-07 22:43:21 +01:00
Arkadiusz
8da63cae25 Zmienione self; nadal nie dziala 2019-05-05 23:07:13 +01:00
23 changed files with 685 additions and 244 deletions

View File

@ -3,7 +3,8 @@
<component name="ChangeListManager">
<list default="true" id="152ea650-8e02-4ed6-aa8c-04d44b275be4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/game.py" beforeDir="false" afterPath="$PROJECT_DIR$/game.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Images/stolikJedznie.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/savedPaths.txt" beforeDir="false" afterPath="$PROJECT_DIR$/savedPaths.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/waiter.py" beforeDir="false" afterPath="$PROJECT_DIR$/waiter.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -17,7 +18,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="132">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
@ -26,8 +27,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1475">
<caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<state relative-caret-position="792">
<caret line="69" column="62" selection-start-line="69" selection-start-column="62" selection-end-line="69" selection-end-column="62" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
@ -35,11 +36,16 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
<state relative-caret-position="154">
<caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" />
</state>
</provider>
</entry>
@ -47,8 +53,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
<state relative-caret-position="72">
<caret line="10" column="6" selection-start-line="10" selection-start-column="6" selection-end-line="10" selection-end-column="6" />
</state>
</provider>
</entry>
@ -56,8 +62,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<state relative-caret-position="176">
<caret line="8" column="65" selection-start-line="8" selection-start-column="21" selection-end-line="8" selection-end-column="65" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
@ -68,8 +74,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
<state relative-caret-position="198">
<caret line="9" column="45" lean-forward="true" selection-start-line="9" selection-start-column="45" selection-end-line="9" selection-end-column="45" />
</state>
</provider>
</entry>
@ -77,15 +83,24 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402">
<caret line="249" column="18" lean-forward="true" selection-start-line="249" selection-start-column="18" selection-end-line="249" selection-end-column="18" />
<state relative-caret-position="437">
<caret line="447" column="26" lean-forward="true" selection-start-line="447" selection-start-column="26" selection-end-line="447" selection-end-column="26" />
<folding>
<element signature="e#0#13#0" expanded="true" />
<element signature="e#0#14#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/wasteTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -95,6 +110,14 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>self.last</find>
<find>tmp</find>
<find>visited</find>
<find>drow</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
@ -102,6 +125,14 @@
</list>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="plansza-podstawy" />
</map>
</option>
</component>
<component name="HierarchyBrowserManager">
<option name="SORT_ALPHABETICALLY" value="true" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
@ -111,19 +142,19 @@
<option value="$PROJECT_DIR$/gridElement.py" />
<option value="$PROJECT_DIR$/run.py" />
<option value="$PROJECT_DIR$/order.py" />
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/orderTable.py" />
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/wasteTable.py" />
<option value="$PROJECT_DIR$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="716" />
<option name="y" value="77" />
<option name="width" value="970" />
<option name="height" value="1050" />
<option name="x" value="-7" />
<option name="width" value="1660" />
<option name="height" value="1047" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
@ -154,7 +185,7 @@
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="editor.preferences.fonts.default" />
<property name="settings.editor.selected.configurable" value="xml.catalog" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
@ -257,20 +288,20 @@
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18124342" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.13382508" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49894625" visible="true" weight="0.29577464" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.3997833" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32936078" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49894625" visible="true" weight="0.2979415" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.2708559" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32936078" />
<window_info anchor="bottom" id="Version Control" order="7" sideWeight="0.49947312" weight="0.32936078" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.32936078" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.50105375" side_tool="true" weight="0.32936078" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="bottom" id="Python Console" order="10" weight="0.32936078" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -318,6 +349,31 @@
<MESSAGE value="Lada i skromne kolizje" />
<option name="LAST_COMMIT_MESSAGE" value="Lada i skromne kolizje" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<default-breakpoints>
<breakpoint type="python-exception">
<properties notifyOnTerminate="true" exception="BaseException">
<option name="notifyOnTerminate" value="true" />
</properties>
</breakpoint>
</default-breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="PythonConfigurationType">
<watch expression="grid" language="Python" />
</configuration>
</watches-manager>
</component>
<component name="debuggerHistoryManager">
<expressions id="watch">
<expression>
<expression-string>grid</expression-string>
<language-id>Python</language-id>
<evaluation-mode>EXPRESSION</evaluation-mode>
</expression>
</expressions>
</component>
<component name="editorHistoryManager">
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py">
<provider selected="true" editor-type-id="text-editor">
@ -329,13 +385,6 @@
<entry file="file://$PROJECT_DIR$/Images/waiter.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/pydevd.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="1134" selection-start-line="1134" selection-end-line="1134" />
</state>
</provider>
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/_pydev_imps/_pydev_execfile.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
@ -365,9 +414,6 @@
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/run.py" />
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/Images/water.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
@ -384,60 +430,84 @@
<entry file="file://$PROJECT_DIR$/Images/tlo.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/order.py">
<entry file="file://$USER_HOME$/.PyCharmCE2018.3/system/python_stubs/-258859485/builtins.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="6" selection-start-line="6" selection-end-line="6" />
<state relative-caret-position="299">
<caret line="3704" column="8" selection-start-line="3704" selection-start-column="8" selection-end-line="3704" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gridElement.py">
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/pydevd.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
<state relative-caret-position="448">
<caret line="1740" selection-start-line="1740" selection-end-line="1740" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<state relative-caret-position="176">
<caret line="8" column="65" selection-start-line="8" selection-start-column="21" selection-end-line="8" selection-end-column="65" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/Images/tableSmall.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="9" column="45" lean-forward="true" selection-start-line="9" selection-start-column="45" selection-end-line="9" selection-end-column="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/wasteTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
<caret column="13" lean-forward="true" selection-start-column="13" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="72">
<caret line="10" column="6" selection-start-line="10" selection-start-column="6" selection-end-line="10" selection-end-column="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1475">
<caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<state relative-caret-position="792">
<caret line="69" column="62" selection-start-line="69" selection-start-column="62" selection-end-line="69" selection-end-column="62" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402">
<caret line="249" column="18" lean-forward="true" selection-start-line="249" selection-start-column="18" selection-end-line="249" selection-end-column="18" />
<state relative-caret-position="437">
<caret line="447" column="26" lean-forward="true" selection-start-line="447" selection-start-column="26" selection-end-line="447" selection-end-column="26" />
<folding>
<element signature="e#0#13#0" expanded="true" />
<element signature="e#0#14#0" expanded="true" />
</folding>
</state>
</provider>

BIN
Images/ladaJedzenie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
Images/stolik.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
Images/stolikBrudny.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
Images/stolikJedzenie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
Images/stolikOczekuje.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
Images/waiterJedzenie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
Images/zmywak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

86
game.py
View File

@ -1,10 +1,13 @@
import pygame, sys
import pygame, sys, random
from waiter import Waiter
from table import Table
from gridElement import GridElement
from pygame.math import Vector2
from orderTable import OrderTable
from pool import Pool
from wasteTable import WasteTable
from operator import attrgetter
import copy
class Game(object):
def __init__(self):
@ -25,29 +28,57 @@ class Game(object):
self.grid = []
self.row = []
self.tableList = []
self.orderTableList = []
# TWORZENIE ELEMENTÓW PLANSZY
for b in range(self.y):
for i in range(self.x):
if ((i == 0) or (i == 9)) and ((b == 0) or (b == 6)):
self.row.append(Table(i * 50, b * 50, self))
elif (b == self.y-1 or b == self.y-2 or b == self.y-3) and (i == 5):
table = OrderTable(i * 50, b * 50, self)
tmp = random.randint(0, 3)
table = Table(i * 50, b * 50, self)
if tmp == 1:
table.isOrdering = True
elif tmp == 2:
table.isWaiting = True
elif tmp == 3:
table.isClean = False
self.row.append(table)
self.tableList.append(table)
elif (b == self.y-1 or b == self.y-2 or b == self.y-3) and (i == 5):
orderTable = OrderTable(i * 50, b * 50, self)
self.row.append(orderTable)
self.orderTableList.append(orderTable)
elif i == 4 and b == 9:
self.waiter = Waiter(self, i * 50, b * 50)
self.row.append(self.waiter)
self.waiterNumberInGrid.x = i
self.waiterNumberInGrid.y = b
elif (((b > 0 and b < 6) and (i > 0 and i < 9)) and not((i==1 or i == 8) and (b==1 or b==5))) \
or (b>6 and (i<4 or i > 5) ):
elif (((((b > 0 and b < 6) and (i > 0 and i < 9)) and not((i == 1 or i == 8) and (b == 1 or b == 5))) \
or (b > 6 and (i < 4 or i > 5)))) and not i == 4 and not (b == 3) and not (i==3 and b==9):
self.row.append(Pool(i * 50, b * 50, self))
elif i == 3 and b == 9:
self.row.append(WasteTable(i * 50, b * 50, self))
else:
self.row.append(GridElement(i * 50, b * 50, self))
if i == self.x-1:
self.grid.append(list(self.row))
self.row.clear()
self.waiter.dfsFind(self, self.waiter.lastStep, 1)
#Wydawka jedzenia
for table in self.tableList:
if table.isWaiting:
self.orderTableList[0].hasDish = True
self.orderTableList.sort(key=attrgetter("hasDish"))
#self.dfs(self.waiter, 1, [])
#self.dfs(self.waiter, 3, [])
self.bfs(self.waiter, 1, [])
self.bfs(self.waiter, 4, [])
#path = self.waiter.bfsFind([self.waiter.positionX, self.waiter.positionY], [], 1)
# GŁÓWNA PĘTLA GRY
while True:
for event in pygame.event.get():
@ -56,11 +87,12 @@ class Game(object):
self.draw()
self.waiter.move(self)
print(self.waiter.checkPoss(self, self.waiter.lastStep))
pygame.display.flip()
#print(self.waiter.checkPoss(self.grid, self.waiter.lastStep))
#print(self.waiterNumberInGrid)
self.fpsClock.tick(10)
# WYRYSOWANIE KAZDEGO ELEMENTU Z GRIDU NA EKRAN
def draw(self):
tempTable = []
for row in self.grid:
@ -71,6 +103,7 @@ class Game(object):
tempTable.append(gridElement)
for otherElement in tempTable:
otherElement.draw()
pygame.display.flip()
def convert(self, object):
if object.type == "gridElement":
@ -83,6 +116,9 @@ class Game(object):
return 'O'
elif object.type == "pool":
return 'P'
elif object.type == "wasteTable":
return 'Z'
def showGrid(self, grid):
charakterList = []
@ -92,7 +128,33 @@ class Game(object):
charakterList.append(row)
print(row)
# ZNAJDUJE NAJKRÓTSZĄ ŚCIEŻKĘ DFS I PRZECHODZI WEDŁUG LISTY KROKÓW
def dfs(self, waiter, soughtID, operation=[]):
visited = []
waiter.dfsFind([waiter.positionX, waiter.positionY], operation, visited, soughtID)
paths = waiter.dfsPaths
paths.sort(key=len)
print("Wszystkie sciezki dfs: ", paths)
if paths:
bestPath = paths[0]
waiter.dfsPaths = []
waiter.followThePath(bestPath)
# ZNAJDUJE NAJKRÓTSZĄ ŚCIEŻKĘ BFS I PRZECHODZI WEDŁUG LISTY KROKÓW
def bfs(self, waiter, soughtID, operation=[]):
waiter.bfsFind([waiter.positionX, waiter.positionY], operation, [], soughtID)
paths = waiter.bfsPaths
paths.sort(key=len)
print("Wszystkie sciezki bfs: ", paths)
if paths:
bestPath = paths[0]
savedPaths = open("savedPaths.txt", "a+")
print(str(bestPath))
savedPaths.write(str(bestPath) + "\n")
waiter.bfsPaths = []
waiter.bfsQueue = []
waiter.followThePath(bestPath)
savedPaths.close()
if __name__ == "__main__":
Game()
v1 = Game()

View File

@ -12,7 +12,11 @@ class OrderTable(object):
self.y = y
self.image = pygame.image.load("./Images/drewno.jpg")
self.type = "orderTable"
self.hasDish = False
def draw(self):
self.rect = pygame.Rect(self.x, self.y, 50, 50)
self.game.screen.blit(self.image,(self.x, self.y))
if self.hasDish:
self.game.screen.blit(pygame.image.load("./Images/ladaJedzenie.png"),(self.x, self.y))
else:
self.game.screen.blit(self.image, (self.x, self.y))

77
savedPaths.txt Normal file
View File

@ -0,0 +1,77 @@
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left', 'Up', 'Up']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']
['Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Up', 'Left', 'Left', 'Left', 'Left']
['Right', 'Right', 'Right', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Right', 'Right', 'Right', 'Right']

View File

@ -11,12 +11,25 @@ class Table(object):
game.idTable += 1
game.idItem += 1
self.number = game.idItem
self.isBusy = False
self.isWaiting = False
self.isClean = True
self.isOrdering = False
self.hasDish = False
self.id = game.idTable
self.image = pygame.image.load("./Images/tableSmall.png")
self.image = pygame.image.load("./Images/stolik.png")
#self.image = pygame.transform.scale(self.image, (50, 50))
self.type = "table"
def draw(self):
self.table = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (100, 0, 100), self.table)
#self.game.screen.blit(self.image, (self.x, self.y))
if self.isOrdering:
self.game.screen.blit(pygame.image.load("./Images/stolikSkladaZamowienie.png"), (self.x, self.y))
elif self.isWaiting:
self.game.screen.blit(pygame.image.load("./Images/stolikOczekuje.png"), (self.x, self.y))
elif not self.isClean:
self.game.screen.blit(pygame.image.load("./Images/stolikBrudny.png"), (self.x, self.y))
elif self.hasDish:
self.game.screen.blit(pygame.image.load("./Images/stolikJedzenie.png"), (self.x, self.y))
else:
self.game.screen.blit((self.image), (self.x, self.y))

539
waiter.py
View File

@ -1,11 +1,15 @@
import asyncio
from multiprocessing import Queue
import pygame
import time
from pygame.math import Vector2
class Waiter(object):
def __init__(self, game, x, y):
self.game = game
self.grid = game.grid
game.idItem += 1
self.size= self.game.screen.get_size()
self.x = x
@ -16,236 +20,429 @@ class Waiter(object):
self.image.set_colorkey((255, 255, 255))
self.type = "waiter"
self.lastStep = []
self.whatKeep = 0
self.dfsStack = []
self.dfsPaths = []
def moveLeft(self, game):
self.bfsQueue = []
self.bfsPaths = []
# NIEUZYWANA FUNKCJA ZNAJDOWANIA KELNERA NA PLANSZY; ZWRACA POZYCJĘ KELNERA
def findWaiter(self, grid):
for y in range(10):
for x in range(10):
if grid[y][x].type =="waiter":
#print(x,y)
return [x, y]
def moveLeft(self):
if self.positionX != 0:
collisionObject = game.grid[self.positionY][self.positionX - 1]
collisionObject = self.game.grid[self.positionY][self.positionX - 1]
if collisionObject.type == "gridElement":
game.grid[self.positionY][self.positionX - 1].x += 50
game.grid[self.positionY][self.positionX].x -= 50
game.grid[self.positionY][self.positionX - 1], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY][self.positionX - 1]
self.game.grid[self.positionY][self.positionX - 1].x += 50
self.game.grid[self.positionY][self.positionX].x -= 50
self.game.grid[self.positionY][self.positionX - 1], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY][self.positionX - 1]
self.positionX -= 1
#print(self.positionX)
self.lastStep.append("Left")
else:
pass
def moveRight(self, game):
if self.positionX != game.x-1:
collisionObject = game.grid[self.positionY][self.positionX + 1]
self.work(collisionObject)
def moveRight(self):
if self.positionX != self.game.x-1:
collisionObject = self.game.grid[self.positionY][self.positionX + 1]
if collisionObject.type == "gridElement":
game.grid[self.positionY][self.positionX + 1].x -= 50
game.grid[self.positionY][self.positionX].x += 50
game.grid[self.positionY][self.positionX + 1], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY][self.positionX + 1]
self.game.grid[self.positionY][self.positionX + 1].x -= 50
self.game.grid[self.positionY][self.positionX].x += 50
self.game.grid[self.positionY][self.positionX + 1], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY][self.positionX + 1]
self.positionX += 1
#print(self.positionX)
self.lastStep.append("Right")
else:
pass
self.work(collisionObject)
def moveUp(self, game):
def moveUp(self):
if self.positionY != 0:
collisionObject = game.grid[self.positionY - 1][self.positionX]
collisionObject = self.game.grid[self.positionY - 1][self.positionX]
if collisionObject.type == "gridElement":
game.grid[self.positionY - 1][self.positionX].y += 50
game.grid[self.positionY][self.positionX].y -= 50
game.grid[self.positionY - 1][self.positionX], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY - 1][self.positionX]
self.game.grid[self.positionY - 1][self.positionX].y += 50
self.game.grid[self.positionY][self.positionX].y -= 50
self.game.grid[self.positionY - 1][self.positionX], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY - 1][self.positionX]
self.positionY -= 1
self.lastStep.append("Up")
else:
pass
self.work(collisionObject)
def moveDown(self, game):
if self.positionY != game.y-1:
collisionObject = game.grid[self.positionY + 1][self.positionX]
def moveDown(self):
if self.positionY != self.game.y-1:
collisionObject = self.game.grid[self.positionY + 1][self.positionX]
if collisionObject.type == "gridElement":
game.grid[self.positionY + 1][self.positionX].y -= 50
game.grid[self.positionY][self.positionX].y += 50
game.grid[self.positionY + 1][self.positionX], \
game.grid[self.positionY][self.positionX] = \
game.grid[self.positionY][self.positionX], \
game.grid[self.positionY + 1][self.positionX]
self.game.grid[self.positionY + 1][self.positionX].y -= 50
self.game.grid[self.positionY][self.positionX].y += 50
self.game.grid[self.positionY + 1][self.positionX], \
self.game.grid[self.positionY][self.positionX] = \
self.game.grid[self.positionY][self.positionX], \
self.game.grid[self.positionY + 1][self.positionX]
self.positionY += 1
self.lastStep.append("Down")
else:
pass
self.work(collisionObject)
# SPRAWDZA NACIŚNIĘTE KLAWISZE
def move(self, game):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.moveLeft(game)
self.moveLeft()
if keys[pygame.K_RIGHT]:
self.moveRight(game)
self.moveRight()
if keys[pygame.K_UP]:
self.moveUp(game)
self.moveUp()
if keys[pygame.K_DOWN]:
self.moveDown(game)
self.moveDown()
if keys[pygame.K_s]:
game.showGrid(game.grid)
def draw(self):
self.rect1 = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1)
#print(self.lastStep)
self.game.screen.blit(self.image, (self.x, self.y))
if self.whatKeep == 0:
self.game.screen.blit(self.image, (self.x, self.y))
elif self.whatKeep == 1:
self.game.screen.blit(pygame.image.load("./Images/waiterJedzenie.png"), (self.x, self.y))
elif self.whatKeep == 2:
self.game.screen.blit(pygame.image.load("./Images/waiterBrudneTalerze.png"), (self.x, self.y))
# SPRAWDZA CZY ELELEMNT, KTORY POBIERAMY NIE JEST SPOZA PLANSZY
def isMoveInRange(self, move, position):
positionX = position[0]
positionY = position[1]
def isMoveInRange(self, move):
if move == "Left":
if self.positionX == 0:
if positionX == 0:
return False
if move == "Right":
if self.positionX == 9:
if positionX == 9:
return False
if move == "Up":
if self.positionY == 0:
if positionY == 0:
return False
if move == "Down":
if self.positionY == 9:
if positionY == 9:
return False
return True
# SPRAWDZA MOZLIWOSCI RUCHU ZGODNIE Z OSTATNIM RUCHEM
def checkPoss(self, position, lastOperation):
def checkPoss(self, game, lastOperation):
self.grid = game.grid
self.lastOperation = lastOperation
self.stackMove = []
stackMove = []
if len(self.lastOperation) == 0:
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
positionX = position[0]
positionY = position[1]
if len(lastOperation) == 0:
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement" or collisionObjectUp.type == "waiter":
stackMove.append("Up")
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement" or collisionObjectLeft.type == "waiter":
stackMove.append("Left")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement" or collisionObjectRight.type == "waiter":
stackMove.append("Right")
return stackMove
else:
self.last = self.lastOperation[-1]
if self.last == "Left":
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
last = lastOperation[-1]
if last == "Left":
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement":
stackMove.append("Up")
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement":
stackMove.append("Left")
return self.stackMove
return stackMove
if self.last == "Right":
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if last == "Right":
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement":
stackMove.append("Up")
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement":
stackMove.append("Right")
return stackMove
if self.last == "Up":
if self.isMoveInRange("Up"):
self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
if self.collisionObjectUp.type == "gridElement":
self.stackMove.append("Up")
if last == "Up":
if self.isMoveInRange("Up", position):
collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement":
stackMove.append("Up")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement":
stackMove.append("Left")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement":
stackMove.append("Right")
return stackMove
if self.last == "Down":
if last == "Down":
if self.isMoveInRange("Down"):
self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
if self.collisionObjectDown.type == "gridElement":
self.stackMove.append("Down")
if self.isMoveInRange("Left"):
self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
if self.collisionObjectLeft.type == "gridElement":
self.stackMove.append("Left")
if self.isMoveInRange("Right"):
self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
if self.collisionObjectRight.type == "gridElement":
self.stackMove.append("Right")
return self.stackMove
if self.isMoveInRange("Down", position):
collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement":
stackMove.append("Down")
if self.isMoveInRange("Left", position):
collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement":
stackMove.append("Left")
if self.isMoveInRange("Right", position):
collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement":
stackMove.append("Right")
return stackMove
# DFS
def dfsFind(self, position, currentOperation, visited, idTable):
#print("Sprawdzam czy stolik")
def dfsFind(self, game, currentOperation, idTable):
self.game = game
self.grid = game.grid
self.currentOperation = currentOperation
print("Sprawdzam czy stolik")
if self.isMoveInRange("Up"):
if self.grid[self.positionY - 1][self.positionX].type == "table":
if self.grid[self.positionY - 1][self.positionX].id == idTable:
return self.currentOperation
if self.isMoveInRange("Down"):
if self.grid[self.positionY + 1][self.positionX].type == "table":
if self.grid[self.positionY + 1][self.positionX].id == idTable:
return self.currentOperation
if self.isMoveInRange("Left"):
if self.grid[self.positionY][self.positionX - 1].type == "table":
if self.grid[self.positionY][self.positionX - 1].id == idTable:
return self.currentOperation
if self.isMoveInRange("Right"):
if self.grid[self.positionY][self.positionX + 1].type == "table":
if self.grid[self.positionY][self.positionX + 1].id == idTable:
return self.currentOperation
print("Sprawdzilem nie stolik")
positionX = position[0]
positionY = position[1]
#print("Pozycja kelnera: ", position)
if self.isMoveInRange("Up", position):
if self.grid[positionY - 1][positionX].type == "table":
if self.grid[positionY - 1][positionX].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Down", position):
if self.grid[positionY + 1][positionX].type == "table":
if self.grid[positionY + 1][positionX].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Left", position):
if self.grid[positionY][positionX - 1].type == "table":
if self.grid[positionY][positionX - 1].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Right", position):
if self.grid[positionY][positionX + 1].type == "table":
if self.grid[positionY][positionX + 1].id == idTable:
self.dfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
# print("Sprawdzilem nie jest to stolik")
steps = []
steps.append(self.checkPoss(self.game, self.currentOperation))
step = steps[-1]
print(step[-1])
if step[-1] == "Left":
self.moveLeft(self.game)
self.currentOperation.append("Left")
if step[-1] == "Right":
self.moveRight(self.game)
self.currentOperation.append("Right")
if step[-1] == "Up":
self.moveUp(self.game)
self.currentOperation.append("Up")
if step[-1] == "Down":
self.moveDown(self.game)
self.currentOperation.append("Down")
game.draw()
time.sleep(.500)
pygame.display.flip()
self.dfsFind(self.game, self.currentOperation, idTable)
steps.append(self.checkPoss(position, currentOperation))
allstep = steps[-1]
# print("Naszymi mozliwosciami sa ", allstep)
if not allstep:
return 0
else:
for step in allstep:
newCurrentOperation = currentOperation[:]
newCurrentOperation.append(step)
newPosition = position[:]
newVisited = visited[:]
#print("newVisited", newVisited)
if step == "Left":
if [newPosition[0] - 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Right":
if [newPosition[0] + 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Up":
if [newPosition[0], newPosition[1] - 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
else:
if [newPosition[0], newPosition[1] + 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
self.dfsStack.append([newPosition, newCurrentOperation, newVisited, idTable])
while self.dfsStack:
move = self.dfsStack.pop()
self.dfsFind(move[0], move[1], move[2], move[3])
# BFS
def bfsFind(self, position, currentOperation, visited, idTable):
#print("Sprawdzam czy stolik")
positionX = position[0]
positionY = position[1]
# print("Pozycja kelnera: ", position)
if self.isMoveInRange("Up", position):
if self.grid[positionY - 1][positionX].type == "table":
if self.grid[positionY - 1][positionX].id == idTable:
currentOperation.append("Up")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Down", position):
if self.grid[positionY + 1][positionX].type == "table":
if self.grid[positionY + 1][positionX].id == idTable:
currentOperation.append("Down")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Left", position):
if self.grid[positionY][positionX - 1].type == "table":
if self.grid[positionY][positionX - 1].id == idTable:
currentOperation.append("Left")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
if self.isMoveInRange("Right", position):
if self.grid[positionY][positionX + 1].type == "table":
if self.grid[positionY][positionX + 1].id == idTable:
currentOperation.append("Right")
self.bfsPaths.append(currentOperation)
print("Dodalem sciezke: ", currentOperation)
return 0
# print("Sprawdzilem nie jest to stolik")
steps = []
steps.append(self.checkPoss(position, currentOperation))
allstep = steps[-1]
# print("Naszymi mozliwosciami sa ", allstep)
if not allstep:
return 0
else:
for step in allstep:
newCurrentOperation = currentOperation[:]
newCurrentOperation.append(step)
newPosition = position[:]
newVisited = visited[:]
# print("newVisited", newVisited)
if step == "Left":
if [newPosition[0] - 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Right":
if [newPosition[0] + 1, newPosition[1]] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[0] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
elif step == "Up":
if [newPosition[0], newPosition[1] - 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] -= 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
else:
if [newPosition[0], newPosition[1] + 1] in visited:
# print("Tam gdzie chce isc bylem juz: ", step)
continue
newPosition[1] += 1
if len(self.checkPoss(newPosition, newCurrentOperation)) == 1:
newVisited.append(newPosition)
self.bfsQueue.append([newPosition, newCurrentOperation, newVisited, idTable])
while not(self.bfsPaths) and self.bfsQueue:
move = self.bfsQueue.pop(0)
self.bfsFind(move[0], move[1],move[2], move[3])
# PORUSZA KELNERA WEDŁUG LISTY KROKOW
def followThePath(self, path):
for direction in path:
if direction == "Left":
self.moveLeft()
if direction == "Right":
self.moveRight()
if direction == "Up":
self.moveUp()
if direction == "Down":
self.moveDown()
self.game.draw()
time.sleep(.50)
def takeDish(self, orderTable):
orderTable.hasDish = False
self.whatKeep = 1
def putDish(self, table):
self.whatKeep = 0
table.hasDish = True
table.isWaiting = False
def takePlate(self, table):
table.hasDish = False
table.isClean = True
self.whatKeep = 2
def putPlate(self):
self.whatKeep = 0
def takeOrder(self, table):
table.isOrdering = False
def work(self, object: object) -> object:
if object.type == "wasteTable" and self.whatKeep == 2:
self.putPlate()
elif object.type == "orderTable" and object.hasDish and self.whatKeep == 0:
self.takeDish(object)
elif object.type == "table":
if not object.isClean and (self.whatKeep == 0 or self.whatKeep == 2):
self.takePlate(object)
elif object.isOrdering and self.whatKeep == 0:
self.takeOrder(object)
elif object.isWaiting and self.whatKeep == 1:
self.putDish(object)

18
wasteTable.py Normal file
View File

@ -0,0 +1,18 @@
import pygame
class WasteTable(object):
def __init__(self, x, y, game):
self.game = game
game.idItem += 1
self.idItem = game.idItem
self.x = x
self.y = y
self.image = pygame.image.load("./Images/zmywak.png")
self.type = "wasteTable"
def draw(self):
self.rect = pygame.Rect(self.x, self.y, 50, 50)
self.game.screen.blit(pygame.image.load("./Images/zmywak.png"), (self.x, self.y))