Skip to content

Commit

Permalink
fix: action type
Browse files Browse the repository at this point in the history
  • Loading branch information
kir0ul committed Aug 23, 2022
1 parent f72e0f9 commit 55c69e6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pettingzoo/utils/conversions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import copy
import warnings
from collections import defaultdict
from typing import Dict, Optional

from pettingzoo.utils import agent_selector
from pettingzoo.utils.env import AECEnv, ParallelEnv
from pettingzoo.utils.wrappers import OrderEnforcingWrapper

ActionType = Optional[int]
AgentID = str
ActionDict = Dict[AgentID, ActionType]


def parallel_wrapper_fn(env_fn):
def par_fn(**kwargs):
Expand Down Expand Up @@ -231,7 +236,7 @@ def reset(self, seed=None, return_info=False, options=None):
self._observations = self.env.reset(seed=seed, options=options)
self.agents = self.env.agents[:]
self._live_agents = self.agents[:]
self._actions = {agent: None for agent in self.agents}
self._actions: ActionDict = {agent: None for agent in self.agents}
self._agent_selector = agent_selector(self._live_agents)
self.agent_selection = self._agent_selector.reset()
self.dones = {agent: False for agent in self.agents}
Expand All @@ -257,9 +262,12 @@ def add_new_agent(self, new_agent):
self.rewards[new_agent] = 0
self._cumulative_rewards[new_agent] = 0

def step(self, action: None):
def step(self, action: ActionType):
if action is not None:
action = int(action)
if self.dones[self.agent_selection]:
del self._actions[self.agent_selection]
assert action is None
return self._was_done_step(action)
self._actions[self.agent_selection] = action
if self._agent_selector.is_last():
Expand Down

0 comments on commit 55c69e6

Please sign in to comment.