johnridesabike / coronate

A Swiss-style chess tournament management app.
https://coronate.netlify.app/
Mozilla Public License 2.0
140 stars 22 forks source link

Pairings for players with draws not working properly #52

Closed MagicValleyChess closed 2 years ago

MagicValleyChess commented 2 years ago

I am loving Coronate. I am a middle school teacher and we are currently running a 6 round blitz tournament over the course of several weeks (because each round takes 3 days (limited clocks) and we have over 70 participants!)

I just noticed that the software is pairing players with half wins against other players with half wins (3.5 vs 2.5) instead of pairing them against the player that is closest to their score (3.5 vs 3.0). It seems to be an error since I also noted players with 2.5 vs 1.5.

I honestly can't think of much else that I would change... oh, except an easy way to print out standings and pairings. That would be awesome.

Thanks again for this program. Thoroughly enjoying it! Peter Clark Twin Falls, ID

johnridesabike commented 2 years ago

Thanks for the report. Draws shouldn't affect the pairing like that, since the scores are just numbers, and 0.5 isn't treated in a special way. I'll take a look at the pairing code and see if I can track down any problems.

The pairing code is pretty complex, though, so it's possible that there's something else going on. It looks at each possible pair and rates how "ideal" that pair is. These are what it uses to calculate each pair's ideal, in order of importance:

  1. Whether the players have been paired before. (Not being paired before is preferred.)
  2. How close their scores are.
  3. The players' ratings.
  4. Which color (black or white) they're each due for their next round.

Because these are prioritized, the only thing more important than scores is whether they've been paired before. Is it possible that's happened in some of the examples you've seen? (I.e. all of the players with close scores have already played each other.)

Finally, the pairing code uses an algorithm which tries to match everyone so the average pair "ideal" is as high as possible. Occasionally this means it won't pair two people who have a high "ideal" value if it means pairing them with other people raises the overall average "ideal" for everyone. (I hope that makes sense.)

And I'm glad you're enjoying it! PS: I'll take a look at making a printable view for the standings and pairings too. 😊

MagicValleyChess commented 2 years ago

Awesome. Thanks!

On Fri, Mar 4, 2022 at 11:38 AM John Jackson @.***> wrote:

Thanks for the report. Draws shouldn't affect the pairing like that, since the scores are just numbers, and 0.5 isn't treated in a special way. I'll take a look at the pairing code and see if I can track down any problems.

The pairing code is pretty complex, though, so it's possible that there's something else going on. It looks at each possible pair and rates how "ideal" that pair is. These are what it uses to calculate each pair's ideal, in order of importance:

  1. Whether the players have been paired before. (Not being paired before is preferred.)
  2. How close their scores are.
  3. The players' ratings.
  4. Which color (black or white) they're each due for their next round.

Because these are prioritized, the only thing more important than scores is whether they've been paired before. Is it possible that's happened in some of the examples you've seen? (I.e. all of the players with close scores have already played each other.)

Finally, the pairing code uses an algorithm which tries to match everyone so the average pair "ideal" is as high as possible. Occasionally this means it won't pair two people who have a high "ideal" value if it means pairing them with other people raises the overall average "ideal" for everyone. (I hope that makes sense.)

And I'm glad you're enjoying it! PS: I'll take a look at making a printable view for the standings and pairings too. 😊

— Reply to this email directly, view it on GitHub https://github.com/johnridesabike/coronate/issues/52#issuecomment-1059420372, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWKJYTIAA6COLHKLMLYVEV3U6JKD5ANCNFSM5P6DSJVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

--

Peter Clark

Math Teacher

Robert Stuart Middle School

johnridesabike commented 2 years ago

I've drafted a patch that should make some of the pages look a lot better when printed. It's not live on the main app yet, but you can preview it here: https://deploy-preview-54--coronate.netlify.app/

Please let me know if you have any thoughts about it!

Regarding your main question, I haven't been able to pinpoint any specific bug related to pairings with draws yet. It's possible I'm missing something, but it's also possible that the pairing is working correctly and other variables are just outweighing the score variable.

(Like I mentioned earlier, pairing is very complicated, so sometimes the algorithm does things that seem counter-intuitive at first.)

If you have data for a specific tournament that you think has a pairing error, and you don't mind sharing it with me, that will help me see if there really is a bug or not.

MagicValleyChess commented 2 years ago

I like the print feature. I think it is much improved. :) Thanks!

Here is the tournament that I was referring to: https://coronate.netlify.app/tourneys/EglU49GZINSLnyt0n57n0/

I think that some of the players with 1/2 points ended up with more generous pairings. (playing someone a full point below their current score as opposed to playing someone 1/2 a point below).

Not a huge deal- but it did end up affecting the results of the tournament. Let me know what you think! -Peter

johnridesabike commented 2 years ago

