Skip to content

Commit

Permalink
Fix knights_archers_zombies render FPS, manual_control script (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniGrotto authored Aug 30, 2023
1 parent 1742c8d commit f0c94c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/environments/butterfly.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions pettingzoo/butterfly/cooperative_pong/cooperative_pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def __init__(
render_mode=None,
render_ratio=2,
kernel_window_length=2,
render_fps=15,
):
super().__init__()

Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f0c94c6

Please sign in to comment.