AL-2020/main.py

78 lines
2.5 KiB
Python
Raw Normal View History

2020-05-15 17:25:01 +02:00
import pygame
import functions
import sys
import time
from agent import Agent
from settings import Settings
from board import create_board, draw_board
2020-05-15 19:51:11 +02:00
from random import randint
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")
agent = Agent(screen, 50, 50, "Down")
board = create_board(screen)
for row in board:
for field in row:
print(field.cost_of_travel)
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-05-15 19:51:11 +02:00
print(agent.x, agent.y)
elif event.key == pygame.K_SPACE:
field = board[randint(0, 9)][randint(0, 9)]
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)
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)
2020-05-15 19:51:11 +02:00
2020-05-15 17:25:01 +02:00
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
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')
for row in board:
for field in row:
print(field.g, field.h, field.f, field.previous)
2020-05-15 17:25:01 +02:00
else:
functions.change_turn(agent, next_step)
2020-05-15 19:51:11 +02:00
print(agent.x, agent.y)
2020-05-15 17:25:01 +02:00
draw_board(board)
agent.blitme()
pygame.display.flip()
run()