mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-05-23 07:16:44 +02:00
centered the arrows and text for better readability in plt action maps and added colored arrow assets
This commit is contained in:
parent
0e09094f97
commit
28094bf4ce
BIN
marl_factory_grid/utils/plotting/action_assets/green_arrow.png
Normal file
BIN
marl_factory_grid/utils/plotting/action_assets/green_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 455 B |
BIN
marl_factory_grid/utils/plotting/action_assets/grey_arrow.png
Normal file
BIN
marl_factory_grid/utils/plotting/action_assets/grey_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 425 B |
BIN
marl_factory_grid/utils/plotting/action_assets/red_arrow.png
Normal file
BIN
marl_factory_grid/utils/plotting/action_assets/red_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 439 B |
BIN
marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png
Normal file
BIN
marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 443 B |
@ -121,7 +121,7 @@ def plot_routes(factory, agents):
|
|||||||
|
|
||||||
|
|
||||||
def plot_action_maps(factory, agents):
|
def plot_action_maps(factory, agents):
|
||||||
renderer = Renderer(factory.map.level_shape, custom_assets_path={
|
renderer = Renderer(factory.map.level_shape, cell_size=80, custom_assets_path={
|
||||||
'green_arrow': 'marl_factory_grid/utils/plotting/action_assets/green_arrow.png',
|
'green_arrow': 'marl_factory_grid/utils/plotting/action_assets/green_arrow.png',
|
||||||
'yellow_arrow': 'marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png',
|
'yellow_arrow': 'marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png',
|
||||||
'red_arrow': 'marl_factory_grid/utils/plotting/action_assets/red_arrow.png',
|
'red_arrow': 'marl_factory_grid/utils/plotting/action_assets/red_arrow.png',
|
||||||
|
@ -278,7 +278,7 @@ class Renderer:
|
|||||||
walls which cover the entire grid cell.
|
walls which cover the entire grid cell.
|
||||||
"""
|
"""
|
||||||
self.fill_bg()
|
self.fill_bg()
|
||||||
font = pygame.font.Font(None, 18)
|
font = pygame.font.Font(None, 20)
|
||||||
|
|
||||||
# prepare position dict to iterate over
|
# prepare position dict to iterate over
|
||||||
position_dict = defaultdict(list)
|
position_dict = defaultdict(list)
|
||||||
@ -286,18 +286,7 @@ class Renderer:
|
|||||||
position_dict[tuple(entity.pos)].append(entity)
|
position_dict[tuple(entity.pos)].append(entity)
|
||||||
|
|
||||||
for position, entities in position_dict.items():
|
for position, entities in position_dict.items():
|
||||||
num_entities = len(entities)
|
|
||||||
entity_size = self.cell_size // 2 # Adjust size to fit multiple entities for non-wall entities
|
entity_size = self.cell_size // 2 # Adjust size to fit multiple entities for non-wall entities
|
||||||
|
|
||||||
# Define offsets for each direction based on a quadrant layout within the cell
|
|
||||||
offsets = {
|
|
||||||
0: (-entity_size // 2, -entity_size // 2), # North
|
|
||||||
90: (-entity_size // 2, entity_size // 2), # East
|
|
||||||
180: (entity_size // 2, entity_size // 2), # South
|
|
||||||
270: (entity_size // 2, -entity_size // 2) # West
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sort entities based on direction to ensure consistent positioning
|
|
||||||
entities.sort(key=lambda x: x.rotation)
|
entities.sort(key=lambda x: x.rotation)
|
||||||
|
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
@ -306,31 +295,37 @@ class Renderer:
|
|||||||
print(f"Error: No asset available for '{entity.name}'. Skipping rendering this entity.")
|
print(f"Error: No asset available for '{entity.name}'. Skipping rendering this entity.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
img = pygame.transform.rotate(img, entity.rotation)
|
|
||||||
|
|
||||||
# Check if the entity is a wall and adjust the size and position accordingly
|
# Check if the entity is a wall and adjust the size and position accordingly
|
||||||
if entity.name == 'wall':
|
if entity.name == 'wall':
|
||||||
img = pygame.transform.scale(img, (self.cell_size, self.cell_size))
|
img = pygame.transform.scale(img, (self.cell_size, self.cell_size))
|
||||||
img_rect = img.get_rect(center=(position[0] * self.cell_size + self.cell_size // 2,
|
img_rect = img.get_rect(center=(position[0] * self.cell_size + self.cell_size // 2,
|
||||||
position[1] * self.cell_size + self.cell_size // 2))
|
position[1] * self.cell_size + self.cell_size // 2))
|
||||||
else:
|
else:
|
||||||
img = pygame.transform.scale(img, (entity_size, entity_size)) # Scale down the image for arrows
|
# Define offsets for each direction based on a quadrant layout within the cell
|
||||||
|
offsets = {
|
||||||
|
0: (0, -entity_size // 2), # North
|
||||||
|
90: (-entity_size // 2, 0), # West
|
||||||
|
180: (0, entity_size // 2), # South
|
||||||
|
270: (entity_size // 2, 0) # East
|
||||||
|
}
|
||||||
|
img = pygame.transform.scale(img, (int(entity_size), entity_size))
|
||||||
offset = offsets.get(entity.rotation, (0, 0))
|
offset = offsets.get(entity.rotation, (0, 0))
|
||||||
img_rect = img.get_rect(center=(
|
img_rect = img.get_rect(center=(
|
||||||
position[0] * self.cell_size + self.cell_size // 2 + offset[0],
|
position[0] * self.cell_size + self.cell_size // 2 + offset[0],
|
||||||
position[1] * self.cell_size + self.cell_size // 2 + offset[1]
|
position[1] * self.cell_size + self.cell_size // 2 + offset[1]
|
||||||
))
|
))
|
||||||
|
|
||||||
|
img = pygame.transform.rotate(img, entity.rotation)
|
||||||
self.screen.blit(img, img_rect)
|
self.screen.blit(img, img_rect)
|
||||||
|
|
||||||
# Render the probability next to the icon if it exists and is non-zero
|
# Render the probability next to the icon if it exists and is non-zero
|
||||||
if entity.probability > 0 and entity.name != 'wall':
|
if entity.probability > 0 and entity.name != 'wall':
|
||||||
formatted_probability = f"{entity.probability:.4f}"
|
formatted_probability = f"{entity.probability * 100:.2f}"
|
||||||
prob_text = font.render(formatted_probability, True, (0, 0, 0)) # Black color for readability
|
prob_text = font.render(formatted_probability, True, (0, 0, 0))
|
||||||
prob_text_rect = prob_text.get_rect(center=img_rect.center) # Center text on the arrow
|
prob_text_rect = prob_text.get_rect(center=img_rect.center) # Center text on the arrow
|
||||||
self.screen.blit(prob_text, prob_text_rect)
|
self.screen.blit(prob_text, prob_text_rect)
|
||||||
|
|
||||||
pygame.display.flip() # Update the display
|
pygame.display.flip()
|
||||||
self.save_screen("multi_action_graph")
|
self.save_screen("multi_action_graph")
|
||||||
|
|
||||||
def save_screen(self, filename):
|
def save_screen(self, filename):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user