blib/lib/Game/Go/Board.pm

filter: Statementstmt 100% 58 / 58 Branchbran 58.3% 7 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 16 / 16 Podpod 91.6% 11 / 12 totaltotal 92.0% 93 / 101 CC 9 SCAR 5.2
CC
9
Cov
92%
new
2.0
libs
2.0
chain_size
2.0
CRAP 1.7
« blib/lib/Game/Go/Error.pm ↑ Summary blib/lib/Game/Go/Marking.pm »
1 package Game::Go::Board;
2  
3 25 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶use Game::Go::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 25 our $VERSION = '0.02';
10  
11 533 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
12 533 my ($class, $engine) = @_;
13 533 ▶ die 'Game::Go::Board: wants a Game::Go::Engine' unless ref $engine;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $engine 0 533 533
14 533 return bless { engine => $engine }, $class;
15 }
16  
17 531 ▶sub size { $_[0]{engine}->size }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
18  
19 21087 ▶sub at {
Subroutine at: called CC=2 SCAR=6.9
Pod documented
20 21087 my ($self, $col, $row) = @_;
21 21087 my $pt = $self->{engine}->point_of($col, $row);
22 21087 ▶ return Game::Go::Rules::BORDER if $pt < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pt < 0 1 21086 21087
23 21086 return $self->{engine}->at($pt);
24 }
25  
26 196 ▶sub libs {
Subroutine libs: called CC=2 SCAR=7.0
Pod documented
27 196 my ($self, $col, $row) = @_;
28 196 my $pt = $self->{engine}->point_of($col, $row);
29 196 ▶ return -1 if $pt < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pt < 0 0 196 196
30 196 return $self->{engine}->libs($pt);
31 }
32  
33 482 ▶sub chain_size {
Subroutine chain_size: called CC=2 SCAR=7.0
Pod documented
34 482 my ($self, $col, $row) = @_;
35 482 my $pt = $self->{engine}->point_of($col, $row);
36 482 ▶ return 0 if $pt < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pt < 0 0 482 482
37 482 return $self->{engine}->chain_size($pt);
38 }
39  
40 457 ▶sub chain_at {
Subroutine chain_at: called CC=2 SCAR=7.0
Pod documented
41 457 my ($self, $col, $row) = @_;
42 457 my $engine = $self->{engine};
43 457 my $pt = $engine->point_of($col, $row);
44 457 ▶ return [] if $pt < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pt < 0 0 457 457
45 457 return [ map { [ $engine->col_of($_), $engine->row_of($_) ] } @{ $engine->chain_at($pt) } ];
46 }
47  
48 13 ▶sub rows {
Subroutine rows: called CC=2 SCAR=6.9
Pod documented
49 13 my ($self) = @_;
50 13 my $size = $self->size;
51 13 my @rows;
52 13 for my $row (0 .. $size - 1) {
53 137 push @rows, [ map { $self->at($_, $row) } 0 .. $size - 1 ];
54 }
55 13 return \@rows;
56 }
57  
58 52 ▶sub stones { $_[0]{engine}->stones($_[1]) }
Subroutine stones: called CC=1 SCAR=0.0
Pod documented
59  
60 16 ▶sub hash_hex { $_[0]{engine}->hash_hex }
Subroutine hash_hex: called CC=1 SCAR=0.0
Pod documented
61  
62 455 ▶sub zobrist_hex {
Subroutine zobrist_hex: called CC=2 SCAR=7.0
Pod documented
63 455 my ($self, $colour, $col, $row) = @_;
64 455 my $pt = $self->{engine}->point_of($col, $row);
65 455 ▶ return undef if $pt < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pt < 0 0 455 455
66 455 return $self->{engine}->zobrist_hex($colour, $pt);
67 }
68  
69 1 ▶sub empties {
Subroutine empties: called CC=1 SCAR=0.0
Pod documented
70 1 my ($self) = @_;
71 1 my $size = $self->size;
72 1 return $size * $size
73 - $self->stones(Game::Go::Rules::BLACK)
74 - $self->stones(Game::Go::Rules::WHITE);
75 }
76  
77 13 ▶sub to_text {
Subroutine to_text: called CC=2 SCAR=7.0
Pod documented
78 13 my ($self) = @_;
79 13 my %glyph = (
80 Game::Go::Rules::EMPTY, '.',
81 Game::Go::Rules::BLACK, 'X',
82 Game::Go::Rules::WHITE, 'O',
83 );
84 13 ▶ return join "\n", map { join '', map { $glyph{$_} // '?' } @$_ } @{ $self->rows };
Condition50%1/2
$glyph{$_} // "?"
l!l
16130
MC/DC0%0/1
$glyph{$_} // "?"
$glyph{$_}
Truth table50%1/2
A
A= $glyph{$_}
Aresult
11
00
85 }
86  
87 25 1;
88  
89 __END__
« blib/lib/Game/Go/Error.pm ↑ Summary blib/lib/Game/Go/Marking.pm »