def __draw_base_img(self): self._base_img = draw_grid(self._grid_shape[0], self._grid_shape[1], cell_size=CELL_SIZE, fill='white') for row in range(self._grid_shape[0]): for col in range(self._grid_shape[1]): if PRE_IDS['wall'] in self._full_obs[row][col]: fill_cell(self._base_img, (row, col), cell_size=CELL_SIZE, fill=WALL_COLOR, margin=0.05) elif PRE_IDS['lemon'] in self._full_obs[row][col]: fill_cell(self._base_img, (row, col), cell_size=CELL_SIZE, fill=LEMON_COLOR, margin=0.05) elif PRE_IDS['apple'] in self._full_obs[row][col]: fill_cell(self._base_img, (row, col), cell_size=CELL_SIZE, fill=APPLE_COLOR, margin=0.05)
def __draw_base_img(self): self._base_img = draw_grid(self._grid_shape[0], self._grid_shape[1], cell_size=CELL_SIZE, fill='white') for row in range(self._grid_shape[0]): for col in range(self._grid_shape[1]): if self.__wall_exists((row, col)): fill_cell(self._base_img, (row, col), cell_size=CELL_SIZE, fill=WALL_COLOR) for agent_i, pos in list(self.final_agent_pos.items())[:self.n_agents]: row, col = pos[0], pos[1] draw_cell_outline(self._base_img, (row, col), cell_size=CELL_SIZE, fill=AGENT_COLORS[agent_i])
def __draw_base_img(self): # create grid and make everything black img = draw_grid(self._grid_shape[0], self._grid_shape[1], cell_size=CELL_SIZE, fill=WALL_COLOR) # draw tracks for i, row in enumerate(self._full_obs): for j, col in enumerate(row): if col == PRE_IDS['empty']: fill_cell(img, (i, j), cell_size=CELL_SIZE, fill='white', margin=0.05) return img
def __init__(self, grid_shape: Coordinates = (5, 5), n_agents: int = 2, n_trees: int = 12, agent_view: Tuple[int, int] = (1, 1), full_observable: bool = False, step_cost: float = -1, tree_cutdown_reward: float = 10, max_steps: int = 100): assert 0 < n_agents assert n_agents + n_trees <= np.prod(grid_shape) assert 1 <= agent_view[0] <= grid_shape[0] and 1 <= agent_view[1] <= grid_shape[1] self._grid_shape = grid_shape self.n_agents = n_agents self._n_trees = n_trees self._agent_view = agent_view self.full_observable = full_observable self._step_cost = step_cost self._tree_cutdown_reward = tree_cutdown_reward self._max_steps = max_steps self.steps_beyond_done = 0 self.seed() self._agents = [] # List[Agent] # In order to speed up the environment we used the advantage of vector operations. # Therefor we need to pad the grid size by the maximum agent_view size. # Relative coordinates refer to the coordinates in non pad grid. These are the only # coordinates visible to user. Extended coordinates refer to the coordinates in pad grid. self._agent_map = None self._tree_map = None self._total_episode_reward = None self._agent_dones = None mask_size = np.prod(tuple(2 * v + 1 for v in self._agent_view)) # Agent ID (1) + Pos (2) + Step (1) + Neighborhood (2 * mask_size) self._obs_len = (1 + 2 + 1 + 2 * mask_size) obs_high = np.array([1.] * self._obs_len) obs_low = np.array([0.] * self._obs_len) if self.full_observable: obs_high = np.tile(obs_high, self.n_agents) obs_low = np.tile(obs_low, self.n_agents) self.action_space = MultiAgentActionSpace([spaces.Discrete(5)] * self.n_agents) self.observation_space = MultiAgentObservationSpace([spaces.Box(obs_low, obs_high)] * self.n_agents) self._base_img = draw_grid(self._grid_shape[0], self._grid_shape[1], cell_size=CELL_SIZE, fill='white') self._viewer = None
def __draw_base_img(self): self._base_img = draw_grid(self._grid_shape[0], self._grid_shape[1], cell_size=CELL_SIZE, fill='white')