Skip to content

Fix preset alliance teams being randomised by draft-order shuffle - #115

Merged
shenanigans-be merged 1 commit into
shenanigans-be:mainfrom
nrkovacs:fix/preset-alliance-teams
Jul 16, 2026
Merged

Fix preset alliance teams being randomised by draft-order shuffle#115
shenanigans-be merged 1 commit into
shenanigans-be:mainfrom
nrkovacs:fix/preset-alliance-teams

Conversation

@nrkovacs

Copy link
Copy Markdown
Contributor

Problem

Fixes #114. When the Alliance variant is used with Preset teams, the teams are randomised anyway unless "Use specified player order" is also enabled.

Cause

In GenerateDraft::generatePlayerData(), the player list is shuffled for random draft order (presetDraftOrder = false, the default) before alliance teams are assigned. Teams are then formed by pairing adjacent players in that already-shuffled list, so the preset pairs entered in the form are lost.

The two settings — presetDraftOrder (pick sequence) and allianceTeamMode (team composition) — were conflated. The existing itCanGeneratePlayerDataForAlliances test only passed because it set presetDraftOrder => true, which skips the shuffle and masked the bug.

Fix

  • Capture the preset team-per-player mapping from the original input order before the draft-order shuffle, then re-apply it after players are created — so team composition stays fixed regardless of draft order.
  • Random teams keep their existing adjacency-pairing behaviour (now shuffling a local copy rather than the associative $players array in place).

Test

Adds itKeepsPresetTeamsWhenDraftOrderIsRandomised, which runs with presetDraftOrder => false and asserts (across 20 shuffled runs) that each player keeps their preset team. This fails against the old code and passes with the fix.

Note: I wasn't able to run the PHPUnit suite locally in my environment, so a CI run / reviewer verification would be appreciated.

generatePlayerData() shuffled the player list for random draft order
before assigning alliance teams by adjacency, so "Preset teams" only
worked when "Use specified player order" was also enabled. With random
draft order (the default) the preset pairs were scrambled.

Capture the preset team-per-player mapping from the original input order
before the draft-order shuffle, and re-apply it afterwards so team
composition stays fixed regardless of draft order. Random teams keep
their existing pairing behaviour.

Fixes shenanigans-be#114

@shenanigans-be shenanigans-be left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for the high quality PR!

@shenanigans-be
shenanigans-be merged commit 023f4e0 into shenanigans-be:main Jul 16, 2026
3 of 4 checks passed
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.

Alliance variant preset team option does not work

2 participants