import secrets import sys from random import randrange from src.decisionTree import * from src.SubprojectMaksymilianKierski.PlateRecognition import use_model_to_predict, text_speech # Marcin Dobrowolski from src.SubprojectMarcinDobrowolski.suggestionDecisionTree import * from src.SubprojectMarcinDobrowolski.utility import generateTestData, generateTestExample if __name__ == "__main__": # SETUP pygame.init() clock = pygame.time.Clock() graphics = Graphics() waiter = Waiter(graphics) tree = DecisionTree() # Init functions graphics.drawBackground(waiter.matrix) graphics.update(waiter) # AStar goal = None path = '' # Marcin Dobrowolski suggestionTreeRoot = SuggestionTree.buildTree(trainingData) # Maksymilian go = 0 rand = 0 while True: for event in pygame.event.get(): # rabbit.check(waiter.matrix, waiter.X, waiter.Y) if event.type == pygame.QUIT: pygame.quit() sys.exit() break if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() break if event.key == pygame.K_s: tree.TasksList('check', [10, 3]) tree.TasksList('eat', [5, 12]) tree.TasksList('order', [12, 4]) tree.TasksList('goToBar', [10, 10]) tree.TasksList('check', [3, 4]) tree.TasksList('eat', [10, 5]) tree.print() if event.key == pygame.K_m: tabPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8], [8, 2], [8, 5], [8, 8], [12, 3], [12, 7]] if not [waiter.X, waiter.Y] in tabPos or go == 0: if [waiter.X, waiter.Y] in tabPos: model = 'waiter_' + waiter.direction for x in range(-1, 2): waiterX = waiter.X+(x*0.1) print(waiterX) graphics.clear(waiterX, waiter.Y - 1) rand = randrange(9) x = tabPos[rand][0] y = tabPos[rand][1] goal = (x, y) path = waiter.findPath(goal) path = waiter.translatePath(path) go = 1 else: predict = use_model_to_predict('test-{}'.format(rand)) if predict == 1: predict = 'EMPTY' else: predict = 'FOOD' text_speech('arialnarrow.ttf', 25, predict, (255, 255, 255), (0, 128, 0), (waiter.X * 50 + 25), (waiter.Y * 50 - 25), False, False, screen=graphics.screen) pygame.display.flip() go = 0 # 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())) # Marcin Dobrowolski if event.key == pygame.K_1: example = generateTestExample() print('Test example prediction: ') print('{} - {}'.format(example, SuggestionTree.classify( example, suggestionTreeRoot).printLeaf())) # Marcin Dobrowolski if event.key == pygame.K_2: SuggestionTree.printTree(suggestionTreeRoot) # AStar if event.key == pygame.K_r: temp = False while not temp: x = secrets.randbelow(graphics.width) y = secrets.randbelow(graphics.height) print(x, y) if waiter.matrix.matrix[x][y].walk_through == 1: temp = True goal = (x, y) path = waiter.findPath(goal) path = waiter.translatePath(path) # AStar if path != '': nextStep = path[0] path = path[1:] waiter.travel(nextStep, graphics) pygame.display.flip() clock.tick(graphics.fps)