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