Skip Menu |

This queue is for tickets about the Games-Tournament-Swiss CPAN distribution.

Report information
The Basics
Id: 37780
Status: open
Priority: 0/
Queue: Games-Tournament-Swiss

People
Owner: Nobody in particular
Requestors: bartolin [...] gmx.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Fri, 18 Jul 2008 12:45:40 +0200
To: bug-Games-Tournament-Swiss [...] rt.cpan.org
From: Christian Bartolomaeus <bartolin [...] gmx.de>
Hi, I think I discovered a bug in method "x" in Games/Tournament/Swiss/Bracket.pm. This method determines "x" from A.8 of FIDE Swiss Rules. The code of "sub x" does the following: my $w = grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } @$players; my $b = @$players - $w; The last line assumes, that all remaining players in a bracket (after taking away those with a preference for white (ROLES)[0]) have a preference for black (ROLES)[1]. But I think that's not true for all cases. If we take a tournament with an odd number of participants, in the second round there will be one player (the player who got a bye in the first round) who has neither a preference for white nor for black. Unfortunately this can leads to problems. Take a look at the following (partial) pairing table (it is taken from http://www.lsvmv.de/turniere/erg/lem_schnellschach_2008_maenner_paarungen.htm and I'd like to add that tournament as a test; but that may take a while): Round 2 Pairing Groups ------------------------------------------------------------------------- Place No Opponents Roles Float Score 1-14 1 15 W 1 2 16 B 1 3 17 W 1 4 18 B 1 6 20 B 1 8 22 B 1 9 23 W 1 10 24 B 1 12 26 B 1 13 27 W 1 14 28 B 1 21 7 B 1 25 11 B 1 29 - - D 1 [...] Here we have four players with a preference for black and nine players with a preference for white -- and one player with no preference. We have to generate seven pairins, so "x" should be 2 (9-7). Games::Tournament::Swiss version 0.15 calculates x as 3 (apparently adding player 29 to the group of players with a preference for white). I think it would be correct to change the above code to: my $w = grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } @$players; my $b = grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } @$players; Unfortunately this leads to problems for round 1 pairings. The reason for this is, that (according to E.5 of FIDE Swiss Rules) only the players from S1 have a color preference for round 1. As a workaround one could assign proper color preferences for players from S2 for round 1 as well -- though the rules don't call for this it should have no negative side effect. I tried to do so in method "initializePreferences" and everything seems to work fine. (But see also my bug report for method "initializePreferences": http://rt.cpan.org/Public/Bug/Display.html?id=37778) My (experimental) Games/Tournamen/Swiss.pm does for method "initializePreferences": ## modified by CB to follow E.5 strictly foreach my $n ( 1 .. ($#players + 1) / 2 ) { if ( $n % 2 ) { $players [ $n - 1 ]->preference->sign($oddRole); $players [ $n - 1 ]->preference->difference(0); } else { $players [ $n - 1 ]->preference->sign($evenRole); $players [ $n - 1 ]->preference->difference(0); } } ## added by CB to avoid missing preferences calculating x for round 1 foreach my $n ( ( ($#players + 1) / 2 + 1 ) .. ( $#players + 1 ) ) { if ( $n % 2 ) { $players [ $n - 1 ]->preference->sign($evenRole); $players [ $n - 1 ]->preference->difference(0); } else { $players [ $n - 1 ]->preference->sign($oddRole); $players [ $n - 1 ]->preference->difference(0); } } Best regards Christian
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #37780] bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Fri, 18 Jul 2008 13:28:13 +0000
To: Christian Bartolomaeus via RT <bug-Games-Tournament-Swiss [...] rt.cpan.org>
From: Greg Matheson <drbean [...] freeshell.org>
On Fri, 18 Jul 2008, Christian Bartolomaeus via RT wrote: Show quoted text
> The code of "sub x" does the following:
Show quoted text
> my $w = > grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } > @$players; > my $b = @$players - $w;
Show quoted text
> The last line assumes, that all remaining players in a bracket (after > taking away those with a preference for white (ROLES)[0]) have a > preference for black (ROLES)[1].
good catch. Show quoted text
> I think it would be correct to change the above code to:
Show quoted text
> my $w = > grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } > @$players; > my $b = > grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } > @$players;
yes, this is the right fix, I think. Show quoted text
> Unfortunately this leads to problems for round 1 pairings. The reason > for this is, that (according to E.5 of FIDE Swiss Rules) only the > players from S1 have a color preference for round 1.
Show quoted text
> As a workaround one could assign proper color preferences for players > from S2 for round 1 as well -- though the rules don't call for this it > should have no negative side effect. I tried to do so in method > "initializePreferences" and everything seems to work fine. (But see > also my bug report for method "initializePreferences": > http://rt.cpan.org/Public/Bug/Display.html?id=37778)
I don't think colors preferences should be assigned in round 1. In fact players in the top half who don't actually play (in the cases you outlined in #30332) should also have the preferences assigned them canceled? At the top of the colors method in Games::Tournament::Swiss::Procedure::FIDE there is code to handle cases of players with no color preferences. if ( not roles[0] ) etc if ( not roles[1] ) etc Show quoted text
> My (experimental) Games/Tournamen/Swiss.pm does for method > "initializePreferences":
Show quoted text
> ## modified by CB to follow E.5 strictly > foreach my $n ( 1 .. ($#players + 1) / 2 ) { > if ( $n % 2 ) { > $players [ $n - 1 ]->preference->sign($oddRole); > $players [ $n - 1 ]->preference->difference(0); > } > else { > $players [ $n - 1 ]->preference->sign($evenRole); > $players [ $n - 1 ]->preference->difference(0); > } > }
Is this easier to understand than the foreach loop over 0 .. $#players/4 ? Show quoted text
> ## added by CB to avoid missing preferences calculating x for round 1 > foreach my $n ( ( ($#players + 1) / 2 + 1 ) .. ( $#players + 1 ) ) { > if ( $n % 2 ) { > $players [ $n - 1 ]->preference->sign($evenRole); > $players [ $n - 1 ]->preference->difference(0); > } > else { > $players [ $n - 1 ]->preference->sign($oddRole); > $players [ $n - 1 ]->preference->difference(0); > } > }
Wouldn't this give the player with a bye a preference?
Subject: Re: [rt.cpan.org #37780] AutoReply: bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Fri, 18 Jul 2008 15:47:51 +0200
To: Bugs in Games-Tournament-Swiss via RT <bug-Games-Tournament-Swiss [...] rt.cpan.org>
From: Christian Bartolomaeus <bartolin [...] gmx.de>
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Hi, * On 2008-07-18 Christian Bartolomaeus (bartolin@gmx.de) wrote: Show quoted text
> [...] > Unfortunately this can lead to problems. Take a look at the > following (partial) pairing table (it is taken from > http://www.lsvmv.de/turniere/erg/lem_schnellschach_2008_maenner_paarungen.htm > and I'd like to add that tournament as a test; but that may take a > while):
I now made a test for rounds 1 to 6 of this tournament (see attachment). With my modified versions of Games/Tournament/Swiss.pm and Games/Tournament/Swiss/Bracket.pm (see last post) this test runs fine for rounds 1 to 5 -- that is, Games::Tournament::Swiss gives the same pairings as were actually made in the tournament. With the unmodified module files there is a problem with round 2. Please note that there is a small problem with round 6. This has something to do with the fact that Games::Tournament::Swiss doesn't avoid giving a second bye for player 27. But maybe I should open a new bug report for this problem. I'll do that later -- after the problem with method "x" is fixed. Otherwise matters would become a bit complicated, since I couldn't provide the correct pairing tables. Best regards Christian

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #37780] bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Fri, 18 Jul 2008 13:28:13 +0000
To: Christian Bartolomaeus via RT <bug-Games-Tournament-Swiss [...] rt.cpan.org>
From: Greg Matheson <drbean [...] freeshell.org>
On Fri, 18 Jul 2008, Christian Bartolomaeus via RT wrote: Show quoted text
> The code of "sub x" does the following:
Show quoted text
> my $w = > grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } > @$players; > my $b = @$players - $w;
Show quoted text
> The last line assumes, that all remaining players in a bracket (after > taking away those with a preference for white (ROLES)[0]) have a > preference for black (ROLES)[1].
good catch. Show quoted text
> I think it would be correct to change the above code to:
Show quoted text
> my $w = > grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } > @$players; > my $b = > grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } > @$players;
yes, this is the right fix, I think. Show quoted text
> Unfortunately this leads to problems for round 1 pairings. The reason > for this is, that (according to E.5 of FIDE Swiss Rules) only the > players from S1 have a color preference for round 1.
Show quoted text
> As a workaround one could assign proper color preferences for players > from S2 for round 1 as well -- though the rules don't call for this it > should have no negative side effect. I tried to do so in method > "initializePreferences" and everything seems to work fine. (But see > also my bug report for method "initializePreferences": > http://rt.cpan.org/Public/Bug/Display.html?id=37778)
I don't think colors preferences should be assigned in round 1. In fact players in the top half who don't actually play (in the cases you outlined in #30332) should also have the preferences assigned them canceled? At the top of the colors method in Games::Tournament::Swiss::Procedure::FIDE there is code to handle cases of players with no color preferences. if ( not roles[0] ) etc if ( not roles[1] ) etc Show quoted text
> My (experimental) Games/Tournamen/Swiss.pm does for method > "initializePreferences":
Show quoted text
> ## modified by CB to follow E.5 strictly > foreach my $n ( 1 .. ($#players + 1) / 2 ) { > if ( $n % 2 ) { > $players [ $n - 1 ]->preference->sign($oddRole); > $players [ $n - 1 ]->preference->difference(0); > } > else { > $players [ $n - 1 ]->preference->sign($evenRole); > $players [ $n - 1 ]->preference->difference(0); > } > }
Is this easier to understand than the foreach loop over 0 .. $#players/4 ? Show quoted text
> ## added by CB to avoid missing preferences calculating x for round 1 > foreach my $n ( ( ($#players + 1) / 2 + 1 ) .. ( $#players + 1 ) ) { > if ( $n % 2 ) { > $players [ $n - 1 ]->preference->sign($evenRole); > $players [ $n - 1 ]->preference->difference(0); > } > else { > $players [ $n - 1 ]->preference->sign($oddRole); > $players [ $n - 1 ]->preference->difference(0); > } > }
Wouldn't this give the player with a bye a preference?
Subject: Re: [rt.cpan.org #37780] bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Fri, 18 Jul 2008 16:05:56 +0200
To: Greg Matheson via RT <bug-Games-Tournament-Swiss [...] rt.cpan.org>
From: Christian Bartolomaeus <bartolin [...] gmx.de>
Hi, * On 2008-07-18 Greg Matheson via RT (bug-Games-Tournament-Swiss@rt.cpan.org) wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=37780 > >
> > Unfortunately this leads to problems for round 1 pairings. The reason > > for this is, that (according to E.5 of FIDE Swiss Rules) only the > > players from S1 have a color preference for round 1.
>
> > As a workaround one could assign proper color preferences for players > > from S2 for round 1 as well -- though the rules don't call for this it > > should have no negative side effect. I tried to do so in method > > "initializePreferences" and everything seems to work fine. (But see > > also my bug report for method "initializePreferences": > > http://rt.cpan.org/Public/Bug/Display.html?id=37778)
> > I don't think colors preferences should be assigned in round 1. > In fact players in the top half who don't actually play (in the > cases you outlined in #30332) should also have the preferences assigned > them canceled?
well, maybe I didn't get it right. I thought method "initializePreference" was used to assign preferences for the top half. So I thought, one could do the same thing for the bottom half as well. But indeed those "assigned preferences" should be relevant only for the pairing of round 1. Show quoted text
> At the top of the colors method in > Games::Tournament::Swiss::Procedure::FIDE there is code to handle > cases of players with no color preferences. > > if ( not roles[0] ) > etc > > > if ( not roles[1] ) > etc
I see. But I had the impression that for round one pairings at some point the method "x" is called and the code my $b = grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } @$players; fails to work, since there are players in @$players with no preferences. Show quoted text
> > My (experimental) Games/Tournamen/Swiss.pm does for method > > "initializePreferences":
>
> > ## modified by CB to follow E.5 strictly > > foreach my $n ( 1 .. ($#players + 1) / 2 ) { > > if ( $n % 2 ) { > > $players [ $n - 1 ]->preference->sign($oddRole); > > $players [ $n - 1 ]->preference->difference(0); > > } > > else { > > $players [ $n - 1 ]->preference->sign($evenRole); > > $players [ $n - 1 ]->preference->difference(0); > > } > > }
> > Is this easier to understand than the foreach loop > over 0 .. $#players/4 ?
I wouldn't say that. But there was this other problem with the loop over 0 .. $#players/4 (see #37780). Show quoted text
> > ## added by CB to avoid missing preferences calculating x for round 1 > > foreach my $n ( ( ($#players + 1) / 2 + 1 ) .. ( $#players + 1 ) ) { > > if ( $n % 2 ) { > > $players [ $n - 1 ]->preference->sign($evenRole); > > $players [ $n - 1 ]->preference->difference(0); > > } > > else { > > $players [ $n - 1 ]->preference->sign($oddRole); > > $players [ $n - 1 ]->preference->difference(0); > > } > > }
> > Wouldn't this give the player with a bye a preference?
Yes, you're right. So this might be a wrong thing to do. But I tried this as a workaround for #37780 and it seemed to work so far. Best regards Christian
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #37780] bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Fri, 18 Jul 2008 22:11:24 +0000
To: Christian Bartolomaeus via RT <bug-Games-Tournament-Swiss [...] rt.cpan.org>
From: Greg Matheson <drbean [...] freeshell.org>
On Fri, 18 Jul 2008, Christian Bartolomaeus via RT wrote: Show quoted text
> I see. But I had the impression that for round one pairings at some > point the method "x" is called and the code
Show quoted text
> my $b = > grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } > @$players;
Show quoted text
> fails to work, since there are players in @$players with no > preferences.
Your code: Show quoted text
> my $w = > grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } > @$players; > my $b = > grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } > @$players;
should be introduced, and there should be some tests to see x is returning the right values in cases where some player don't have preferences. Probably some invalid values for x have been being returned in round 2.
Subject: Re: [rt.cpan.org #37780] bug in method "x" (Version 0.06 of Games::Tournament::Swiss::Bracket)
Date: Sat, 19 Jul 2008 13:12:19 +0200
To: Greg Matheson via RT <bug-Games-Tournament-Swiss [...] rt.cpan.org>
From: Christian Bartolomaeus <bartolin [...] gmx.de>
* On 2008-07-18 Greg Matheson via RT (bug-Games-Tournament-Swiss@rt.cpan.org) wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=37780 > >
> > I see. But I had the impression that for round one pairings at some > > point the method "x" is called and the code
>
> > my $b = > > grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } > > @$players;
>
> > fails to work, since there are players in @$players with no > > preferences.
> > Your code: >
> > my $w = > > grep { $_->preference->role and $_->preference->role eq (ROLES)[0] } > > @$players; > > my $b = > > grep { $_->preference->role and $_->preference->role eq (ROLES)[1] } > > @$players;
> > should be introduced, and there should be some tests to see x is > returning the right values in cases where some player don't have > preferences.
That sounds good to me. Thanks Christian
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.