File Coverage

blib/lib/Games/Tournament/Swiss/Procedure/Dummy.pm
Criterion Covered Total %
statement 63 65 96.9
branch 13 18 72.2
condition 3 3 100.0
subroutine 11 11 100.0
pod 5 5 100.0
total 95 102 93.1


line stmt bran cond sub pod time code
1             package Games::Tournament::Swiss::Procedure::Dummy;
2              
3             # Last Edit: 2009 7月 06, 16時20分56秒
4             # $Id: $
5              
6 8     8   1125 use warnings;
  8         13  
  8         203  
7 8     8   36 use strict;
  8         13  
  8         200  
8              
9 8     8   35 use constant ROLES => @Games::Tournament::Swiss::Config::roles;
  8         12  
  8         444  
10 8     8   38 use constant FIRSTROUND => $Games::Tournament::Swiss::Config::firstround;
  8         14  
  8         398  
11              
12 8     8   37 use base qw/Games::Tournament::Swiss/;
  8         13  
  8         445  
13 8     8   213 use Games::Tournament::Contestant::Swiss;
  8         12  
  8         5434  
14              
15             =head1 NAME
16              
17             Games::Tournament::Swiss::Procedure::Dummy - A brain-dead pairing algorithm
18              
19             =head1 VERSION
20              
21             Version 0.03
22              
23             =cut
24              
25             our $VERSION = '0.03';
26              
27             =head1 SYNOPSIS
28              
29             $tourney = Games::Tournament::Swiss->new( rounds => 2, entrants => [ $a, $b, $c ] );
30             %groups = $tourney->formBrackets;
31             $pairing = $tourney->pairing( \%groups );
32             @pairs = $pairing->matchPlayers;
33              
34             =head1 DESCRIPTION
35              
36             A test module swappable in to allow testing the non-Games::Tournament::Procedure parts of Games::Tournament::Swiss
37              
38             =head1 METHODS
39              
40             =head2 new
41              
42             $pairing = Games::Tournament::Swiss::Procedure::Dummy->new(TODO \@groups );
43              
44             Creates a stupid algorithm object that on matchPlayers will just pair the nth player with the n+1th in each score group, downfloating the last player if the number in the bracket is odd, ignoring the FIDE Swiss Rules. You can swap in this module in your configuration file, instead of your real algorithm to test the non-algorithm parts of your program are working.
45              
46             =cut
47              
48             sub new {
49 13     13 1 24 my $self = shift;
50 13         18 my $index = 0;
51 13         78 my %args = @_;
52 13         25 my $round = $args{round};
53 13         22 my $brackets = $args{brackets};
54 13         29 my $banner = "Round $round: ";
55 13         69 for my $bracket ( reverse sort keys %$brackets ) {
56 49         159 my $members = $brackets->{$bracket}->members;
57 49         147 my $score = $brackets->{$bracket}->score;
58 49         74 $banner .= "@{[map { $_->pairingNumber } @$members]} ($score), ";
  49         78  
  127         283  
59             }
60 13         1636 print $banner . "\n";
61 13         131 return bless {
62             round => $round,
63             brackets => $brackets,
64             matches => []
65             },
66             "Games::Tournament::Swiss::Procedure";
67             }
68              
69              
70             =head2 matchPlayers
71              
72             @pairs = $pairing->matchPlayers;
73              
74             Run a brain-dead algorithm that instead of pairing the players according to the rules creates matches between the nth and n+1th player of a bracket, downfloating the last player of the group if the number of players is odd. If there is an odd number of total players, the last gets a Bye.
75              
76             =cut
77              
78             sub matchPlayers {
79 13     13 1 205 my $self = shift;
80 13         51 my $brackets = $self->brackets;
81 13         18 my $downfloater;
82             # my @allMatches = @{ $self->matches };
83             my %allMatches;
84 13         22 my $number = 1;
85 13         53 for my $score ( reverse sort keys %$brackets ) {
86 49         50 my @bracketMatches;
87 49         138 my $players = $brackets->{$score}->members;
88 49 100       122 if ($downfloater) {
89 20         41 unshift @$players, $downfloater;
90 20         34 undef $downfloater;
91             }
92 49 100       136 $downfloater = pop @$players if @$players % 2;
93 49         130 for my $table ( 0 .. @$players / 2 - 1 ) {
94 62         144 push @bracketMatches, Games::Tournament::Card->new(
95             round => $self->round,
96             result => undef,
97             score => $score,
98             contestants => {
99             (ROLES)[0] => $players->[ 2 * $table ],
100             (ROLES)[1] => $players->[ 2 * $table + 1 ]
101             },
102              
103             # floats => \%floats
104             );
105             }
106 49 100 100     177 if ( $number == keys %$brackets and $downfloater ) {
107 3         8 push @bracketMatches, Games::Tournament::Card->new(
108             round => $self->round,
109             result => undef,
110             contestants => { Bye => $downfloater },
111              
112             # floats => \%floats
113             );
114             }
115 49         103 $allMatches{$score} = \@bracketMatches;
116 49         95 $number++;
117             }
118 13         46 $self->matches( \%allMatches );
119             }
120              
121              
122             =head2 brackets
123              
124             $pairing->brackets
125              
126             Gets/sets all the brackets which we are pairing, as an anonymous array of score group (bracket) objects. The order of this array is important. The brackets are paired in order.
127              
128             =cut
129              
130             sub brackets {
131 13     13 1 19 my $self = shift;
132 13         20 my $brackets = shift;
133 13 50       70 if ( defined $brackets ) { $self->{brackets} = $brackets; }
  0 50       0  
134 13         35 elsif ( $self->{brackets} ) { return $self->{brackets}; }
135             }
136              
137              
138             =head2 round
139              
140             $pairing->round
141              
142             What round is this round's results we're pairing on the basis of?
143              
144             =cut
145              
146             sub round {
147 65     65 1 81 my $self = shift;
148 65         76 my $round = shift;
149 65 50       226 if ( defined $round ) { $self->{round} = $round; }
  0 50       0  
150 65         432 elsif ( $self->{round} ) { return $self->{round}; }
151             }
152              
153              
154             =head2 matches
155              
156             $group->matches
157              
158             Gets/sets the matches which we have made.
159              
160             =cut
161              
162             sub matches {
163 16     16 1 33 my $self = shift;
164 16         30 my $matches = shift;
165 16 100       47 if ( defined $matches ) { $self->{matches} = $matches; }
  13 50       58  
166 3         18 elsif ( $self->{matches} ) { return $self->{matches}; }
167             }
168              
169             =head1 AUTHOR
170              
171             Dr Bean, C<< >>
172              
173             =head1 BUGS
174              
175             Please report any bugs or feature requests to
176             C, or through the web interface at
177             L.
178             I will be notified, and then you'll automatically be notified of progress on
179             your bug as I make changes.
180              
181             =head1 SUPPORT
182              
183             You can find documentation for this module with the perldoc command.
184              
185             perldoc Games::Tournament::Swiss
186              
187             You can also look for information at:
188              
189             =over 4
190              
191             =item * AnnoCPAN: Annotated CPAN documentation
192              
193             L
194              
195             =item * CPAN Ratings
196              
197             L
198              
199             =item * RT: CPAN's request tracker
200              
201             L
202              
203             =item * Search CPAN
204              
205             L
206              
207             =back
208              
209             =head1 ACKNOWLEDGEMENTS
210              
211             See L for the FIDE's Swiss rules.
212              
213             =head1 COPYRIGHT & LICENSE
214              
215             Copyright 2006 Dr Bean, all rights reserved.
216              
217             This program is free software; you can redistribute it and/or modify it
218             under the same terms as Perl itself.
219              
220             =cut
221              
222             1; # End of Games::Tournament::Swiss::Procedure
223              
224             # vim: set ts=8 sts=4 sw=4 noet: