diff --git a/environment.md b/environment.md new file mode 100644 index 0000000..7b6826f --- /dev/null +++ b/environment.md @@ -0,0 +1,57 @@ +# Raport 1 + +**Wybrany temat:** Automatyczny kelner + +**Członkowie zespołu:** Marcin Jerzy Dobrowalski, Paweł Lewcki, Dominik Zawadzki, Maksymilian Kierski + +**Czas prac:** 04.03.2020 - 08.04.2020 + +**Link do repozytorium projektu:** https://git.wmi.amu.edu.pl/s444427/Sztuczna_Inteligencja_2020 + +## Założenia Projektu + +1. Stworzenie symulacji pracy automatycznego kelnera +2. Praca agenta, opiera się o metody naucznia maszynowego +3. Środowisko działania symulacji jest oparte na macierzy +4. Środowisko generowane jest na bazie pliku tesktowego +5. Kelner porusza się tylko po predefiniowanych polach macierzy +6. Kelner potrafi rozpoznawać pola marzecierzy z predefiniowanymi elementami takimi jak klient, stół, krzesło, bar, ściana +7. Kelner sprawdza stan stolika (pusty, nowi goście, starzy goście, po gościach) +8. Kelner obsługuje gości (doradza danie, przyjmuję zamówienie, serwuje danie, sprząta stolik) +9. Kelner porusza się w optymalny sposób +10. Kelner odbiera gotowe dania z baru i zanosi je do gości + +## Środowisko agenta i reprezentacja wiedzy + +Środowisko oparte jest na macierzy. Macierz z poczególnymi polami środowiska tworzona jest na podstawie pliku tekstowego simulation_1.txt. Pola macierzy zawierają objekty reprezentujące elemnty środowiska. Każdy z obiektów ma swoje poszczególne atrybuty, odpowiedzialne za sposób interakcji agenta względem nich. Agent potrafi porszać się na poczególnych polach pomocą WSAD. + +* [main.py](main.py) - plik startowy +* [matrix.py](src/matrix.py) - klasa macierzy +* [tile.py](src/tile.py) - klasa pola macierzy +* [graphics.py](src/graphics.py) - klasa grafiki +* [waiter.py](src/waiter.py) - klasa agenta + +![Raport screen](resources/raport.jpg "Raport screen") + +## Instalacja i uruchomienie + +Wymagania: + +``` +module: pygames +Python: 3.7.7 +``` + +macOS / Linux + +``` +pygames +python main.py +``` + +Windows + +``` +pygames +python main.py +``` diff --git a/main.py b/main.py index b8f8927..016ffe0 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,15 @@ import sys + from src.graphics import * -from src.waiter import Waiter +from src.waiter import * if __name__ == "__main__": # SETUP pygame.init() clock = pygame.time.Clock() fps = 40 - waiter = Waiter() graphics = Graphics() + waiter = Waiter(graphics) # init functions graphics.drawBackground(waiter.matrix) @@ -28,7 +29,7 @@ if __name__ == "__main__": break graphics.clear(waiter.X, waiter.Y) - waiter.update(event) + waiter.update(event, graphics) graphics.update(waiter.X, waiter.Y) pygame.display.flip() clock.tick(fps) diff --git a/resources/images/chair-back.png b/resources/images/chair-back.png new file mode 100644 index 0000000..45ddf0d Binary files /dev/null and b/resources/images/chair-back.png differ diff --git a/resources/images/chair-front.png b/resources/images/chair-front.png new file mode 100644 index 0000000..60b141b Binary files /dev/null and b/resources/images/chair-front.png differ diff --git a/resources/images/chair-left.png b/resources/images/chair-left.png new file mode 100644 index 0000000..a6d2f17 Binary files /dev/null and b/resources/images/chair-left.png differ diff --git a/resources/images/chair-right.png b/resources/images/chair-right.png new file mode 100644 index 0000000..46d5b98 Binary files /dev/null and b/resources/images/chair-right.png differ diff --git a/resources/images/wall.png b/resources/images/wall.png new file mode 100644 index 0000000..5fd1323 Binary files /dev/null and b/resources/images/wall.png differ diff --git a/resources/raport.jpg b/resources/raport.jpg new file mode 100644 index 0000000..99d6ed0 Binary files /dev/null and b/resources/raport.jpg differ diff --git a/resources/simulations/simulation_1.txt b/resources/simulations/simulation_1.txt new file mode 100644 index 0000000..b452938 --- /dev/null +++ b/resources/simulations/simulation_1.txt @@ -0,0 +1,15 @@ +______________ +______________ +__PW_____PW___ +_USWP___USWP__ +__OWS____OWSI_ +__PWO____PWO__ +_USW____USW___ +__OWP____OWP__ +__PWS____PWSI_ +_USWO___USWO__ +__OW_____OW___ +______________ +______________ +BBBBB_________ +FFFFB_________ \ No newline at end of file diff --git a/resources/simulations/simulation_2.txt b/resources/simulations/simulation_2.txt new file mode 100644 index 0000000..b271377 --- /dev/null +++ b/resources/simulations/simulation_2.txt @@ -0,0 +1,8 @@ +X___TXFX +T_X_X__X +X_X_X_XX +T_X____T +X_X_XX_X +X_X____T +T_X_XXXX +XXX____W \ No newline at end of file diff --git a/resources/simulations/simulation_3.txt b/resources/simulations/simulation_3.txt new file mode 100644 index 0000000..69bc73e --- /dev/null +++ b/resources/simulations/simulation_3.txt @@ -0,0 +1,2 @@ +__X +___ \ No newline at end of file diff --git a/src/__pycache__/graphics.cpython-37.pyc b/src/__pycache__/graphics.cpython-37.pyc new file mode 100644 index 0000000..5a3ce97 Binary files /dev/null and b/src/__pycache__/graphics.cpython-37.pyc differ diff --git a/src/__pycache__/matrix.cpython-37.pyc b/src/__pycache__/matrix.cpython-37.pyc new file mode 100644 index 0000000..afca1ee Binary files /dev/null and b/src/__pycache__/matrix.cpython-37.pyc differ diff --git a/src/__pycache__/tile.cpython-37.pyc b/src/__pycache__/tile.cpython-37.pyc new file mode 100644 index 0000000..465e2fb Binary files /dev/null and b/src/__pycache__/tile.cpython-37.pyc differ diff --git a/src/__pycache__/waiter.cpython-37.pyc b/src/__pycache__/waiter.cpython-37.pyc new file mode 100644 index 0000000..5fdaebc Binary files /dev/null and b/src/__pycache__/waiter.cpython-37.pyc differ diff --git a/src/graphics.py b/src/graphics.py index 3210f72..b8d7781 100644 --- a/src/graphics.py +++ b/src/graphics.py @@ -5,23 +5,28 @@ class Graphics: def __init__(self): self.image = { 'floor': pygame.image.load('../resources/images/floor.jpg'), - 'table': pygame.image.load('../resources/images/table.png'), + 'wall': pygame.image.load('../resources/images/wall.png'), # + 'bar': pygame.image.load('../resources/images/table3.png'), # + 'bar_floor': pygame.image.load('../resources/images/waiter.png'), + 'table': pygame.image.load('../resources/images/table3.png'), 'waiter': pygame.image.load('../resources/images/waiter.png'), - 'table2': pygame.image.load('../resources/images/table2.png'), - 'table3': pygame.image.load('../resources/images/table3.png') + 'chair_front': pygame.image.load('../resources/images/chair-front.png'), # + 'chair_back': pygame.image.load('../resources/images/chair-back.png'), # + 'chair_left': pygame.image.load('../resources/images/chair-left.png'), # + 'chair_right': pygame.image.load('../resources/images/chair-right.png') # } self.block_size = 50 self.height = 15 - self.width = 14 - self.screen = pygame.display.set_mode((self.block_size*self.width, self.block_size*self.height)) + self.width: int = 14 + self.screen = pygame.display.set_mode((self.block_size * self.width, self.block_size * self.height)) def drawBackground(self, matrix): - for y in range(15): - for x in range(14): + for y in range(self.height): + for x in range(self.width): self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) - for y in range(15): - for x in range(14): + for y in range(self.height): + for x in range(self.width): self.screen.blit(self.image[matrix.get_type(x, y)], (x * self.block_size, y * self.block_size)) def clear(self, x, y): diff --git a/src/matrix.py b/src/matrix.py index af8d07c..bd74866 100644 --- a/src/matrix.py +++ b/src/matrix.py @@ -2,19 +2,44 @@ from src.tile import Tile class Matrix: - def __init__(self): + def __init__(self, graphics): self.matrix = [] - for x in range(14): - self.matrix.append([0] * 15) + self.set_default_matrix(graphics) + self.set_default_restaurant(graphics) - for x in range(14): - for y in range(15): - self.matrix[x][y] = Tile(type_='floor', watch_through=1) - self.matrix[1][0].type = 'table3' - self.matrix[1][0].walk_through = 0 + def set_default_matrix(self, graphics): + for x in range(graphics.width): + self.matrix.append([0] * graphics.height) + + for x in range(graphics.width): + for y in range(graphics.height): + self.matrix[x][y] = Tile(type_='floor') + + def set_default_restaurant(self, graphics): + lines = [line.rstrip('\n') for line in open('../resources/simulations/simulation_1.txt')] + symbols = { + '_': 'floor', + 'W': 'wall', + 'S': 'table', + 'B': 'bar', + 'F': 'bar_floor', + 'P': 'chair_front', + 'O': 'chair_back', + 'I': 'chair_left', + 'U': 'chair_right', + 'X': 'waiter' + } + + for x in range(graphics.width): + for y in range(graphics.height): + sign = lines[y][x] + self.matrix[x][y] = Tile(symbols[sign]) def get_type(self, x, y): return self.matrix[x][y].type def walk_through(self, x, y): return self.matrix[x][y].walk_through + + def watch_through(self, x, y): + return self.matrix[x][y].watch_through diff --git a/src/tile.py b/src/tile.py index c63e8aa..25f107b 100644 --- a/src/tile.py +++ b/src/tile.py @@ -1,7 +1,17 @@ # TILE class Tile: - def __init__(self, type_, watch_through): - self.watch_through = watch_through - self.walk_through = 1 - self.action_required = 0 + def __init__(self, type_): self.type = type_ + + if self.type == 'wall': + self.watch_through = 0 + self.walk_through = 0 + elif self.type == 'table' or self.type == 'bar' or self.type == 'chair': + self.watch_through = 1 + self.walk_through = 0 + else: + self.walk_through = 1 + self.watch_through = 1 + + self.action_required = 0 + diff --git a/src/waiter.py b/src/waiter.py index faf2715..b6e1de5 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -1,30 +1,32 @@ import pygame + from src.matrix import Matrix # WAITER class Waiter(pygame.sprite.Sprite): - def __init__(self): + def __init__(self, graphics): pygame.sprite.Sprite.__init__(self) self.X = 0 self.Y = 0 self.frame = 0 - self.matrix = Matrix() + self.matrix = Matrix(graphics=graphics) # Borders - def move(self, x, y): - if 0 <= self.X + x <= 13 and 0 <= self.Y + y <= 14: + def move(self, x, y, graphics): + if 0 <= self.X + x <= graphics.width - 1 and 0 <= self.Y + y <= graphics.height - 1: if self.matrix.walk_through(self.X + x, self.Y + y) == 1: self.X += x self.Y += y - def update(self, event): + def update(self, event, graphics): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: - self.move(-1, 0) + self.move(-1, 0, graphics) if event.key == pygame.K_RIGHT: - self.move(1, 0) + self.move(1, 0, graphics) if event.key == pygame.K_UP: - self.move(0, -1) + self.move(0, -1, graphics) if event.key == pygame.K_DOWN: - self.move(0, 1) + self.move(0, 1, graphics) + print(self.X, self.Y)