import pygame import functions import sys import time import decision_tree import data from agent import Agent from settings import Settings from board import create_board, draw_board from random import randint, choice from mcda import choseProducts # Inicjalizacja programu i utworzenie obiektu ekrany def run(): pygame.init() settings = Settings() screen = pygame.display.set_mode((settings.screen_width, settings.screen_height)) pygame.display.set_caption("Inteligentny wózek widłowy") agent = Agent(screen, 50, 50, "Down") board = create_board(screen) my_tree = decision_tree.build_tree(data.learning_data) produsctsFromSupply = choseProducts(5) # for row in board: # for field in row: # print(field.cost_of_travel) path = [] next_step = None # Rozpoczęcie głównej pętli programu while True: # functions.check_events(agent, board) # functions.update_screen(board, screen, agent) # for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: agent.turn_right() elif event.key == pygame.K_LEFT: agent.turn_left() elif event.key == pygame.K_UP: agent.move_forward(board) print(agent.x, agent.y) elif event.key == pygame.K_SPACE: board[9][0].item = choice(data.learning_data) print("Wybrano: " + board[9][0].item[-1]) board[9][0].item[-1] = 'Something' field = board[9][0] if not field.is_shelf: path = functions.a_star(board[agent.y][agent.x], field, board) path.pop(len(path) - 1) next_step = path.pop(len(path) - 1) if next_step is not None: time.sleep(0.5) if functions.check_turn(agent, next_step): agent.move_forward(board) if len(path) != 0: next_step = path.pop() else: next_step = None # print(next_step, path) for row in board: for field in row: if not field.is_shelf: field.image = pygame.image.load('img/Field.png') else: functions.change_turn(agent, next_step) if board[agent.y][agent.x].item: prediction = decision_tree.print_leaf(decision_tree.classify(board[agent.y][agent.x].item, my_tree)) print("Agent uważa, że przedmiot to: " + prediction[0]) board[agent.y][agent.x].item = [] draw_board(board) agent.blitme() pygame.display.flip() run()