Dodanie kierunku agenta; rozstawienie stolow; dodanie kuchni; agent nie wchodzi na pola z obiektem stol i kuchnia

This commit is contained in:
s444447 2020-04-25 14:31:02 +02:00
parent 1a23e2bebf
commit d88933f530
9 changed files with 180 additions and 54 deletions

6
Restaurant/.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="76f12f94-8135-4028-8378-41c67cca6cd2" name="Default Changelist" comment="" />
<list default="true" id="76f12f94-8135-4028-8378-41c67cca6cd2" name="Default Changelist" comment="Dodanie kierunku agenta; rozstawienie stolow; dodanie kuchni; agent nie wchodzi na pola z obiektem stol i kuchnia">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/kitchen1.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/kitchen2.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/kitchen3.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/kitchen4.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/waiter_left.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/waiter_right.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -9,12 +19,15 @@
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="277">
<caret line="18" column="61" selection-start-line="18" selection-start-column="61" selection-end-line="18" selection-end-column="61" />
<state relative-caret-position="4">
<caret line="20" column="51" lean-forward="true" selection-start-line="20" selection-start-column="51" selection-end-line="20" selection-end-column="51" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -28,6 +41,14 @@
</list>
</option>
</component>
<component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
<option value="Kinga Molik" />
</list>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
@ -35,18 +56,17 @@
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="7">
<option name="x" value="574" />
<option name="y" value="-19" />
<option name="width" value="694" />
<option name="height" value="735" />
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="950" />
<option name="width" value="979" />
<option name="height" value="1040" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -58,10 +78,11 @@
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
<property name="settings.editor.selected.configurable" value="settings.github" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
@ -122,33 +143,48 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
<editor active="true" />
<frame x="-7" y="-7" width="1550" height="838" extended-state="6" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.122023806" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.019828156" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Python Console" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" sideWeight="0.50074404" side_tool="true" weight="0.3289689" />
<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.49925596" visible="true" weight="0.3289689" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49925596" weight="0.3045326" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39934534" />
<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" />
<window_info anchor="bottom" id="Version Control" order="7" weight="0.53824365" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.9575071" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.50074404" side_tool="true" weight="0.3289689" />
<window_info anchor="bottom" id="Python Console" order="10" />
<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" />
</layout>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Dodanie kierunku agenta; rozstawienie stolow; dodanie kuchni; agent nie wchodzi na pola z obiektem stol i kuchnia" />
<option name="LAST_COMMIT_MESSAGE" value="Dodanie kierunku agenta; rozstawienie stolow; dodanie kuchni; agent nie wchodzi na pola z obiektem stol i kuchnia" />
</component>
<component name="editorHistoryManager">
<entry file="file://$USER_HOME$/Downloads/DSZI_2020_Projekt-master/dszi_2020_projekt/Restaurant/main.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="277">
<caret line="18" column="61" selection-start-line="18" selection-start-column="61" selection-end-line="18" selection-end-column="61" />
<state relative-caret-position="4">
<caret line="20" column="51" lean-forward="true" selection-start-line="20" selection-start-column="51" selection-end-line="20" selection-end-column="51" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>

BIN
Restaurant/kitchen1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
Restaurant/kitchen2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

BIN
Restaurant/kitchen3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
Restaurant/kitchen4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

View File

