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
Message body not shown because it is not plain text.