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
|
# Marcin Dobrowolski
|
||||||
from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import *
|
from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import *
|
||||||
from src.SubprojectMarcinDobrowolski.utility import generateTestData, generateTestExample
|
from src.SubprojectMarcinDobrowolski.utility import generateTestData, generateTestExample
|
||||||
|
from src.guest import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# SETUP
|
# SETUP
|
||||||
@ -28,6 +29,8 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Marcin Dobrowolski
|
# Marcin Dobrowolski
|
||||||
suggestionTreeRoot = SuggestionTree.buildTree(trainingData)
|
suggestionTreeRoot = SuggestionTree.buildTree(trainingData)
|
||||||
|
newGuests = []
|
||||||
|
actions = []
|
||||||
|
|
||||||
# Maksymilian
|
# Maksymilian
|
||||||
go = 0
|
go = 0
|
||||||
@ -92,41 +95,22 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Marcin Dobrowolski
|
# Marcin Dobrowolski
|
||||||
if event.key == pygame.K_0:
|
if event.key == pygame.K_0:
|
||||||
generateTestData('testData.csv', 100)
|
newGuests.append(Guest(graphics))
|
||||||
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()))
|
|
||||||
|
|
||||||
# Marcin Dobrowolski
|
# Marcin Dobrowolski
|
||||||
if event.key == pygame.K_1:
|
if event.key == pygame.K_1:
|
||||||
example = generateTestExample()
|
guest = newGuests[0]
|
||||||
|
goal = [0, 0]
|
||||||
|
|
||||||
print('Test example prediction: ')
|
if guest.cord[0] == 2 or guest.cord[1] == 9:
|
||||||
print('{} - {}'.format(example, SuggestionTree.classify(
|
goal[0] = guest.cord[0] - 1
|
||||||
example, suggestionTreeRoot).printLeaf()))
|
goal[1] = guest.cord[1]
|
||||||
|
else:
|
||||||
|
goal[0] = guest.cord[0] + 1
|
||||||
|
goal[1] = guest.cord[1]
|
||||||
|
|
||||||
# Marcin Dobrowolski
|
actions.append(('takeOrder', goal))
|
||||||
if event.key == pygame.K_2:
|
print(actions)
|
||||||
SuggestionTree.printTree(suggestionTreeRoot)
|
|
||||||
|
|
||||||
# AStar
|
# AStar
|
||||||
if event.key == pygame.K_r:
|
if event.key == pygame.K_r:
|
||||||
@ -144,10 +128,24 @@ if __name__ == "__main__":
|
|||||||
path = waiter.translatePath(path)
|
path = waiter.translatePath(path)
|
||||||
|
|
||||||
# AStar
|
# 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 != '':
|
if path != '':
|
||||||
nextStep = path[0]
|
nextStep = path[0]
|
||||||
path = path[1:]
|
path = path[1:]
|
||||||
waiter.travel(nextStep, graphics)
|
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()
|
pygame.display.flip()
|
||||||
clock.tick(graphics.fps)
|
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_front': pygame.image.load(relative_path + 'chair-front.png'),
|
||||||
'chair_back': pygame.image.load(relative_path + 'chair-back.png'),
|
'chair_back': pygame.image.load(relative_path + 'chair-back.png'),
|
||||||
'chair_left': pygame.image.load(relative_path + 'chair-left.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.fps = 2
|
||||||
self.block_size = 50
|
self.block_size = 50
|
||||||
@ -49,3 +55,21 @@ class Graphics:
|
|||||||
model = 'waiter_' + waiter.direction
|
model = 'waiter_' + waiter.direction
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
self.image[model], (waiter.X * self.block_size, waiter.Y * self.block_size))
|
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 .matrix import Matrix
|
||||||
from .tile import Tile
|
from .tile import Tile
|
||||||
|
from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import *
|
||||||
|
|
||||||
# WAITER
|
# WAITER
|
||||||
|
|
||||||
|
|
||||||
class Waiter(pygame.sprite.Sprite):
|
class Waiter(pygame.sprite.Sprite):
|
||||||
def __init__(self, graphics):
|
def __init__(self, graphics):
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
@ -13,7 +15,6 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
self.frame = 0
|
self.frame = 0
|
||||||
self.matrix = Matrix(graphics=graphics)
|
self.matrix = Matrix(graphics=graphics)
|
||||||
self.direction = 'E'
|
self.direction = 'E'
|
||||||
self.tile = Tile(self, self.X, self.Y)
|
|
||||||
|
|
||||||
# Borders
|
# Borders
|
||||||
def move(self, x, y, graphics):
|
def move(self, x, y, graphics):
|
||||||
@ -52,6 +53,10 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
self.move(-1, 0, graphics)
|
self.move(-1, 0, graphics)
|
||||||
# print(self.X, self.Y)
|
# print(self.X, self.Y)
|
||||||
|
|
||||||
|
def takeOrder(self, tree, guest):
|
||||||
|
print('{} - {}'.format(guest.description, SuggestionTree.classify(
|
||||||
|
guest.description, tree).printLeaf()))
|
||||||
|
|
||||||
# AStar
|
# AStar
|
||||||
def findPath(self, goal):
|
def findPath(self, goal):
|
||||||
|
|
||||||
@ -242,7 +247,7 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
graphics.clear(self.X, self.Y)
|
graphics.clear(self.X, self.Y)
|
||||||
self.update('L', graphics)
|
self.update('L', graphics)
|
||||||
graphics.update(self)
|
graphics.update(self)
|
||||||
|
|
||||||
def Node(self):
|
def Node(self):
|
||||||
node = [self.X, self.Y]
|
node = [self.X, self.Y]
|
||||||
return node
|
return node
|
||||||
|
Loading…
Reference in New Issue
Block a user