@ -28,9 +28,10 @@ class Plate(object):
class Kitchen(object):
def __init__(self):
self.readyDishes = queue.queue(32) #kolejka o maksymalnej długości 32
self.orders = queue.queue(32)
def __init__(self, pos):
self.readyDishes = queue.Queue(32) #kolejka o maksymalnej długości 32
self.orders = queue.Queue(32) #wyskakiwał mi tu błąd - poprawiłam na dużą literę i jest ok
self.pos = pos
def makeDish(self):
if not self.orders.empty():
@ -45,6 +46,24 @@ class Kitchen(object):
else:
return None
def draw(self, surface):
image1 = pygame.image.load(r'kitchen1.png')
image1 = pygame.transform.scale(image1, (sizeBetween - 1, sizeBetween - 1))
surface.blit(image1, (13*sizeBetween+1, 0*sizeBetween+1))
image2 = pygame.image.load(r'kitchen2.png')
image2 = pygame.transform.scale(image2, (sizeBetween - 1, sizeBetween - 1))
surface.blit(image2, (14*sizeBetween+1, 0*sizeBetween+1))
image3 = pygame.image.load(r'kitchen3.png')
image3 = pygame.transform.scale(image3, (sizeBetween - 1, sizeBetween - 1))
surface.blit(image3, (13*sizeBetween+1, 1*sizeBetween+1))
image4 = pygame.image.load(r'kitchen4.png')
image4 = pygame.transform.scale(image4, (sizeBetween - 1, sizeBetween - 1))
surface.blit(image4, (14*sizeBetween+1, 1*sizeBetween+1))
class Client(object):
def __init__(self, age, sex, budget):
@ -81,43 +100,52 @@ class Table(object):
class Waiter(object):
def __init__(self, color, pos):
def __init__(self, color, pos, direction):
self.color = color
self.pos = pos #pozycja agenta, zapisana w formie dwuelementowej listy
self.dirnx = 0 #zmienne dirnx i dirny używane są do ruchu bota i ustalania, w którą stronę jest zwrócony
self.dirny = 1
self.plates = [] #lista niesionych przez agenta talerzy, planowo lista par: (talerz, klient)
self.direction = direction #kierunek, w ktory jest skierowany bot
def moveRandomly(self):
def moveRandomly(self, noWalkable):
rand = random.randrange(1, 5, 1) #losuje w zakresie 1-4
print(rand)
#print(rand)
if rand == 1:
self.dirnx = -1
self.dirny = 0
if self.pos[0] == 0: #zabezpieczenie przed wyjściem bota poza obszar okna w ruchu losowym
self.dirnx *= (-1)
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
self.direction = 'left'
if self.pos[0] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable): #zabezpieczenie przed wyjściem bota poza obszar okna w ruchu losowym
self.dirnx *= (-1) #oraz w miejsce, na ktore nie moze wejsc (stoły, kuchania)
self.direction = 'right'
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
elif rand == 2:
self.dirnx = 1
self.dirny = 0
if self.pos[0] == 14:
self.direction = 'right'
if self.pos[0] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
self.dirnx *= (-1)
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
self.direction = 'left'
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
elif rand == 3:
self.dirnx = 0
self.dirny = -1
if self.pos[1] == 0:
if self.pos[1] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
self.dirny *= (-1)
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
elif rand == 4:
self.dirnx = 0
self.dirny = 1
if self.pos[1] == 14:
if self.pos[1] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
self.dirny *= (-1)
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
def moveWithKeyboard(self): #funkcja testowa - bot sterowany z klawiatury
def moveWithKeyboard(self, noWalkable): #funkcja testowa - bot sterowany z klawiatury
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
@ -129,8 +157,13 @@ class Waiter(object):
if keys[pygame.K_LEFT]:
self.dirnx = -1
self.dirny = 0
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
break
self.direction = 'left'
if self.pos[0] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable): # zabezpieczenie przed wyjściem bota poza obszar okna w ruchu losowym
#self.dirnx *= (-1)
break
else:
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
break
# te break musiałam dodać, bo w przeciwnym wypadku zamiast jednego kroku robił 303 - jeden za drugim
# nie wiem dlaczego tak było, po zmianie sterowania z klawiatury na bota samego w sobie nie powinno
# być z tym problemów, to jest na razie tylko, żeby pokazać, że ten ruch jest
@ -138,20 +171,33 @@ class Waiter(object):
elif keys[pygame.K_RIGHT]:
self.dirnx = 1
self.dirny = 0
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
break
self.direction = 'right'
if self.pos[0] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
#self.dirnx *= (-1)
break
else:
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
break
elif keys[pygame.K_UP]:
self.dirnx = 0
self.dirny = -1
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
break
if self.pos[1] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
#self.dirny *= (-1)
break
else:
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
break
elif keys[pygame.K_DOWN]:
self.dirnx = 0
self.dirny = 1
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
break
if self.pos[1] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
#self.dirny *= (-1)
break
else:
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
break
def resetPosition(self, pos):
self.pos = pos
@ -169,10 +215,23 @@ class Waiter(object):
client.takePlateAndEat(plate)
def draw(self, surface):
i = self.pos[0]
j = self.pos[1]
if self.direction == 'right':
image = pygame.image.load(r'waiter_right.png')
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
pygame.draw.rect(surface, self.color, (i*sizeBetween+1, j*sizeBetween+1, sizeBetween-1, sizeBetween-1))
i = self.pos[0]
j = self.pos[1]
surface.blit(image, (i*sizeBetween+1, j*sizeBetween+1))
else:
image = pygame.image.load(r'waiter_left.png')
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
i = self.pos[0]
j = self.pos[1]
surface.blit(image, (i*sizeBetween+1, j*sizeBetween+1))
def drawGrid(width, rows, surface):
@ -190,13 +249,21 @@ def drawGrid(width, rows, surface):
def redrawWindow(surface):
surface.fill(beige)
bot.draw(surface)
table1.draw(surface)
kitchen.draw(surface)
for i in range(len(tables)):
tables[i].draw(surface)
drawGrid(width, rows, surface)
pygame.display.update()
def noWalkable(tables, kitchen):
list = []
for i in range(len(tables)):
list.append(tables[i].pos)
list.append(kitchen.pos)
return list
def main():
global width, rows, bot, beige, white, black, sizeBetween, table1
global width, rows, bot, beige, white, black, sizeBetween, tables, kitchen
# skróty do kolorów
beige = (255, 205, 178)
white = (255, 255, 255)
@ -206,16 +273,33 @@ def main():
rows = 15
sizeBetween = width // rows #wielkość pojedynczej kratki
window = pygame.display.set_mode((width, width))
bot = Waiter((255, 0, 0), [7, 7])
table1 = Table([5, 5])
bot = Waiter((255, 0, 0), [12, 8], 'right')
tables = []
tables.append(Table([0, 3], 1))
tables.append(Table([0, 6], 1))
tables.append(Table([0, 9], 2))
tables.append(Table([0, 12], 2))
tables.append(Table([4, 4], 2))
tables.append(Table([4, 7], 2))
tables.append(Table([4, 10], 2))
tables.append(Table([4, 13], 2))
tables.append(Table([8, 3], 1))
tables.append(Table([8, 6], 1))
tables.append(Table([8, 9], 2))
tables.append(Table([8, 12], 2))
flag = True
clock = pygame.time.Clock()
kitchen = Kitchen([13, 1])
list = noWalkable(tables, kitchen) # lista pozycji, na ktore bot nie moze wejsc
while flag:
pygame.time.delay(100)
clock.tick(60)
for i in range(40): #bot testowo ma wykonać 40 kroków
bot.moveRandomly()
bot.moveRandomly(list)
redrawWindow(window)
time.sleep(0.5) #opóźnienie każdego kolejnego kroku o pół sekundy
flag = False

BIN
Restaurant/waiter_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

BIN
Restaurant/waiter_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB