Skip to content

Fix cooperative_pong ball bounce physics (v7) — supersedes #1336 - #1398

Open
RewardGuard wants to merge 7 commits into
Farama-Foundation:mainfrom
RewardGuard:pong-physics-v7
Open

RewardGuard wants to merge 7 commits into
Farama-Foundation:mainfrom
RewardGuard:pong-physics-v7

Conversation

@RewardGuard

Copy link
Copy Markdown
Contributor

Description

Supersedes #1336 (which had merge conflicts and a failing CI) and fixes #1289.

Cooperative pong resolved collisions by snapping the ball's position exactly onto the colliding surface, throwing away the distance the ball had already travelled past the wall/paddle during that step. The correct behaviour is to reflect that overshoot back out of the surface, so the bounce conserves the ball's motion within the step.

This PR:

  • ball.py — reflects the overshoot on top/bottom wall bounces instead of clamping to the wall.
  • paddle.py — reflects the overshoot on all four paddle-collision cases (left/right/top/bottom) instead of clamping to the paddle edge.
  • Bumps cooperative_pong_v6v7 (the physics change alters environment dynamics) and updates every reference: the version module, all_modules.py, the env registry, docs, and tests.
  • Adds a v7 entry to the Version History.

Rebased cleanly on current main, so there are no merge conflicts (the pyproject.toml/pygame_init_test fixes that #1336 carried are already present on main).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

Checklist:

  • I have run pytest for the affected env (api_test, parallel_api_test, seed_test all pass for cooperative_pong_v7).
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • New and existing unit tests pass locally with my changes.

🤖 Generated with Claude Code

@jkterry1

Copy link
Copy Markdown
Member

@RewardGuard I apologize for the hassle, but could you please rebase your changes off main?

@virgilt

virgilt commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@RewardGuard there's merge conflicts.

The ball previously had its position clamped exactly to the colliding
surface on a bounce, discarding the distance it had already overshot past
the wall/paddle within that step. This made bounces lose energy/precision
and could let the ball clip through fast collisions.

Reflect the overshoot back out of the surface instead of clamping, in both
the top/bottom wall handling (ball.py) and the paddle collision handling
(paddle.py). Because this changes environment dynamics, bump
cooperative_pong_v6 -> v7 and update all references, docs, tests and the
env registry accordingly.

Supersedes Farama-Foundation#1336, fixes Farama-Foundation#1289.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tzh476 added a commit to tzh476/PettingZoo that referenced this pull request Sep 8, 2026
The detector cut two fixed column bands and treated the rest as the ball. The
right paddle is four stacked rectangles spanning columns 420-479, so the band
wide enough to hold it also hid every ball in the last 60px of the frame.

That is latent on v6 and load-bearing on v7. Applying Farama-Foundation#1398 locally and running
the documented config:

                       seeds 0-49          seeds 1000-1049
    fixed columns      96.18, 47/50        98.88, 49/50
    edge connectivity  100.00, 50/50       100.00, 50/50

On v6 both give 100.00, 50/50, so this is not a regression there. The failures
are not caused by the new bounce physics: replacing only the perception step
with the environment's true rectangles, and leaving the control rule alone,
restores 50/50 on v7.

Both paddles are anchored to a screen edge and the ball never is, so the lit
run reaching each edge is that paddle and anything lit between them is the
ball. Checked against the environment's own rectangles over 18,000 frames, on
both versions, the detector never misreads the ball except while it is touching
a paddle, by which point the bounce is already decided.

The GIF is regenerated because the detector changes 1.2% of the actions.

Change-Id: Ia718e1a3a6eeac557692ad0c26ff931348b6f440
Co-Authored-By: Claude Code <noreply@anthropic.com>
@jkterry1

Copy link
Copy Markdown
Member

@tzh476 do you mind looking at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] Cooperative pong wall bounce physics is wrong

3 participants