mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-23 12:01:36 +02:00
added valid move viz.
This commit is contained in:
environments/factory
@ -29,7 +29,7 @@ class Renderer:
|
||||
self.screen = pygame.display.set_mode(self.screen_size)
|
||||
self.clock = pygame.time.Clock()
|
||||
assets = list((Path(__file__).parent / 'assets').rglob('*.png'))
|
||||
self.assets = {path.stem: self.load_asset(str(path), 0.97) for path in assets}
|
||||
self.assets = {path.stem: self.load_asset(str(path), 0.96) for path in assets}
|
||||
self.fill_bg()
|
||||
|
||||
def fill_bg(self):
|
||||
@ -76,7 +76,7 @@ class Renderer:
|
||||
visibility_rect = bp['dest'].inflate((self.view_radius*2)*self.cell_size, (self.view_radius*2)*self.cell_size)
|
||||
shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA)
|
||||
pygame.draw.rect(shape_surf, self.WHITE, shape_surf.get_rect())
|
||||
shape_surf.set_alpha(96)
|
||||
shape_surf.set_alpha(70)
|
||||
self.screen.blit(shape_surf, visibility_rect)
|
||||
self.screen.blit(**bp)
|
||||
pygame.display.flip()
|
||||
|
@ -39,11 +39,12 @@ class GettingDirty(BaseFactory):
|
||||
height, width = self.state.shape[1:]
|
||||
self.renderer = Renderer(width, height, view_radius=2)
|
||||
|
||||
dirt = [Entity('dirt', [x, y], min(1.1*self.state[DIRT_INDEX, x, y], 1), 'opacity')
|
||||
dirt = [Entity('dirt', [x, y], min(1.5*self.state[DIRT_INDEX, x, y], 1), 'opacity')
|
||||
for x, y in np.argwhere(self.state[DIRT_INDEX] > h.IS_FREE_CELL)]
|
||||
walls = [Entity('wall', pos) for pos in np.argwhere(self.state[h.LEVEL_IDX] > h.IS_FREE_CELL)]
|
||||
violation = lambda agent: agent.action_valid and agent.collision_vector[h.LEVEL_IDX] <= 0
|
||||
agents = {f'agent{i+1}': [Entity(f'agent{i+1}' if violation(agent) else f'agent{i+1}violation', agent.pos)]
|
||||
asset_str = lambda agent: f'agent{agent.i+1}violation' if (not agent.action_valid or agent.collision_vector[h.LEVEL_IDX] > 0)\
|
||||
else (f'agent{agent.i+1}valid' if self._is_clean_up_action(agent.action) else f'agent{agent.i+1}')
|
||||
agents = {f'agent{i+1}': [Entity(asset_str(agent), agent.pos)]
|
||||
for i, agent in enumerate(self.agent_states)}
|
||||
self.renderer.render(OrderedDict(dirt=dirt, wall=walls, **agents))
|
||||
|
||||
|
Reference in New Issue
Block a user