Update main.py

This commit is contained in:
Miron 2021-05-09 23:47:54 +02:00
parent 0529f89343
commit 4858436e9e

View File

@ -25,12 +25,12 @@ def get_position_from_pix(pix_pos):
WAREHOUSE_MAP = [
[0, 0, 0, 10, 10, 0, 0, 0, 0],
[0, 10, 0, 10, 0, 10, 0, 0, 0],
[0, 10, 0, 0, 0, 200, 200, 200, 200],
[0, 0, 10, 0, 0, 0, 0, 0, 0],
[0, 0, 10, 0, 0, 200, 200, 200, 200],
[0, 0, 10, 10, 0, 0, 0, 0, 0],
[10, 0, 0, 0, 10, 200, 200, 200, 200],
[10, 10, 0, 10, 0, 10, 0, 0, 0],
[10, 10, 0, 0, 0, 200, 200, 200, 200],
[10, 0, 10, 0, 0, 0, 0, 0, 0],
[10, 10, 10, 0, 0, 200, 200, 200, 200],
[10, 10, 10, 10, 0, 0, 0, 0, 0],
[10, 10, 0, 0, 10, 200, 200, 200, 200],
[0, 0, 10, 10, 10, 0, 0, 0, 0],
[0, 10, 0, 0, 0, 200, 200, 200, 200],
]
@ -136,14 +136,14 @@ def a_star_search(start, end, agent_direction):
path = []
current = current_node
while current is not None:
#path.append(current.position)
# path.append(current.position)
if current.action is not None:
current.action.reverse()
for each_action in current.action:
path.append(each_action)
current = current.parent
#path = path.pop()
# path = path.pop()
return path[::-1]
#
@ -226,7 +226,6 @@ class NodeAStar:
return self.position == other.position
class Node:
def __init__(self, state, agent_direction, action=None, parent=None):
self.state = state
@ -410,11 +409,9 @@ class Agent:
board = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA) # transparently surface
create_positions()
#Rysowanie lini
# Rysowanie lini
for x in range(9):
for y in range(9):
pygame.draw.rect(board, (0, 0, 0), (x * size, y * size, size, size), 3)
@ -439,24 +436,22 @@ Package_list = [
generate_package(40, 40)
]
print(a_star_search((6, 8), (0, 0), "down"))
#agent.path = breadth_first_search(agent.pos_coord, agent.agent_direction)
# agent.path = breadth_first_search(agent.pos_coord, agent.agent_direction)
agent.path = a_star_search((agent.pos_coord[1], agent.pos_coord[0]), (0, 0), agent.agent_direction)
print(agent.path)
Stain_list = []
# Pętla służąca do tworzenia plam oleju na podstawie mapy magazynu
for index_x in range(9):
for index_y in range(9):
if WAREHOUSE_MAP[index_x][index_y] == 10:
Stain_list.append(Stain((index_y, index_x)))
running = True
running = True
while running:
time.sleep(0.25)
for event in pygame.event.get():
@ -498,7 +493,8 @@ while running:
agent.goal_achieved = False
# agent.path = breadth_first_search(agent.pos_coord, agent.agent_direction)
agent.path = a_star_search((agent.pos_coord[1], agent.pos_coord[0]), (agent.goal[1], agent.goal[0]), agent.agent_direction)
agent.path = a_star_search((agent.pos_coord[1], agent.pos_coord[0]), (agent.goal[1], agent.goal[0]),
agent.agent_direction)
# DRAWING
screen.blit(BACKGROUND, [0, 0])