2020-05-15 17:25:01 +02:00
|
|
|
import pygame
|
|
|
|
import functions
|
|
|
|
import sys
|
|
|
|
import time
|
2020-05-19 13:14:19 +02:00
|
|
|
import decision_tree
|
|
|
|
import data
|
2020-05-15 17:25:01 +02:00
|
|
|
|
|
|
|
from agent import Agent
|
|
|
|
from settings import Settings
|
|
|
|
from board import create_board, draw_board
|
2020-05-19 13:14:19 +02:00
|
|
|
from random import randint, choice
|
2020-06-08 18:26:34 +02:00
|
|
|
from mcda import selectedSupply
|
2020-06-09 15:21:36 +02:00
|
|
|
from product import FinalProduct
|
|
|
|
from coder import create_image
|
2020-05-15 17:25:01 +02:00
|
|
|
|
2020-06-08 18:21:02 +02:00
|
|
|
|
2020-05-15 17:25:01 +02:00
|
|
|
# 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")
|
2020-06-09 21:58:59 +02:00
|
|
|
agent = Agent(screen, 950, 950, "Left")
|
2020-05-15 17:25:01 +02:00
|
|
|
board = create_board(screen)
|
2020-05-19 13:14:19 +02:00
|
|
|
my_tree = decision_tree.build_tree(data.learning_data)
|
2020-06-09 15:21:36 +02:00
|
|
|
products_from_supply = []
|
|
|
|
supply_depot = board[9][0]
|
2020-05-15 17:25:01 +02:00
|
|
|
|
2020-05-15 19:51:11 +02:00
|
|
|
path = []
|
|
|
|
next_step = None
|
2020-05-15 17:25:01 +02:00
|
|
|
# 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)
|
2020-06-09 15:21:36 +02:00
|
|
|
elif event.key == pygame.K_DOWN:
|
|
|
|
agent.item = None
|
|
|
|
agent.is_busy = False
|
2020-05-15 19:51:11 +02:00
|
|
|
elif event.key == pygame.K_SPACE:
|
2020-06-09 15:21:36 +02:00
|
|
|
products_from_supply = selectedSupply()
|
|
|
|
|
|
|
|
# print("Wybrano: " + board[9][0].item[-1])
|
|
|
|
# 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 len(products_from_supply) != 0 and supply_depot.is_empty is True and agent.is_busy is False:
|
|
|
|
supply_depot.item = products_from_supply.pop(0)
|
|
|
|
print(supply_depot.item)
|
|
|
|
path = functions.a_star(board[agent.y][agent.x], supply_depot, board)
|
|
|
|
path.pop(len(path) - 1)
|
|
|
|
next_step = path.pop(len(path) - 1)
|
|
|
|
agent.is_busy = True
|
|
|
|
|
|
|
|
if board[agent.y][agent.x].item and agent.item is None:
|
|
|
|
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])
|
|
|
|
new_product = FinalProduct(supply_depot.item[0], supply_depot.item[1], supply_depot.item[2],
|
|
|
|
supply_depot.item[3], prediction[0])
|
|
|
|
print(new_product)
|
|
|
|
agent.item = new_product
|
2020-05-15 17:25:01 +02:00
|
|
|
|
2020-05-15 19:51:11 +02:00
|
|
|
if next_step is not None:
|
2020-05-15 17:25:01 +02:00
|
|
|
time.sleep(0.5)
|
|
|
|
if functions.check_turn(agent, next_step):
|
|
|
|
agent.move_forward(board)
|
|
|
|
if len(path) != 0:
|
|
|
|
next_step = path.pop()
|
2020-05-15 19:51:11 +02:00
|
|
|
else:
|
|
|
|
next_step = None
|
2020-05-19 13:25:53 +02:00
|
|
|
# print(next_step, path)
|
2020-05-15 19:51:11 +02:00
|
|
|
for row in board:
|
|
|
|
for field in row:
|
|
|
|
if not field.is_shelf:
|
|
|
|
field.image = pygame.image.load('img/Field.png')
|
2020-05-19 13:14:19 +02:00
|
|
|
|
2020-05-15 17:25:01 +02:00
|
|
|
else:
|
|
|
|
functions.change_turn(agent, next_step)
|
2020-05-19 13:14:19 +02:00
|
|
|
|
2020-05-15 17:25:01 +02:00
|
|
|
draw_board(board)
|
|
|
|
agent.blitme()
|
|
|
|
|
|
|
|
pygame.display.flip()
|
|
|
|
|
|
|
|
|
|
|
|
run()
|