Skip Menu |

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

Report information
The Basics
Id: 37778
Status: resolved
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 "initializePreferences" (Version 0.15 of Games::Tournament::Swiss)
Date: Fri, 18 Jul 2008 12:19:47 +0200
To: bug-Games-Tournament-Swiss [...] rt.cpan.org
From: Christian Bartolomaeus <bartolin [...] gmx.de>
Hi, I think I discovered a bug in method "initializePreferences" in Games/Tournament/Swiss.pm. This methods is used to assign preferences to players in S1 (Nr. E.5 of Fide Swiss Rules). Rule E.5 reads: "In the first round all even numbered players in S1 will receive a colour different from all odd numbered players in S1." Swiss.pm tries to do this with the following code (lines 107-112): for my $n ( 0 .. $#players / 4 ) { $players[ 2 * $n ]->preference->sign($evenRole); $players[ 2 * $n ]->preference->difference(0); $players[ 2 * $n + 1 ]->preference->sign($oddRole); $players[ 2 * $n + 1 ]->preference->difference(0); } But this doesn't address exactely the players from S1. Let's assume we have @players with six players (A B C D E F), then we have S1 as (A B C). But the code is similar to for my $n ( 0 .. 1 ) { $players [ 2 * $n ]-> ... $players [ 2 * $n ]-> ... $players [ 2 * $n + 1 ]-> ... $players [ 2 * $n + 1 ]-> ... } which actually addresses players (A B C D). I think the following code should do what E.5 prescribes: 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); } } 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 #37778] bug in method "initializePreferences" (Version 0.15 of Games::Tournament::Swiss)
Date: Fri, 18 Jul 2008 13:44:30 +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
> "In the first round all even numbered players in S1 will receive a > colour different from all odd numbered players in S1."
Show quoted text
> Swiss.pm tries to do this with the following code (lines 107-112):
Show quoted text
> But this doesn't address exactely the players from S1. Let's assume we > have @players with six players (A B C D E F), then we have S1 > as (A B C). But the code .. actually addresses players (A B C D).
Oops. It looks like I was assuming there was an even number of players in S1. Show quoted text
> I think the following code should do what E.5 prescribes:
Show quoted text
> 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); > } > }
I would prefer to loop over 0 .. $#players/2 foreach my $n ( 0 .. $#players / 2 ) { if ( $n % 2 ) { $players [ $n ]->preference->sign($oddRole); $players [ $n ]->preference->difference(0); } else { $players [ $n ]->preference->sign($evenRole); $players [ $n ]->preference->difference(0); } }
Subject: Re: [rt.cpan.org #37778] bug in method "initializePreferences" (Version 0.15 of Games::Tournament::Swiss)
Date: Fri, 18 Jul 2008 16:17:14 +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=37778 > >
> > I think the following code should do what E.5 prescribes:
>
> > 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); > > } > > }
> > I would prefer to loop over 0 .. $#players/2 > > foreach my $n ( 0 .. $#players / 2 ) { > if ( $n % 2 ) { > $players [ $n ]->preference->sign($oddRole); > $players [ $n ]->preference->difference(0); > } > else { > $players [ $n ]->preference->sign($evenRole); > $players [ $n ]->preference->difference(0); > } > }
I agree that my loop looks a bit awkward. But your code would have problems with an odd number of players. It would address n/2 players rounded up -- whereas S1 consist of n/2 players rounded down. I just have a kind of knot in my head and do see how to write the code starting with $n=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 #37778] bug in method "initializePreferences" (Version 0.15 of Games::Tournament::Swiss)
Date: Fri, 18 Jul 2008 21:20:21 +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 would prefer to loop over 0 .. $#players/2
Show quoted text
> > foreach my $n ( 0 .. $#players / 2 ) { > > if ( $n % 2 ) { > > $players [ $n ]->preference->sign($oddRole); > > $players [ $n ]->preference->difference(0); > > } > > else { > > $players [ $n ]->preference->sign($evenRole); > > $players [ $n ]->preference->difference(0); > > } > > }
Show quoted text
> I agree that my loop looks a bit awkward. But your code would have > problems with an odd number of players. It would address n/2 players > rounded up -- whereas S1 consist of n/2 players rounded down.
You're right. I think (0..($#players+1)/2-1) is OK. Show quoted text
> Best regards
Show quoted text
> Christian
Subject: Re: [rt.cpan.org #37778] bug in method "initializePreferences" (Version 0.15 of Games::Tournament::Swiss)
Date: Sat, 19 Jul 2008 13:07:50 +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=37778 > > [...]
> > > I would prefer to loop over 0 .. $#players/2
>
> > > foreach my $n ( 0 .. $#players / 2 ) { > > > if ( $n % 2 ) { > > > $players [ $n ]->preference->sign($oddRole); > > > $players [ $n ]->preference->difference(0); > > > } > > > else { > > > $players [ $n ]->preference->sign($evenRole); > > > $players [ $n ]->preference->difference(0); > > > } > > > }
>
> > I agree that my loop looks a bit awkward. But your code would have > > problems with an odd number of players. It would address n/2 players > > rounded up -- whereas S1 consist of n/2 players rounded down.
> > You're right. I think > > (0..($#players+1)/2-1) > > is OK.
Yes, that looks good. Thanks for resolving this issue.
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

It looks like I wasn't listening in 2008. I don't think I ever committed this fix. I guess this is why I came across the same (?) bug again #47450, which was fixed by: svn diff -r 9:10 http://svn.openfoundry.org/swiss/trunk/lib/Games/Tournament/Swiss.pm That fix looks similar to this one.