Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions gym-unity/gym_unity/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
self._env.step()

self.visual_obs = None
self._n_agents = -1

# Save the step result from the last time all Agents requested decisions.
self._previous_decision_step: DecisionSteps = None
Expand Down Expand Up @@ -172,6 +171,7 @@ def step(self, action: List[Any]) -> GymStepResult:

self._env.step()
decision_step, terminal_step = self._env.get_steps(self.name)
self._check_agents(max(len(decision_step), len(terminal_step)))
if len(terminal_step) != 0:
# The agent is done
self.game_over = True
Expand Down Expand Up @@ -264,10 +264,11 @@ def seed(self, seed: Any = None) -> None:
logger.warning("Could not seed environment %s", self.name)
return

def _check_agents(self, n_agents: int) -> None:
if self._n_agents > 1:
@staticmethod
def _check_agents(n_agents: int) -> None:
if n_agents > 1:
raise UnityGymException(
"There can only be one Agent in the environment but {n_agents} were detected."
f"There can only be one Agent in the environment but {n_agents} were detected."
)

@property
Expand All @@ -290,10 +291,6 @@ def action_space(self):
def observation_space(self):
return self._observation_space

@property
def number_agents(self):
return self._n_agents


class ActionFlattener:
"""
Expand Down
6 changes: 3 additions & 3 deletions ml-agents-envs/mlagents_envs/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ def set_actions(self, behavior_name: BehaviorName, action: np.ndarray) -> None:
expected_shape = (len(self._env_state[behavior_name][0]), spec.action_size)
if action.shape != expected_shape:
raise UnityActionException(
"The behavior {0} needs an input of dimension {1} but received input of dimension {2}".format(
behavior_name, expected_shape, action.shape
)
"The behavior {0} needs an input of dimension {1} for "
"(<number of agents>, <action size>) but received input of "
"dimension {2}".format(behavior_name, expected_shape, action.shape)
)
if action.dtype != expected_type:
action = action.astype(expected_type)
Expand Down