Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/content/basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ from pettingzoo import make

make(
"aec",
"butterfly/cooperative_pong-v6",
"butterfly/cooperative_pong-v7",
ball_speed=18,
left_paddle_speed=25,
right_paddle_speed=25,
Expand All @@ -78,7 +78,7 @@ Environments can be interacted with using a similar interface to Gymnasium:
```python
from pettingzoo import make

env = make("aec", "butterfly/cooperative_pong-v6", render_mode="human")
env = make("aec", "butterfly/cooperative_pong-v7", render_mode="human")
env.reset(seed=42)

for agent in env.agent_iter():
Expand Down
4 changes: 2 additions & 2 deletions pettingzoo/butterfly/all_modules.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pettingzoo.butterfly import (
cooperative_pong_v6,
cooperative_pong_v7,
knights_archers_zombies_v11,
pistonball_v6,
)

butterfly_environments = {
"butterfly/knights_archers_zombies_v11": knights_archers_zombies_v11,
"butterfly/pistonball_v6": pistonball_v6,
"butterfly/cooperative_pong_v6": cooperative_pong_v6,
"butterfly/cooperative_pong_v7": cooperative_pong_v7,
}
6 changes: 4 additions & 2 deletions pettingzoo/butterfly/cooperative_pong/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ def update2(self, area: pygame.Rect, p0: Paddle, p1: Paddle) -> None:
if not area.contains(self._rect):
# bottom wall
if self._rect.bottom > area.bottom:
self._rect.bottom = area.bottom
overshoot = self._rect.bottom - area.bottom
self._rect.bottom = area.bottom - overshoot
self._speed[1] = -self._speed[1]
# top wall
elif self._rect.top < area.top:
self._rect.top = area.top
overshoot = area.top - self._rect.top
self._rect.top = area.top + overshoot
self._speed[1] = -self._speed[1]

# after bouncing back from the top/bottom, if it is still out of
Expand Down
7 changes: 4 additions & 3 deletions pettingzoo/butterfly/cooperative_pong/cooperative_pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

This environment is part of the <a href='..'>butterfly environments</a>. Please read that page first for general information.

| Creation | `make("aec", "butterfly/cooperative_pong-v6")` |
| Creation | `make("aec", "butterfly/cooperative_pong-v7")` |
|----------------------|--------------------------------------------------------|
| Actions | Discrete |
| Parallel API | Yes |
Expand Down Expand Up @@ -39,7 +39,7 @@
```python
from pettingzoo import make

make("aec", "butterfly/cooperative_pong-v6",
make("aec", "butterfly/cooperative_pong-v7",
ball_speed = 9,
left_paddle_speed = 12,
right_paddle_speed = 12,
Expand Down Expand Up @@ -79,6 +79,7 @@

### Version History

* v7: Fixed incorrect ball bounce physics against the paddles and the top/bottom walls (1.26.1)
* v6: Fixed incorrect termination condition and random bounce behaviour (1.25.5)
* v5: Fixed ball teleporting bugs
* v4: Added max_reward and off_screen_penalty arguments and changed default, fixed glitch where ball would occasionally teleport, reward redesign (1.14.0)
Expand Down Expand Up @@ -448,7 +449,7 @@ class raw_env(AECEnv[AgentID, ObsType, ActionType], EzPickle):

metadata = {
"render_modes": ["human", "rgb_array"],
"name": "cooperative_pong_v6",
"name": "cooperative_pong_v7",
"is_parallelizable": True,
"render_fps": FPS,
"has_manual_policy": True,
Expand Down
8 changes: 4 additions & 4 deletions pettingzoo/butterfly/cooperative_pong/manual_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def __call__(self, observation: ObsType, agent: AgentID) -> ActionType:


if __name__ == "__main__":
from pettingzoo.butterfly import cooperative_pong_v6
from pettingzoo.butterfly import cooperative_pong_v7

# which agents will be controlled by manual policies
MANUAL_AGENTS = [0, 1]

env = cooperative_pong_v6.env(render_mode="human")
env = cooperative_pong_v7.env(render_mode="human")
env.reset()

# this allows holding down a key for continuous motion. Only a single
Expand All @@ -100,9 +100,9 @@ def __call__(self, observation: ObsType, agent: AgentID) -> ActionType:

clock = pygame.time.Clock()

manual_policies: dict[AgentID, cooperative_pong_v6.ManualPolicy] = {}
manual_policies: dict[AgentID, cooperative_pong_v7.ManualPolicy] = {}
for agent_id in MANUAL_AGENTS:
new_policy = cooperative_pong_v6.ManualPolicy(env, agent_id)
new_policy = cooperative_pong_v7.ManualPolicy(env, agent_id)
manual_policies[new_policy.agent] = new_policy

for agent in env.agent_iter():
Expand Down
12 changes: 8 additions & 4 deletions pettingzoo/butterfly/cooperative_pong/paddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ def _process_collision_with_rect(
"""
# handle collision from left or right
if self._side == PaddleLocation.PADDLE_LEFT and b_rect.left < rect.right:
b_rect.left = rect.right
overshoot = rect.right - b_rect.left
b_rect.left = rect.right + overshoot
if b_speed[0] < 0:
b_speed[0] *= -1
elif self._side == PaddleLocation.PADDLE_RIGHT and b_rect.right > rect.left:
b_rect.right = rect.left
overshoot = b_rect.right - rect.left
b_rect.right = rect.left - overshoot
if b_speed[0] > 0:
b_speed[0] *= -1
# handle collision from top
Expand All @@ -156,14 +158,16 @@ def _process_collision_with_rect(
and b_rect.top - b_speed[1] < rect.top
and b_speed[1] > 0
):
b_rect.bottom = rect.top
overshoot = b_rect.bottom - rect.top
b_rect.bottom = rect.top - overshoot
b_speed[1] *= -1
# handle collision from bottom
elif (
b_rect.top < rect.bottom
and b_rect.bottom - b_speed[1] > rect.bottom
and b_speed[1] < 0
):
b_rect.top = rect.bottom - 1
overshoot = rect.bottom - b_rect.top
b_rect.top = rect.bottom + overshoot
b_speed[1] *= -1
return True, b_rect, b_speed
2 changes: 1 addition & 1 deletion pettingzoo/env_registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _maybe_register_parallel(
_butterfly_envs = [
("knights_archers_zombies_v11", "knights_archers_zombies"),
("pistonball_v6", "pistonball"),
("cooperative_pong_v6", "cooperative_pong"),
("cooperative_pong_v7", "cooperative_pong"),
]

for _id, _base in _butterfly_envs:
Expand Down
8 changes: 4 additions & 4 deletions test/all_parameter_combs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
wizard_of_wor_v3,
)
from pettingzoo.butterfly import (
cooperative_pong_v6,
cooperative_pong_v7,
knights_archers_zombies_v11,
pistonball_v6,
)
Expand Down Expand Up @@ -85,10 +85,10 @@
volleyball_pong_v3,
{"num_players": 4, "max_cycles": 50},
],
["butterfly/cooperative_pong_v6", cooperative_pong_v6, {"max_cycles": 50}],
["butterfly/cooperative_pong_v7", cooperative_pong_v7, {"max_cycles": 50}],
[
"butterfly/cooperative_pong_v6",
cooperative_pong_v6,
"butterfly/cooperative_pong_v7",
cooperative_pong_v7,
{"bounce_randomness": True, "max_cycles": 50},
],
["classic/connect_four_v3", connect_four_v3, {}],
Expand Down
4 changes: 2 additions & 2 deletions test/pygame_init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from pettingzoo.butterfly import (
cooperative_pong_v6,
cooperative_pong_v7,
knights_archers_zombies_v11,
pistonball_v6,
)
Expand All @@ -21,7 +21,7 @@
from pettingzoo.sisl import multiwalker_v9, pursuit_v5

pygame_envs = [
cooperative_pong_v6,
cooperative_pong_v7,
knights_archers_zombies_v11,
pistonball_v6,
chess_v6,
Expand Down