Skip to content
Snippets Groups Projects
Commit a9d9f231 authored by u229589's avatar u229589
Browse files

Merge branch '188_refining_generator' of gitlab.aicrowd.com:flatland/flatland...

Merge branch '188_refining_generator' of gitlab.aicrowd.com:flatland/flatland into 188_refining_generator
parents 300dccdc 6d6a9f8f
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,8 @@ class GraphicsLayer(object): ...@@ -73,7 +73,8 @@ class GraphicsLayer(object):
""" """
pass pass
def set_agent_at(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False,rail_grid=None,show_debug=False): def set_agent_at(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False,rail_grid=None,show_debug=False,
clear_debug_text=True):
pass pass
def set_cell_occupied(self, iAgent, row, col): def set_cell_occupied(self, iAgent, row, col):
......
...@@ -639,7 +639,7 @@ class PILSVG(PILGL): ...@@ -639,7 +639,7 @@ class PILSVG(PILGL):
self.pil_zug[(in_direction_2, out_direction_2, color_idx)] = pils[color_idx] self.pil_zug[(in_direction_2, out_direction_2, color_idx)] = pils[color_idx]
def set_agent_at(self, agent_idx, row, col, in_direction, out_direction, is_selected, def set_agent_at(self, agent_idx, row, col, in_direction, out_direction, is_selected,
rail_grid=None, show_debug=False): rail_grid=None, show_debug=False,clear_debug_text=True):
delta_dir = (out_direction - in_direction) % 4 delta_dir = (out_direction - in_direction) % 4
color_idx = agent_idx % self.n_agent_colors color_idx = agent_idx % self.n_agent_colors
# when flipping direction at a dead end, use the "out_direction" direction. # when flipping direction at a dead end, use the "out_direction" direction.
...@@ -656,7 +656,25 @@ class PILSVG(PILGL): ...@@ -656,7 +656,25 @@ class PILSVG(PILGL):
self.clear_layer(PILGL.SELECTED_AGENT_LAYER, 0) self.clear_layer(PILGL.SELECTED_AGENT_LAYER, 0)
self.draw_image_row_col(bg_svg, (row, col), layer=PILGL.SELECTED_AGENT_LAYER) self.draw_image_row_col(bg_svg, (row, col), layer=PILGL.SELECTED_AGENT_LAYER)
if show_debug: if show_debug:
self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx)) if not clear_debug_text:
dr = 0.2
dc = 0.2
if in_direction == 0:
dr = 0.8
dc = 0.0
if in_direction == 1:
dr = 0.0
dc = 0.8
if in_direction == 2:
dr = 0.4
dc = 0.8
if in_direction == 3:
dr = 0.8
dc = 0.4
self.text_rowcol((row + dr, col + dc,), str(agent_idx), layer=PILGL.SELECTED_AGENT_LAYER)
else:
self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx))
def set_cell_occupied(self, agent_idx, row, col): def set_cell_occupied(self, agent_idx, row, col):
occupied_im = self.cell_occupied[agent_idx % len(self.cell_occupied)] occupied_im = self.cell_occupied[agent_idx % len(self.cell_occupied)]
......
...@@ -41,7 +41,7 @@ class RenderTool(object): ...@@ -41,7 +41,7 @@ class RenderTool(object):
def __init__(self, env, gl="PILSVG", jupyter=False, def __init__(self, env, gl="PILSVG", jupyter=False,
agent_render_variant=AgentRenderVariant.ONE_STEP_BEHIND, agent_render_variant=AgentRenderVariant.ONE_STEP_BEHIND,
show_debug=False, screen_width=800, screen_height=600): show_debug=False, clear_debug_text=True,screen_width=800, screen_height=600):
self.env = env self.env = env
self.frame_nr = 0 self.frame_nr = 0
...@@ -60,6 +60,7 @@ class RenderTool(object): ...@@ -60,6 +60,7 @@ class RenderTool(object):
self.new_rail = True self.new_rail = True
self.show_debug = show_debug self.show_debug = show_debug
self.clear_debug_text = clear_debug_text
self.update_background() self.update_background()
def reset(self): def reset(self):
...@@ -556,7 +557,8 @@ class RenderTool(object): ...@@ -556,7 +557,8 @@ class RenderTool(object):
if self.agent_render_variant == AgentRenderVariant.ONE_STEP_BEHIND_AND_BOX: if self.agent_render_variant == AgentRenderVariant.ONE_STEP_BEHIND_AND_BOX:
self.gl.set_cell_occupied(agent_idx, *(agent.position)) self.gl.set_cell_occupied(agent_idx, *(agent.position))
self.gl.set_agent_at(agent_idx, *position, old_direction, direction, self.gl.set_agent_at(agent_idx, *position, old_direction, direction,
selected_agent == agent_idx, rail_grid=env.rail.grid, show_debug=self.show_debug) selected_agent == agent_idx, rail_grid=env.rail.grid,
show_debug=self.show_debug,clear_debug_text=self.clear_debug_text)
else: else:
position = agent.position position = agent.position
direction = agent.direction direction = agent.direction
...@@ -569,7 +571,7 @@ class RenderTool(object): ...@@ -569,7 +571,7 @@ class RenderTool(object):
# set_agent_at uses the agent index for the color # set_agent_at uses the agent index for the color
self.gl.set_agent_at(agent_idx, *position, agent.direction, direction, self.gl.set_agent_at(agent_idx, *position, agent.direction, direction,
selected_agent == agent_idx, rail_grid=env.rail.grid, selected_agent == agent_idx, rail_grid=env.rail.grid,
show_debug=self.show_debug) show_debug=self.show_debug,clear_debug_text=self.clear_debug_text)
# set_agent_at uses the agent index for the color # set_agent_at uses the agent index for the color
if self.agent_render_variant == AgentRenderVariant.AGENT_SHOWS_OPTIONS_AND_BOX: if self.agent_render_variant == AgentRenderVariant.AGENT_SHOWS_OPTIONS_AND_BOX:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment