line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::SGF::Tournament; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
88692
|
use version; $VERSION = qv('1.1_2'); |
|
2
|
|
|
|
|
5207
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
243
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
69
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
64
|
|
6
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
196
|
|
7
|
2
|
|
|
2
|
|
4906
|
use CGI qw/ :html /; |
|
2
|
|
|
|
|
38225
|
|
|
2
|
|
|
|
|
17
|
|
8
|
2
|
|
|
2
|
|
9064
|
use Parse::RecDescent; |
|
2
|
|
|
|
|
121920
|
|
|
2
|
|
|
|
|
18
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
1
|
1553
|
my $class = shift; |
12
|
1
|
|
|
|
|
7
|
my %params = @_; |
13
|
1
|
50
|
|
|
|
8
|
$params{sgf_dir} = '.' unless defined $params{sgf_dir}; |
14
|
1
|
50
|
|
|
|
6
|
$params{base_url} = '' unless defined $params{base_url}; |
15
|
1
|
|
|
|
|
2
|
my @games; |
16
|
1
|
|
|
|
|
5
|
undef $/; |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
54
|
unless (opendir(SGF, $params{sgf_dir})) { |
19
|
0
|
|
|
|
|
0
|
carp "While opening directory \"$params{sgf_dir}\": $!"; |
20
|
0
|
|
|
|
|
0
|
return undef; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
12
|
my $parser = Parse::RecDescent->new(q< |
24
|
|
|
|
|
|
|
{ my %info } |
25
|
|
|
|
|
|
|
SGF: GameTree { $return = \%info } |
26
|
|
|
|
|
|
|
GameTree: '(' Node(s) GameTree(s?) ')' |
27
|
|
|
|
|
|
|
Node: ';' Property(s?) |
28
|
|
|
|
|
|
|
Property: PropIdent PropValue(s) { |
29
|
|
|
|
|
|
|
$info{$item{PropIdent}} = |
30
|
|
|
|
|
|
|
join ';', @{$item{'PropValue(s)'}} |
31
|
|
|
|
|
|
|
if grep $item{PropIdent} eq $_, |
32
|
|
|
|
|
|
|
qw/ RU SZ HA KM PW PB DT TM RE /; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
PropIdent: /[[:alnum:]]+/o { |
35
|
|
|
|
|
|
|
($return = $item[1]) =~ s/[^[:upper:]\d]//go; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
PropValue: '[' Character(s?) ']' { |
38
|
|
|
|
|
|
|
$return = join '', @{$item{'Character(s?)'}} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
Character: /[^\\\\\]]+/so | Escaped |
41
|
|
|
|
|
|
|
Escaped: '\\\\' | '\]' { $return = substr $item[1], 1 } |
42
|
|
|
|
|
|
|
>); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
54801
|
foreach (grep { /.*\.sgf$/io } readdir SGF) { |
|
3
|
|
|
|
|
22
|
|
45
|
1
|
50
|
|
|
|
335
|
open IN, "$params{sgf_dir}/$_" or next; |
46
|
1
|
|
|
|
|
4
|
my %info = %{$parser->SGF()}; |
|
1
|
|
|
|
|
69
|
|
47
|
1
|
|
|
|
|
157187
|
foreach (qw/ RU SZ HA KM PW PB DT TM RE /) { |
48
|
9
|
50
|
|
|
|
24
|
$info{$_} = '' unless defined $info{$_}; |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
|
|
|
5
|
$info{file} = "$params{base_url}$_" ; |
51
|
1
|
|
|
|
|
6
|
push @games, \%info; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
16
|
bless { _games => \@games }, $class; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub games { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
my %params = @_; |
60
|
0
|
0
|
|
|
|
|
$params{cgi}->{border} = '1' unless defined $params{cgi}->{border}; |
61
|
0
|
0
|
|
|
|
|
$params{caption} = 'Played games' unless defined $params{caption}; |
62
|
0
|
|
|
|
|
|
my @rows = TR( |
63
|
|
|
|
|
|
|
th('Game#'), |
64
|
|
|
|
|
|
|
th('Black'), |
65
|
|
|
|
|
|
|
th('White'), |
66
|
|
|
|
|
|
|
th('Setup'), |
67
|
|
|
|
|
|
|
th('Date'), |
68
|
|
|
|
|
|
|
th('Result') |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $i; |
72
|
0
|
|
|
|
|
|
foreach (sort { $a->{DT} cmp $b->{DT} } @{$self->{_games}}) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
push @rows, TR( |
74
|
|
|
|
|
|
|
td(a({ -href => $_->{file} }, ++$i)), |
75
|
|
|
|
|
|
|
td($_->{PB}), |
76
|
|
|
|
|
|
|
td($_->{PW}), |
77
|
|
|
|
|
|
|
td("$_->{RU}/$_->{SZ}/$_->{HA}/$_->{KM}/$_->{TM}"), |
78
|
|
|
|
|
|
|
td($_->{DT}), |
79
|
|
|
|
|
|
|
td($_->{RE}) |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
table($params{cgi}, caption($params{caption}), @rows); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub scores { |
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
my %params = @_; |
89
|
0
|
0
|
|
|
|
|
$params{cgi}->{border} = '1' unless defined $params{cgi}->{border}; |
90
|
0
|
0
|
|
|
|
|
$params{caption} = 'Scoreboard' unless defined $params{caption}; |
91
|
0
|
|
|
|
|
|
my @rows = TR( |
92
|
|
|
|
|
|
|
th('Pos#'), |
93
|
|
|
|
|
|
|
th('Name'), |
94
|
|
|
|
|
|
|
th('Score') |
95
|
|
|
|
|
|
|
); |
96
|
0
|
|
|
|
|
|
my %scores; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
foreach my $info (@{$self->{_games}}) { |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$info->{RE} =~ /^([BW])\+/o; |
100
|
0
|
|
|
|
|
|
foreach (qw/ B W /) { |
101
|
0
|
0
|
|
|
|
|
$scores{$info->{"P$_"}} += $1 eq $_ ? 1:0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $i; |
106
|
0
|
|
|
|
|
|
foreach (sort { $scores{$b} <=> $scores{$a} } keys %scores) { |
|
0
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
push @rows, TR( |
108
|
|
|
|
|
|
|
td(++$i), |
109
|
|
|
|
|
|
|
td($_), |
110
|
|
|
|
|
|
|
td($scores{$_}) |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
table($params{cgi}, caption($params{caption}), @rows); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |