Marcin Dobrowolski subproject v2
This commit is contained in:
parent
55b9625189
commit
510be39b90
58
main.py
58
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)
|
||||
|
BIN
resources/images/guest-back.png
Normal file
BIN
resources/images/guest-back.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/images/guest-front.png
Normal file
BIN
resources/images/guest-front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/images/guest-left.png
Normal file
BIN
resources/images/guest-left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
resources/images/guest-right.png
Normal file
BIN
resources/images/guest-right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Binary file not shown.
@ -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))
|
||||
|
85
src/guest.py
Normal file
85
src/guest.py
Normal file
@ -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)]
|
@ -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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user