line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::SGF::Tournament; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
76828
|
use version; $VERSION = qv(1.0); |
|
2
|
|
|
|
|
4743
|
|
|
2
|
|
|
|
|
12
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
158
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
6
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
63
|
|
7
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
175
|
|
8
|
2
|
|
|
2
|
|
3974
|
use CGI qw/ :html /; |
|
2
|
|
|
|
|
33815
|
|
|
2
|
|
|
|
|
16
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
1
|
881
|
my $class = shift; |
12
|
1
|
|
|
|
|
5
|
my %params = @_; |
13
|
1
|
|
50
|
|
|
5
|
$params{sgf_dir} ||= '.'; |
14
|
1
|
|
50
|
|
|
5
|
$params{base_url} ||= ''; |
15
|
1
|
|
|
|
|
2
|
my %scores; |
16
|
|
|
|
|
|
|
my @games; |
17
|
1
|
|
|
|
|
3
|
undef $/; |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
42
|
unless (opendir(SGF, $params{sgf_dir})) { |
20
|
0
|
|
|
|
|
0
|
carp "While opening directory \"$params{sgf_dir}\": $!"; |
21
|
0
|
|
|
|
|
0
|
return undef; |
22
|
|
|
|
|
|
|
} |
23
|
1
|
|
|
|
|
66
|
foreach (grep { /.*\.sgf$/ } readdir SGF) { |
|
3
|
|
|
|
|
15
|
|
24
|
1
|
50
|
|
|
|
39
|
open IN, "$params{sgf_dir}/$_" or next; |
25
|
1
|
|
|
|
|
28
|
my $sgf_content = ; |
26
|
1
|
|
|
|
|
10
|
close IN; |
27
|
1
|
|
|
|
|
5
|
my %game_info = ( file => "$params{base_url}$_" ); |
28
|
1
|
|
|
|
|
4
|
foreach (qw/ RU SZ HA KM PW PB DT TM RE /) { |
29
|
9
|
50
|
|
|
|
126
|
if ($sgf_content =~ /$_\[(.*?)\]/) { |
30
|
9
|
|
|
|
|
32
|
$game_info{$_} = $1; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
0
|
$game_info{$_} = '?'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
1
|
|
|
|
|
3
|
push @games, \%game_info; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
5
|
$game_info{RE} =~ /^([BW])\+/o; |
38
|
1
|
|
|
|
|
3
|
foreach (qw/ B W /) { |
39
|
2
|
100
|
|
|
|
14
|
$scores{$game_info{"P$_"}} += $1 eq $_ ? 1:0; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
8
|
bless { games => \@games, scores => \%scores }, $class; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub games { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my @rows = TR( |
48
|
|
|
|
|
|
|
th('Game#'), |
49
|
|
|
|
|
|
|
th('Black'), |
50
|
|
|
|
|
|
|
th('White'), |
51
|
|
|
|
|
|
|
th('Setup'), |
52
|
|
|
|
|
|
|
th('Date'), |
53
|
|
|
|
|
|
|
th('Result') |
54
|
|
|
|
|
|
|
); |
55
|
0
|
|
|
|
|
|
my $i; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
foreach (sort { $a->{DT} cmp $b->{DT} } @{ $self->{games} }) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
push @rows, TR( |
59
|
|
|
|
|
|
|
td(a({ -href => $_->{file} }, ++$i)), |
60
|
|
|
|
|
|
|
td($_->{PB}), |
61
|
|
|
|
|
|
|
td($_->{PW}), |
62
|
|
|
|
|
|
|
td("$_->{RU}/$_->{SZ}/$_->{HA}/$_->{KM}/$_->{TM}"), |
63
|
|
|
|
|
|
|
td($_->{DT}), |
64
|
|
|
|
|
|
|
td($_->{RE}) |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return table({ -border => 1 }, |
69
|
|
|
|
|
|
|
caption('Table of played games'), |
70
|
|
|
|
|
|
|
@rows |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub scores { |
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my @rows = TR( |
77
|
|
|
|
|
|
|
th('Pos#'), |
78
|
|
|
|
|
|
|
th('Name'), |
79
|
|
|
|
|
|
|
th('Score') |
80
|
|
|
|
|
|
|
); |
81
|
0
|
|
|
|
|
|
my $i; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
foreach (sort { $self->{scores}->{$b} <=> $self->{scores}->{$a} } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
(keys %{ $self->{scores} }) |
85
|
|
|
|
|
|
|
) { |
86
|
0
|
|
|
|
|
|
push @rows, TR( |
87
|
|
|
|
|
|
|
td(++$i), |
88
|
|
|
|
|
|
|
td($_), |
89
|
|
|
|
|
|
|
td($self->{scores}->{$_}) |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return table({ -border => 1 }, |
94
|
|
|
|
|
|
|
caption('Scoreboard'), |
95
|
|
|
|
|
|
|
@rows |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |