59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import pygame
|
|
import random
|
|
import a_star
|
|
|
|
from pygame.locals import *
|
|
from Forklift import Forklift
|
|
|
|
HORIZONTAL = 1250
|
|
VERTICAL = 750
|
|
|
|
TILE_SIZE = 50
|
|
|
|
|
|
def handle_turn(initial_state, turn_count):
|
|
if turn_count % 2 == 0:
|
|
commands = a_star.a_star(state=initial_state, goal=(7, 23))
|
|
else:
|
|
row = random.randint(0, 1) * 10 + 2 * random.randint(0, 2)
|
|
col = random.randint(1, 5) + 6 * random.randint(0, 3)
|
|
commands = a_star.a_star(state=initial_state, goal=(row, col))
|
|
print('I need to go to row: ' + str(row) + ' column: ' + str(col))
|
|
return commands
|
|
|
|
|
|
class Program:
|
|
def __init__(self):
|
|
pygame.init()
|
|
self.window = pygame.display.set_mode((HORIZONTAL, VERTICAL))
|
|
self.caption = pygame.display.set_caption('Autonomiczny wózek widłowy')
|
|
self.agent = Forklift(self.window)
|
|
self.agent.drawForklift()
|
|
|
|
running = True
|
|
turn_count = 0
|
|
|
|
initial_state = a_star.State(row=int(self.agent.y/50), column=int(self.agent.x/50),
|
|
direction=self.agent.direction)
|
|
|
|
while running:
|
|
commands = handle_turn(initial_state=initial_state, turn_count=turn_count)
|
|
|
|
while commands:
|
|
pygame.event.poll()
|
|
step = commands.pop(0)
|
|
if step == 'rotate_left':
|
|
self.agent.rotate_forklift_left()
|
|
elif step == 'rotate_right':
|
|
self.agent.rotate_forklift_right()
|
|
elif step == 'go':
|
|
self.agent.forklift_move()
|
|
pygame.time.delay(250)
|
|
print(commands)
|
|
turn_count += 1
|
|
pygame.time.delay(2000)
|
|
|
|
initial_state.row = int(self.agent.y / 50)
|
|
initial_state.column = int(self.agent.x / 50)
|
|
initial_state.direction = self.agent.direction
|