diff --git a/docs/environments/butterfly.md b/docs/environments/butterfly.md index aa008be1b..4e1262c03 100644 --- a/docs/environments/butterfly.md +++ b/docs/environments/butterfly.md @@ -57,14 +57,14 @@ from pettingzoo.butterfly import knights_archers_zombies_v10 env = knights_archers_zombies_v10.env(render_mode="human") env.reset(seed=42) -clock = pygame.time.Clock() manual_policy = knights_archers_zombies_v10.ManualPolicy(env) for agent in env.agent_iter(): - clock.tick(env.metadata["render_fps"]) observation, reward, termination, truncation, info = env.last() - if agent == manual_policy.agent: + if termination or truncation: + action = None + elif agent == manual_policy.agent: # get user input (controls are WASD and space) action = manual_policy(observation, agent) else: diff --git a/pettingzoo/butterfly/cooperative_pong/cooperative_pong.py b/pettingzoo/butterfly/cooperative_pong/cooperative_pong.py index b0665dc2e..44b1492a8 100644 --- a/pettingzoo/butterfly/cooperative_pong/cooperative_pong.py +++ b/pettingzoo/butterfly/cooperative_pong/cooperative_pong.py @@ -147,6 +147,7 @@ def __init__( render_mode=None, render_ratio=2, kernel_window_length=2, + render_fps=15, ): super().__init__() @@ -211,6 +212,10 @@ def __init__( self.reinit() + self.render_fps = render_fps + if self.render_mode == "human": + self.clock = pygame.time.Clock() + def reinit(self): self.rewards = dict(zip(self.agents, [0.0] * len(self.agents))) self.terminations = dict(zip(self.agents, [False] * len(self.agents))) @@ -271,6 +276,7 @@ def render(self): observation = np.array(pygame.surfarray.pixels3d(self.screen)) if self.render_mode == "human": pygame.display.flip() + self.clock.tick(self.render_fps) return ( np.transpose(observation, axes=(1, 0, 2)) if self.render_mode == "rgb_array"