Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fairly assign home/away matches amongst players #3

Merged
merged 3 commits into from
Jun 24, 2021

Conversation

jarodburchill
Copy link
Contributor

I really like your use of the circle method here, however, when using robin() I found myself wanting to fairly assign "home" matches to players, meaning that in the event of an odd number of players, each player has the same amount of home matches:

// players 1-5 all play 2 home and 2 away matches

// [ away, home ]
[
  [ [ 2, 5 ], [ 3, 4 ] ],
  [ [ 5, 1 ], [ 2, 3 ] ],
  [ [ 1, 4 ], [ 5, 3 ] ],
  [ [ 3, 1 ], [ 4, 2 ] ],
  [ [ 1, 2 ], [ 4, 5 ] ]
]

or in the event of an even number of players, each player has at most 1 more/less home match:

// players 1,3,5 each play 2 home and 3 away matches
// while players 2,4,6 each play 3 home and 2 away matches

// [ away, home ]
[
  [ [ 1, 6 ], [ 2, 5 ], [ 3, 4 ] ],
  [ [ 5, 1 ], [ 6, 4 ], [ 2, 3 ] ],
  [ [ 1, 4 ], [ 5, 3 ], [ 6, 2 ] ],
  [ [ 3, 1 ], [ 4, 2 ], [ 5, 6 ] ],
  [ [ 1, 2 ], [ 3, 6 ], [ 4, 5 ] ]
]

This PR accomplishes this.

This method was also mentioned in the wiki article you referenced in robin.js

The upper and lower rows can indicate home/away in sports, white/black in chess, etc.; to ensure fairness, this must alternate between rounds since competitor 1 is always on the first row.

I also bumped the version to 2.0.0 as some might see this as a breaking change if they for some reason relied on the order of the match arrays (although I doubt it because the [ away, home ] concept is new and I don't see why else the order would matter).

Let me know what you think :)

@clux
Copy link
Collaborator

clux commented Jun 23, 2021

I think this is a great idea, and it's handled very gracefully. I agree that a major is needed (even though the interface itself is unchanged, and the change will likely go under the radar), as it does change determinism of groupstages higher up the stack, so people trying to resume a tournament might be confused.

Will leave a few questions on the PR, but overall the thing looks pretty good right of the bat. Thanks a lot for doing this!

Copy link
Collaborator

@clux clux left a comment

Choose a reason for hiding this comment

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

questions on order and a seed suggestion

robin.js Show resolved Hide resolved
README.md Show resolved Hide resolved
robin.js Show resolved Hide resolved
@jarodburchill
Copy link
Contributor Author

jarodburchill commented Jun 23, 2021

Perhaps we should also update README.md to say that in version 2.0.0 a user can expect fair home/away assignment and also explain the [ away, home ] ordering/reasoning.

@jarodburchill
Copy link
Contributor Author

Perhaps we should also update README.md to say that in version 2.0.0 a user can expect fair home/away assignment and also explain the [ away, home ] ordering/reasoning.

Done in commit 6d06751.

How does it look?

@clux
Copy link
Collaborator

clux commented Jun 24, 2021

How does it look?

Looks great :-)

As a somewhat amusing sidenote; this will be the second ever update to this library. Last PR was ~7 years ago (issue #1).

@jarodburchill
Copy link
Contributor Author

As a somewhat amusing sidenote; this will be the second ever update to this library. Last PR was ~7 years ago (issue #1).

Haha, yeah I know this repo is a bit old but while I was working on a React Native side project I needed to lay out teams in a round robin format and I thought I'd see if anyone had done it yet. Turns out you had, I just needed to add home/away support. Figured I'd open a PR rather than just keep the changes to myself :)

@clux
Copy link
Collaborator

clux commented Jun 24, 2021

Definitely appreciated :-)

@clux clux merged commit efc75be into tournament-js:master Jun 24, 2021
@clux
Copy link
Collaborator

clux commented Jun 24, 2021

roundrobin@2.0.0 released 🎉

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.

None yet

2 participants