diff --git a/main.py b/main.py index 4f17296..0a1c713 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ from src.SubprojectMaksymilianKierski.PlateRecognition import use_model_to_predi # Marcin Dobrowolski from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import * from src.SubprojectMarcinDobrowolski.utility import generateTestData, generateTestExample +from src.guest import * if __name__ == "__main__": # SETUP @@ -28,6 +29,8 @@ if __name__ == "__main__": # Marcin Dobrowolski suggestionTreeRoot = SuggestionTree.buildTree(trainingData) + newGuests = [] + actions = [] # Maksymilian go = 0 @@ -92,41 +95,22 @@ if __name__ == "__main__": # Marcin Dobrowolski if event.key == pygame.K_0: - generateTestData('testData.csv', 100) - testData = [] - with open('src/SubprojectMarcinDobrowolski/Data/testData.csv') as csv_file: - csvReader = csv.reader(csv_file, delimiter=',') - lineCount = 0 - - for row in csvReader: - example = [] - for column in row: - if column.isdigit(): - example.append(int(column)) - else: - example.append(column) - if lineCount > 0: - testData.append(example) - lineCount += 1 - - print('Processed lines: ', lineCount) - - print('Test examples predictions:') - for example in testData: - print('{} - {}'.format(example, SuggestionTree.classify( - example, suggestionTreeRoot).printLeaf())) + newGuests.append(Guest(graphics)) # Marcin Dobrowolski if event.key == pygame.K_1: - example = generateTestExample() + guest = newGuests[0] + goal = [0, 0] - print('Test example prediction: ') - print('{} - {}'.format(example, SuggestionTree.classify( - example, suggestionTreeRoot).printLeaf())) + if guest.cord[0] == 2 or guest.cord[1] == 9: + goal[0] = guest.cord[0] - 1 + goal[1] = guest.cord[1] + else: + goal[0] = guest.cord[0] + 1 + goal[1] = guest.cord[1] - # Marcin Dobrowolski - if event.key == pygame.K_2: - SuggestionTree.printTree(suggestionTreeRoot) + actions.append(('takeOrder', goal)) + print(actions) # AStar if event.key == pygame.K_r: @@ -144,10 +128,24 @@ if __name__ == "__main__": path = waiter.translatePath(path) # AStar + if path == '' and actions: + print('Goal: {}'.format(actions[0][1])) + path = waiter.findPath(actions[0][1]) + print('Path: {}'.format(path)) + path = waiter.translatePath(path) + print('Translated path: {}'.format(path)) + if path != '': nextStep = path[0] path = path[1:] waiter.travel(nextStep, graphics) + if path == '': + action = actions.pop(0) + if action[0] == 'takeOrder': + guest = newGuests.pop(0) + waiter.takeOrder(suggestionTreeRoot, guest) + graphics.clearGuest(guest) + tables.append(guest.cord) pygame.display.flip() clock.tick(graphics.fps) diff --git a/resources/images/guest-back.png b/resources/images/guest-back.png new file mode 100644 index 0000000..6b35d60 Binary files /dev/null and b/resources/images/guest-back.png differ diff --git a/resources/images/guest-front.png b/resources/images/guest-front.png new file mode 100644 index 0000000..d226c0a Binary files /dev/null and b/resources/images/guest-front.png differ diff --git a/resources/images/guest-left.png b/resources/images/guest-left.png new file mode 100644 index 0000000..7acf3bb Binary files /dev/null and b/resources/images/guest-left.png differ diff --git a/resources/images/guest-right.png b/resources/images/guest-right.png new file mode 100644 index 0000000..0b73dde Binary files /dev/null and b/resources/images/guest-right.png differ diff --git a/src/__pycache__/graphics.cpython-38.pyc b/src/__pycache__/graphics.cpython-38.pyc index e6722a1..7162ce5 100644 Binary files a/src/__pycache__/graphics.cpython-38.pyc and b/src/__pycache__/graphics.cpython-38.pyc differ diff --git a/src/__pycache__/waiter.cpython-38.pyc b/src/__pycache__/waiter.cpython-38.pyc index 25ac9da..0b584d5 100644 Binary files a/src/__pycache__/waiter.cpython-38.pyc and b/src/__pycache__/waiter.cpython-38.pyc differ diff --git a/src/graphics.py b/src/graphics.py index e954cb5..a52c88a 100644 --- a/src/graphics.py +++ b/src/graphics.py @@ -21,7 +21,13 @@ class Graphics: 'chair_front': pygame.image.load(relative_path + 'chair-front.png'), 'chair_back': pygame.image.load(relative_path + 'chair-back.png'), 'chair_left': pygame.image.load(relative_path + 'chair-left.png'), - 'chair_right': pygame.image.load(relative_path + 'chair-right.png') + 'chair_right': pygame.image.load(relative_path + 'chair-right.png'), + # + 'guest_front': pygame.image.load(relative_path + 'guest-front.png'), + 'guest_back': pygame.image.load(relative_path + 'guest-back.png'), + 'guest_left': pygame.image.load(relative_path + 'guest-left.png'), + 'guest_right': pygame.image.load(relative_path + 'guest-right.png') + } self.fps = 2 self.block_size = 50 @@ -49,3 +55,21 @@ class Graphics: model = 'waiter_' + waiter.direction self.screen.blit( self.image[model], (waiter.X * self.block_size, waiter.Y * self.block_size)) + + def drawGuest(self, guest): + self.clear(guest.cord[0], guest.cord[1] - 1) + self.clear(guest.cord[0], guest.cord[1] + 1) + + self.screen.blit(self.image['guest_front'], + (guest.cord[0] * self.block_size, (guest.cord[1] - 1) * self.block_size)) + self.screen.blit(self.image['guest_back'], + (guest.cord[0] * self.block_size, (guest.cord[1] + 1) * self.block_size)) + + def clearGuest(self, guest): + self.clear(guest.cord[0], guest.cord[1] - 1) + self.clear(guest.cord[0], guest.cord[1] + 1) + + self.screen.blit( + self.image['chair_front'], (guest.cord[0] * self.block_size, (guest.cord[1] + 1) * self.block_size)) + self.screen.blit( + self.image['chair_back'], (guest.cord[0] * self.block_size, (guest.cord[1] - 1) * self.block_size)) diff --git a/src/guest.py b/src/guest.py new file mode 100644 index 0000000..7449228 --- /dev/null +++ b/src/guest.py @@ -0,0 +1,85 @@ +import pygame +import random + +from src.matrix import * + + +class Guest(pygame.sprite.Sprite): + def __init__(self, graphics): + pygame.sprite.Sprite.__init__(self) + self.cord = self.randomTable() + self.matrix = Matrix(graphics=graphics) + self.description = self.generateDescription() + graphics.drawGuest(self) + + def randomTable(self): + table = random.choice(tables) + tables.remove(table) + return table + + def generateDescription(self): + example = [] + category = random.randrange(0, 1) + size = random.randrange(0, 2) + if category == 0: + example.append('meat') + + if size == 0: + money = random.randrange(10, 60) + appetite = random.randrange(10, 55) + example.append('little') + example.append(money) + example.append(appetite) + + if size == 1: + money = random.randrange(20, 60) + appetite = random.randrange(10, 55) + if appetite > 40: + if money < 30: + money = random.randrange(30, 60) + example.append('regular') + example.append(money) + example.append(appetite) + + if size == 2: + money = random.randrange(20, 60) + appetite = random.randrange(10, 55) + if appetite > 25 and appetite <= 40: + money = random.randrange(30, 60) + if appetite > 40: + money = random.randrange(50, 60) + example.append('large') + example.append(money) + example.append(appetite) + + elif category == 1: + example.append('vege') + + if size == 0: + money = random.randrange(10, 60) + appetite = random.randrange(10, 55) + example.append('little') + example.append(money) + example.append(appetite) + + if size == 1: + money = random.randrange(20, 60) + appetite = random.randrange(10, 55) + example.append('regular,') + example.append(money) + example.append(appetite) + + if size == 2: + money = random.randrange(20, 60) + appetite = random.randrange(10, 40) + example.append('large,') + example.append(money) + example.append(appetite) + + return example + + +tables = [(2, 3), (2, 6), (2, 9), + (4, 4), (4, 8), + (9, 3), (9, 6), (9, 9), + (11, 4), (11, 8)] diff --git a/src/waiter.py b/src/waiter.py index 5795bd1..d2768e0 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -2,9 +2,11 @@ import pygame from .matrix import Matrix from .tile import Tile - +from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import * # WAITER + + class Waiter(pygame.sprite.Sprite): def __init__(self, graphics): pygame.sprite.Sprite.__init__(self) @@ -13,7 +15,6 @@ class Waiter(pygame.sprite.Sprite): self.frame = 0 self.matrix = Matrix(graphics=graphics) self.direction = 'E' - self.tile = Tile(self, self.X, self.Y) # Borders def move(self, x, y, graphics): @@ -52,6 +53,10 @@ class Waiter(pygame.sprite.Sprite): self.move(-1, 0, graphics) # print(self.X, self.Y) + def takeOrder(self, tree, guest): + print('{} - {}'.format(guest.description, SuggestionTree.classify( + guest.description, tree).printLeaf())) + # AStar def findPath(self, goal): @@ -242,7 +247,7 @@ class Waiter(pygame.sprite.Sprite): graphics.clear(self.X, self.Y) self.update('L', graphics) graphics.update(self) - + def Node(self): node = [self.X, self.Y] return node