Sharing tournaments by URL does not work, unfortunately. (The app stores all of its data in your local browser, so that URL is only valid for you.) If you go to the "options" page, you can export your data there. The easiest export method is using the "backup to Github" feature, which saves the data to a file on GitHub that you can share from the Gist page (https://gist.github.com/). You can also copy the data out of the big text box at the bottom and save it to a text file. If you do that, you can either attach it to a comment here or email it to me at johnbicyclejackson@icloud.com

MagicValleyChess commented 2 years ago

I think this might work?

https://gist.github.com/MagicValleyChess/6811e3d81c8b593e3b112ecfd783f920

Let me know if it doesn't.

johnridesabike commented 2 years ago

I got it. Thanks!

I think I see the pairings you're talking about, and I agree they seem odd. I'll see if I can determine why the algorithm picked them, and whether or not it needs to be tweaked.

MagicValleyChess commented 2 years ago

Cool, thanks!

On Wed, Mar 30, 2022 at 7:33 AM John Jackson @.***> wrote:

I got it. Thanks!

I think I see the pairings you're talking about, and I agree they seem odd. I'll see if I can determine why the algorithm picked them, and whether or not it needs to be tweaked.

— Reply to this email directly, view it on GitHub https://github.com/johnridesabike/coronate/issues/52#issuecomment-1083146713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWKJYTOUDMQDY4X5G3COYBDVCRJZVANCNFSM5P6DSJVQ . You are receiving this because you authored the thread.Message ID: @.***>

--

Peter Clark

Math Teacher

Robert Stuart Middle School

johnridesabike commented 2 years ago

It turns out that you were on to something. Although the current implementation doesn't have an error with half-point scores per-se, it does weigh score differences unevenly, which tends to mostly affect players with half-point scores.

(Begin long explanation.)

The error stems from how it calculates the "pair ideal." In the current implementation, there's a fixed maximum ideal number. It subtracts points from that maximum based on different variables (mentioned in a previous comment). The way it handles the scores variable is problematic. It takes a fixed number and divides it by the difference in player scores (plus 1, since you can't divide by zero).

The problem comes from the fact that this calculation progresses geometrically, not linearly. As players scores are further apart, the "ideal" variable gets less significant. In other words, a 0.5 difference and a 1.0 difference aren't seen as very far apart compared to a 0.0 and a 0.5 difference.

To make it worse, these relative differences would get outweighed by other variables that were supposed to be less important, such as due-colors or ratings.

To fix the problem, I changed the calculation to expand the maximum ideal number based on the highest score in the tournament. Instead of using division with the score differences, it now subtracts a fixed number for each point.

(End long explanation.)

Here's a preview site with the fixed version, if you want to play around with it.

To test it out, here are the differences with auto-pairing from round 5 of your tournament.

Old pairings:

Match # white score black score offset
10 3.5 2.5 1.0
11 2 2.5 0.5
16 1.5 2.5 1.0
31 1 0 1.0

New pairings:

Match # white score black score offset
3 3.5 3 0.5
10 3 2.5 0.5
22 1.5 2 0.5
31 1 0 1.0

I think it's pairing a lot more accurately now. Once I have the time to add some automatic tests to verify it's all working correctly, I'll merge this change with the main app.

MagicValleyChess commented 2 years ago

Awesome, thanks! This looks way better.

Again, don't get me wrong, I really like the program and have shared it with others, but it did make it problematic. I think those who had early draws, ended up getting pretty easy pairings. The person that ended up with 2nd place (5.5 out of 6), had significantly easier tie breaks, for example than those that finished below him in the final standings.

I'm looking forward to the update! -Peter

On Sat, Apr 2, 2022 at 4:57 PM John Jackson @.***> wrote:

It turns out that you were on to something. Although the current implementation doesn't have an error with half-point scores per-se, it does weigh score differences unevenly, which tends to mostly affect players with half-point scores.

(Begin long explanation.)

The error stems from how it calculates the "pair ideal." In the current implementation, there's a fixed maximum ideal number. It subtracts points from that maximum based on different variables (mentioned in a previous comment). The way it handles the scores variable is problematic. It takes a fixed number and divides it by the difference in player scores (plus 1, since you can't divide by zero).

The problem comes from the fact that this calculation progresses geometrically, not linearly. As players scores are further apart, the "ideal" variable gets less significant. In other words, a 0.5 difference and a 1.0 difference aren't seen as very far apart compared to a 0.0 and a 0.5 difference.

To make it worse, these relative differences would get outweighed by other variables that were supposed to be less important, such as due-colors or ratings.

To fix the problem, I changed the calculation to expand the maximum ideal number based on the highest score in the tournament. Instead of using division with the score differences, it now subtracts a fixed number for each point.

(End long explanation.)

Here's a preview site with the fixed version, if you want to play around with it. https://deploy-preview-58--coronate.netlify.app/

To test it out, here are the differences with auto-pairing from round 5 of your tournament.

Old pairings: Match # white score black score offset 10 3.5 2.5 1.0 11 2 2.5 0.5 16 1.5 2.5 1.0 31 1 0 1.0

New pairings: Match # white score black score offset 3 3.5 3 0.5 10 3 2.5 0.5 22 1.5 2 0.5 31 1 0 1.0

I think it's pairing a lot more accurately now. Once I have the time to add some automatic tests to verify it's all working correctly, I'll merge this change with the main app.

— Reply to this email directly, view it on GitHub https://github.com/johnridesabike/coronate/issues/52#issuecomment-1086738438, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWKJYTOMRFP5JTW23VNBT7LVDDGGVANCNFSM5P6DSJVQ . You are receiving this because you authored the thread.Message ID: @.***>

--

Peter Clark

Math Teacher

Robert Stuart Middle School

johnridesabike commented 2 years ago

Thank you, too! I only work on this in my free time, and it's impossible for me to catch all of these issues on my own. Taking the time to share your data helps me a lot. I'll go ahead and publish the update, since it seems to be working.

MagicValleyChess commented 2 years ago

Great!!

On Wed, Apr 6, 2022 at 5:14 PM John Jackson @.***> wrote:

Thank you, too! I only work on this in my free time, and it's impossible for me to catch all of these issues on my own. Taking the time to share your data helps me a lot. I'll go ahead and publish the update, since it seems to be working.

— Reply to this email directly, view it on GitHub https://github.com/johnridesabike/coronate/issues/52#issuecomment-1090911141, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWKJYTMKYJB6S22GY6O3XL3VDYLEVANCNFSM5P6DSJVQ . You are receiving this because you authored the thread.Message ID: @.***>

--

Peter Clark

Math Teacher

Robert Stuart Middle School