Skip to content

Resolve issue with duo/trio/quad team forming logic - #4758

Open
SGunner2014 wants to merge 2 commits into
openfrontio:mainfrom
SGunner2014:bugfix/4253-fix-group-pairings
Open

Resolve issue with duo/trio/quad team forming logic#4758
SGunner2014 wants to merge 2 commits into
openfrontio:mainfrom
SGunner2014:bugfix/4253-fix-group-pairings

Conversation

@SGunner2014

Copy link
Copy Markdown

Add approved & assigned issue number here:

Resolves #4253

Description:

This resolves an issue with duos/trios/quads where humans would be automatically assigned to the emptiest teams, thereby resulting in combinations of humans + nations fighting each other, whereas the preferred behaviour is for humans to be put together where possible.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory

Please put your Discord username so you can be contacted if a bug or regression is found:

sjg.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Team assignment now receives explicit Duos/Trios/Quads context. Human placement prefers fuller teams in these modes, and both game assignment and lobby previews pass the new flag. Tests cover legacy behavior and nation pairing.

Changes

Team packing behavior

Layer / File(s) Summary
Mode-aware team assignment
src/core/game/TeamAssignment.ts
assignTeams and lobby previews accept the mode flag and prefer fuller teams for equal friend counts in Duos, Trios, and Quads.
Game and lobby wiring
src/core/game/GameImpl.ts, src/client/components/LobbyPlayerView.ts
Game assignment and lobby previews derive and pass the Duos/Trios/Quads flag.
Assignment validation
tests/TeamAssignment.test.ts
Existing tests use the explicit non-special-mode flag, and new tests verify human packing and nation placement across mode sizes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: Gameplay

Suggested reviewers: evanpelle, developingtom

Poem

Humans gather, nations align,
Duos and Trios form a line.
Quads now pack with thoughtful cheer,
The lobby preview matches what’s near.
Teams find balance, clear and bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes update team assignment, call sites, and tests to pack humans in duos/trios/quads while keeping explicit counts spread out.
Out of Scope Changes check ✅ Passed The summary shows only issue-related logic, call-site, and test updates with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly matches the main change: duo/trio/quad team forming logic was updated.
Description check ✅ Passed The description is directly related to the change and explains the duo/trio/quad team grouping fix.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/core/game/TeamAssignment.ts (1)

107-120: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Put friend groups before friendless humans.

The new tie-breaker cannot preserve a friend pair when a friendless human is processed first. In Duos, [friendless, A↔B] fills the first team with friendless + A, forcing B onto another team. Partition humans with present friends before friendless humans before placement, and add this regression case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/game/TeamAssignment.ts` around lines 107 - 120, The team-placement
flow in TeamAssignment must prioritize humans with existing friends before
friendless humans. Partition or order the input before placement so
friend-connected players are processed first, then add a regression case
covering a friendless player preceding an A↔B pair and verify the pair remains
together.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/core/game/TeamAssignment.ts`:
- Around line 107-120: The team-placement flow in TeamAssignment must prioritize
humans with existing friends before friendless humans. Partition or order the
input before placement so friend-connected players are processed first, then add
a regression case covering a friendless player preceding an A↔B pair and verify
the pair remains together.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: be14334f-cc5f-4e20-9b93-807172f79f7a

📥 Commits

Reviewing files that changed from the base of the PR and between ad3fcbe and 4be62af.

📒 Files selected for processing (4)
  • src/client/components/LobbyPlayerView.ts
  • src/core/game/GameImpl.ts
  • src/core/game/TeamAssignment.ts
  • tests/TeamAssignment.test.ts

@SGunner2014
SGunner2014 marked this pull request as ready for review July 28, 2026 20:51
@SGunner2014
SGunner2014 requested a review from a team as a code owner July 28, 2026 20:51
@SGunner2014

Copy link
Copy Markdown
Author

Looking at the review from coderabbit, I can see this is outside the scope of the original ticket because it's behaviour that was already present in the code before I made changes. I can update the PR to include a fix to this flagged issue also, if this is preferred?

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

Duos/Trios/Quads: humans are spread across teams and paired with nations instead of each other

1 participant