Skip to content

Commit

Permalink
refactor: Make default default reward methods static
Browse files Browse the repository at this point in the history
  • Loading branch information
Puckoland committed Oct 1, 2024
1 parent aa196ac commit 32e8cf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions generals/integrations/gymnasium_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self.replay = None

self.render_mode = render_mode
self.reward_fn = self.default_reward if reward_fn is None else reward_fn
self.reward_fn = self._default_reward if reward_fn is None else reward_fn
self.grid_factory = grid_factory

self.agent_name = agent.name
Expand Down Expand Up @@ -118,8 +118,9 @@ def step(self, action: Action) -> tuple[Observation, SupportsFloat, bool, bool,

return observation, reward, terminated, truncated, info

def default_reward(
self, observation: dict[str, Observation],
@staticmethod
def _default_reward(
observation: dict[str, Observation],
action: Action,
done: bool,
info: Info,
Expand Down
6 changes: 3 additions & 3 deletions generals/integrations/pettingzoo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
len(self.possible_agents) == len(set(self.possible_agents))
), "Agent names must be unique - you can pass custom names to agent constructors."

self.reward_fn = self.default_reward if reward_fn is None else reward_fn
self.reward_fn = self._default_reward if reward_fn is None else reward_fn

@functools.lru_cache(maxsize=None)
def observation_space(self, agent: AgentID) -> spaces.Space:
Expand Down Expand Up @@ -126,8 +126,8 @@ def step(self, actions: dict[AgentID, Action]) -> tuple[

return observations, rewards, terminated, truncated, infos

def default_reward(
self,
@staticmethod
def _default_reward(
observation: dict[str, Observation],
action: Action,
done: bool,
Expand Down

0 comments on commit 32e8cf7

Please sign in to comment.