blib/lib/Games/Tournament/Swiss/Procedure/Dummy.pm

filter: Statementstmt 97.0% 65 / 67 Branchbran 72.2% 13 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 93.4% 99 / 106 CC 14 SCAR 13.0
CC
14
Cov
92%
matchPlayers
7.0
brackets
3.3
round
3.3
CRAP 3.7
« blib/lib/Games/Tournament/Contestant/Swiss.pm ↑ Summary script_files/pairingtable »
1 package Games::Tournament::Swiss::Procedure::Dummy;
2 9 $Games::Tournament::Swiss::Procedure::Dummy::VERSION = '0.21';
3 # Last Edit: 2016 Jan 01, 13:44:45
4 # $Id: $
5  
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use constant ROLES => @Games::Tournament::Swiss::Config::roles;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use constant FIRSTROUND => $Games::Tournament::Swiss::Config::firstround;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶use base qw/Games::Tournament::Swiss/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Games::Tournament::Contestant::Swiss;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Games::Tournament::Swiss::Procedure::Dummy - A brain-dead pairing algorithm
18  
19 =cut
20  
21 =head1 SYNOPSIS
22  
23 $tourney = Games::Tournament::Swiss->new( rounds => 2, entrants => [ $a, $b, $c ] );
24 %groups = $tourney->formBrackets;
25 $pairing = $tourney->pairing( \%groups );
26 @pairs = $pairing->matchPlayers;
27  
28 =head1 DESCRIPTION
29  
30 A test module swappable in to allow testing the non-Games::Tournament::Procedure parts of Games::Tournament::Swiss
31  
32 =head1 METHODS
33  
34 =head2 new
35  
36 $pairing = Games::Tournament::Swiss::Procedure::Dummy->new(TODO \@groups );
37  
38 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.
39  
40 =cut
41  
42 13 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
43 13 my $self = shift;
44 13 my $index = 0;
45 13 my %args = @_;
46 13 my $round = $args{round};
47 13 my $brackets = $args{brackets};
48 13 my $banner = "Round $round: ";
49 13 for my $bracket ( reverse sort keys %$brackets ) {
50 49 my $members = $brackets->{$bracket}->members;
51 49 my $score = $brackets->{$bracket}->score;
52 49 $banner .= "@{[map { $_->pairingNumber } @$members]} ($score), ";
53 }
54 13 print $banner . "\n";
55 13 return bless {
56 round => $round,
57 brackets => $brackets,
58 matches => []
59 },
60 "Games::Tournament::Swiss::Procedure";
61 }
62  
63  
64 =head2 matchPlayers
65  
66 @pairs = $pairing->matchPlayers;
67  
68 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.
69  
70 =cut
71  
72 13 ▶sub matchPlayers {
Subroutine matchPlayers: called CC=7 SCAR=19.5
Pod documented
73 13 my $self = shift;
74 13 my $brackets = $self->brackets;
75 13 my $downfloater;
76 # my @allMatches = @{ $self->matches };
77 my %allMatches;
78 13 my $number = 1;
79 13 for my $score ( reverse sort keys %$brackets ) {
80 49 my @bracketMatches;
81 49 my $players = $brackets->{$score}->members;
82 49 ▶ if ($downfloater) {
Branch: 1 branch
BranchTrueFalseTotal
if ($downfloater) 20 29 49
83 20 unshift @$players, $downfloater;
84 20 undef $downfloater;
85 }
86 49 ▶ $downfloater = pop @$players if @$players % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$players % 2 23 26 49
87 49 for my $table ( 0 .. @$players / 2 - 1 ) {
88 62 push @bracketMatches, Games::Tournament::Card->new(
89 round => $self->round,
90 result => undef,
91 score => $score,
92 contestants => {
93 (ROLES)[0] => $players->[ 2 * $table ],
94 (ROLES)[1] => $players->[ 2 * $table + 1 ]
95 },
96  
97 # floats => \%floats
98 );
99 }
100 49 ▶ if ( $number == keys %$brackets and $downfloater ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number == keys %$brackets and $downfloater) 3 46 49
Condition100%3/3
$number == keys %$brackets and $downfloater
!ll&&!rl&&r
36103
MC/DC100%2/2
$number == keys %$brackets and $downfloater
$number == keys %$brackets $downfloater
Truth table100%3/3
A and B
A= $number == keys %$bracketsB= $downfloater
ABresult
0X0
100
111
101 3 push @bracketMatches, Games::Tournament::Card->new(
102 round => $self->round,
103 result => undef,
104 contestants => { Bye => $downfloater },
105  
106 # floats => \%floats
107 );
108 }
109 49 $allMatches{$score} = \@bracketMatches;
110 49 $number++;
111 }
112 13 $self->matches( \%allMatches );
113 }
114  
115  
116 =head2 brackets
117  
118 $pairing->brackets
119  
120 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.
121  
122 =cut
123  
124 13 ▶sub brackets {
Subroutine brackets: called CC=3 SCAR=12.0
Pod documented
125 13 my $self = shift;
126 13 my $brackets = shift;
127 0 ▶ if ( defined $brackets ) { $self->{brackets} = $brackets; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $brackets) { } 0 13 13
elsif ($self->{'brackets'}) { } 13 0 13
128 13 elsif ( $self->{brackets} ) { return $self->{brackets}; }
129 }
130  
131  
132 =head2 round
133  
134 $pairing->round
135  
136 What round is this round's results we're pairing on the basis of?
137  
138 =cut
139  
140 65 ▶sub round {
Subroutine round: called CC=3 SCAR=12.0
Pod documented
141 65 my $self = shift;
142 65 my $round = shift;
143 0 ▶ if ( defined $round ) { $self->{round} = $round; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $round) { } 0 65 65
elsif ($self->{'round'}) { } 65 0 65
144 65 elsif ( $self->{round} ) { return $self->{round}; }
145 }
146  
147  
148 =head2 matches
149  
150 $group->matches
151  
152 Gets/sets the matches which we have made.
153  
154 =cut
155  
156 16 ▶sub matches {
Subroutine matches: called CC=3 SCAR=11.0
Pod documented
157 16 my $self = shift;
158 16 my $matches = shift;
159 16 ▶ if ( defined $matches ) { $self->{matches} = $matches; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $matches) { } 13 3 16
elsif ($self->{'matches'}) { } 3 0 3
160 3 elsif ( $self->{matches} ) { return $self->{matches}; }
161 }
162  
163 =head1 AUTHOR
164  
165 Dr Bean, C<< <drbean, followed by the at mark (@), cpan, then a dot, and finally, org> >>
166  
167 =head1 BUGS
168  
169 Please report any bugs or feature requests to
170 C<bug-games-tournament-swiss at rt.cpan.org>, or through the web interface at
171 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Tournament-Swiss>.
172 I will be notified, and then you'll automatically be notified of progress on
173 your bug as I make changes.
174  
175 =head1 SUPPORT
176  
177 You can find documentation for this module with the perldoc command.
178  
179 perldoc Games::Tournament::Swiss
180  
181 You can also look for information at:
182  
183 =over 4
184  
185 =item * AnnoCPAN: Annotated CPAN documentation
186  
187 L<http://annocpan.org/dist/Games-Tournament-Swiss>
188  
189 =item * CPAN Ratings
190  
191 L<http://cpanratings.perl.org/d/Games-Tournament-Swiss>
192  
193 =item * RT: CPAN's request tracker
194  
195 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Tournament-Swiss>
196  
197 =item * Search CPAN
198  
199 L<http://search.cpan.org/dist/Games-Tournament-Swiss>
200  
201 =back
202  
203 =head1 ACKNOWLEDGEMENTS
204  
205 See L<http://www.fide.com/official/handbook.asp?level=C04> for the FIDE's Swiss rules.
206  
207 =head1 COPYRIGHT & LICENSE
208  
209 Copyright 2006 Dr Bean, all rights reserved.
210  
211 This program is free software; you can redistribute it and/or modify it
212 under the same terms as Perl itself.
213  
214 =cut
215  
216 9 1; # End of Games::Tournament::Swiss::Procedure
217  
218 # vim: set ts=8 sts=4 sw=4 noet:
« blib/lib/Games/Tournament/Contestant/Swiss.pm ↑ Summary script_files/pairingtable »