From 611fda05a31e18307fbb51e2e4a39dee38f2df22 Mon Sep 17 00:00:00 2001 From: MortalreminderPT <54986457+MortalreminderPT@users.noreply.github.com> Date: Wed, 29 Mar 2023 21:53:28 +0800 Subject: [PATCH 1/3] Update unity_pettingzoo_base_env.py Modify self._current_action[current_behavior] so that actions can be passed to Unity exactly. --- .../mlagents_envs/envs/unity_pettingzoo_base_env.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py b/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py index 3457f18c88..8c40139e7a 100644 --- a/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py +++ b/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py @@ -168,11 +168,11 @@ def _process_action(self, current_agent, action): if action.continuous is not None: self._current_action[current_behavior].continuous[ current_index - ] = action.continuous[0] + ] = action.continuous if action.discrete is not None: self._current_action[current_behavior].discrete[ current_index - ] = action.discrete[0] + ] = action.discrete else: self._live_agents.remove(current_agent) del self._observations[current_agent] From fa7b0cf4e0cc73525c26f3e7fdb81d47d05df338 Mon Sep 17 00:00:00 2001 From: MortalreminderPT <54986457+MortalreminderPT@users.noreply.github.com> Date: Wed, 29 Mar 2023 22:25:49 +0800 Subject: [PATCH 2/3] Update unity_pettingzoo_base_env.py MultiDiscrete actions in Unity cannot be executed correctly, so you need to assign action.discrete directly to self._current_action[current_behavior].discrete --- ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py b/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py index 8c40139e7a..3e14d7701c 100644 --- a/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py +++ b/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py @@ -168,7 +168,7 @@ def _process_action(self, current_agent, action): if action.continuous is not None: self._current_action[current_behavior].continuous[ current_index - ] = action.continuous + ] = action.continuous[0] if action.discrete is not None: self._current_action[current_behavior].discrete[ current_index From 748384811bc3103f1ab08e0ff4b0216ad8aa7bc7 Mon Sep 17 00:00:00 2001 From: MortalreminderPT <54986457+MortalreminderPT@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:41:05 +0800 Subject: [PATCH 3/3] Update unity_pettingzoo_base_env.py verified that it can correctly assign actions in each case --- .../mlagents_envs/envs/unity_pettingzoo_base_env.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py b/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py index 3e14d7701c..68f408139c 100644 --- a/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py +++ b/ml-agents-envs/mlagents_envs/envs/unity_pettingzoo_base_env.py @@ -165,11 +165,11 @@ def _process_action(self, current_agent, action): if not self._dones[current_agent]: current_behavior = _agent_id_to_behavior(current_agent) current_index = self._agent_id_to_index[current_agent] - if action.continuous is not None: + if action.continuous.shape[-1] != 0: self._current_action[current_behavior].continuous[ current_index - ] = action.continuous[0] - if action.discrete is not None: + ] = action.continuous + if action.discrete.shape[-1] != 0: self._current_action[current_behavior].discrete[ current_index ] = action.discrete