| 1 | package Game::Go::GTP; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Game::Go; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Game::Go::Bot; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Game::Go::Rules; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Game::Go::Notation; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | my $B = Game::Go::Rules::BLACK; | |||||||||||||||||||||||||||
| 17 | 2 | my $W = Game::Go::Rules::WHITE; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | has game => (is => 'rw'); | |||||||||||||||||||||||||||
| 20 | 2 | has bot => (is => 'rw'); | |||||||||||||||||||||||||||
| 21 | 2 | has size => (is => 'rw', isa => Int, default => 19); | |||||||||||||||||||||||||||
| 22 | 2 | has komi => (is => 'rw', default => 6.5); | |||||||||||||||||||||||||||
| 23 | 2 | has level => (is => 'ro', isa => Int, default => 2); | |||||||||||||||||||||||||||
| 24 | 2 | has seed => (is => 'ro', default => 'gtp'); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | has quit => (is => 'rw', default => 0); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | our @COMMANDS; | |||||||||||||||||||||||||||
| 29 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | @COMMANDS = qw( | |||||||||||||||||||||||||||
| 31 | protocol_version name version known_command list_commands quit | ||||||||||||||||||||||||||||
| 32 | boardsize clear_board komi play genmove undo showboard | ||||||||||||||||||||||||||||
| 33 | final_score final_status_list | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 13 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||
| 39 | 13 | $self->_reset; | |||||||||||||||||||||||||||
| 40 | 13 | return; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 24 | ▶ | sub _reset { | ||||||||||||||||||||||||||
|
Subroutine
_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||
| 45 | 24 | $self->game(Game::Go->new( | |||||||||||||||||||||||||||
| 46 | size => $self->size, | ||||||||||||||||||||||||||||
| 47 | komi => $self->komi, | ||||||||||||||||||||||||||||
| 48 | seed => $self->seed, | ||||||||||||||||||||||||||||
| 49 | ko => 'simple', | ||||||||||||||||||||||||||||
| 50 | )); | ||||||||||||||||||||||||||||
| 51 | 24 | $self->bot(Game::Go::Bot->new(level => $self->level, seed => $self->seed)); | |||||||||||||||||||||||||||
| 52 | 24 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 72 | ▶ | sub handle { | ||||||||||||||||||||||||||
|
Subroutine
handle: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 72 | my ($self, $line) = @_; | |||||||||||||||||||||||||||
| 57 | 72 | ▶ | return '' unless defined $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 72 | $line =~ s/#.*\z//; | |||||||||||||||||||||||||||
| 60 | 72 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||
| 61 | 72 | $line =~ s/\A\s+//; | |||||||||||||||||||||||||||
| 62 | 72 | ▶ | return '' unless length $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 69 | my ($id, @words) = (); | |||||||||||||||||||||||||||
| 65 | 69 | my @parts = split /\s+/, $line; | |||||||||||||||||||||||||||
| 66 | 69 | ▶ | $id = shift @parts if @parts && $parts[0] =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@parts and $parts[0] =~ /\A[0-9]+\z/
MC/DC50%1/2
@parts and $parts[0] =~ /\A[0-9]+\z/
@parts
$parts[0] =~ /\A[0-9]+\z/
Truth table66%2/3
A and B
A= @partsB= $parts[0] =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||
| 67 | 69 | ▶ | my $cmd = lc(shift(@parts) // ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @parts // ""
MC/DC0%0/1
shift @parts // ""
shift @parts
Truth table50%1/2
A
A= shift @parts
| |||||||||||||||||||||||||||||
| 68 | 69 | @words = @parts; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 69 | ▶ | my $tag = defined $id ? $id : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 69 | ▶ | unless (grep { $_ eq $cmd } @COMMANDS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 3 | return "?$tag unknown command\n\n"; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 66 | my ($ok, $body) = $self->_run($cmd, \@words); | |||||||||||||||||||||||||||
| 77 | 66 | ▶ | $body = '' unless defined $body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 66 | ▶ | return ($ok ? '=' : '?') . "$tag $body\n\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 66 | ▶ | sub _run { | ||||||||||||||||||||||||||
|
Subroutine
_run: called CC=51 SCAR=40.4
| |||||||||||||||||||||||||||||
| 82 | 66 | my ($self, $cmd, $words) = @_; | |||||||||||||||||||||||||||
| 83 | 66 | my $game = $self->game; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 66 | ▶ | return (1, '2') if $cmd eq 'protocol_version'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 61 | ▶ | return (1, 'Game::Go') if $cmd eq 'name'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 60 | ▶ | return (1, $Game::Go::VERSION) if $cmd eq 'version'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 59 | ▶ | return (1, join "\n", @COMMANDS) if $cmd eq 'list_commands'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 58 | ▶ | return (1, (grep { $_ eq lc($words->[0] // '') } @COMMANDS) ? 'true' : 'false') | ||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$words->[0] // ""
MC/DC0%0/1
$words->[0] // ""
$words->[0]
Truth table50%1/2
A
A= $words->[0]
| |||||||||||||||||||||||||||||
| 90 | if $cmd eq 'known_command'; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 47 | ▶ | if ($cmd eq 'quit') { $self->quit(1); return (1, '') } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 45 | ▶ | if ($cmd eq 'boardsize') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 11 | ▶ | my $n = $words->[0] // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$words->[0] // ""
MC/DC0%0/1
$words->[0] // ""
$words->[0]
Truth table50%1/2
A
A= $words->[0]
| |||||||||||||||||||||||||||||
| 96 | return (0, 'unacceptable size') | ||||||||||||||||||||||||||||
| 97 | 11 | ▶ | unless $n =~ /\A[0-9]+\z/ && grep { $_ == $n } Game::Go->sizes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n =~ /\A[0-9]+\z/ and grep {$_ == $n;} "Game::Go"->sizes
MC/DC100%2/2
$n =~ /\A[0-9]+\z/ and grep {$_ == $n;} "Game::Go"->sizes
$n =~ /\A[0-9]+\z/
grep {$_ == $n;} "Game::Go"->sizes
Truth table100%3/3
A and B
A= $n =~ /\A[0-9]+\z/B= grep {$_ == $n;} "Game::Go"->sizes
| |||||||||||||||||||||||||||||
| 98 | 9 | $self->size($n); | |||||||||||||||||||||||||||
| 99 | 9 | $self->_reset; | |||||||||||||||||||||||||||
| 100 | 9 | return (1, ''); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 34 | ▶ | if ($cmd eq 'clear_board') { $self->_reset; return (1, '') } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 33 | ▶ | if ($cmd eq 'komi') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 2 | ▶ | my $k = $words->[0] // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$words->[0] // ""
MC/DC0%0/1
$words->[0] // ""
$words->[0]
Truth table50%1/2
A
A= $words->[0]
| |||||||||||||||||||||||||||||
| 107 | 2 | ▶ | return (0, 'syntax error') unless $k =~ /\A-?[0-9]+(?:\.[0-9]+)?\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 1 | $self->komi($k + 0); | |||||||||||||||||||||||||||
| 109 | 1 | $self->_reset; | |||||||||||||||||||||||||||
| 110 | 1 | return (1, ''); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 31 | ▶ | if ($cmd eq 'play') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 20 | my $colour = $self->_colour($words->[0]); | |||||||||||||||||||||||||||
| 115 | 20 | ▶ | return (0, 'syntax error') unless $colour; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 19 | ▶ | my $where = uc($words->[1] // ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
$words->[1] // ""
MC/DC0%0/1
$words->[1] // ""
$words->[1]
Truth table50%1/2
A
A= $words->[1]
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 19 | ▶ | if ($where eq 'PASS') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 3 | my $out = $game->pass($colour); | |||||||||||||||||||||||||||
| 120 | 3 | ▶ | return (0, 'illegal move') if ref $out eq 'Game::Go::Error'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 3 | return (1, ''); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 16 | my ($col, $row) = Game::Go::Notation::from_human($game->size, $where); | |||||||||||||||||||||||||||
| 125 | 16 | ▶ | return (0, 'invalid coordinate') unless defined $col; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 13 | ▶ | $game->turn($colour) if $game->turn != $colour && $game->phase eq 'play'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$game->turn != $colour and $game->phase eq "play"
MC/DC0%0/2
$game->turn != $colour and $game->phase eq "play"
$game->turn != $colour
$game->phase eq "play"
Truth table33%1/3
A and B
A= $game->turn != $colourB= $game->phase eq "play"
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 13 | my $out = $game->play($colour, $game->point($col, $row)); | |||||||||||||||||||||||||||
| 130 | 13 | ▶ | return (0, 'illegal move') if ref $out eq 'Game::Go::Error'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 11 | return (1, ''); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 11 | ▶ | if ($cmd eq 'genmove') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 2 | my $colour = $self->_colour($words->[0]); | |||||||||||||||||||||||||||
| 136 | 2 | ▶ | return (0, 'syntax error') unless $colour; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 2 | ▶ | return (1, 'resign') unless $game->status eq 'active'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | ▶ | $game->turn($colour) if $game->phase eq 'play' && $game->turn != $colour; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$game->phase eq "play" and $game->turn != $colour
MC/DC0%0/2
$game->phase eq "play" and $game->turn != $colour
$game->phase eq "play"
$game->turn != $colour
Truth table33%1/3
A and B
A= $game->phase eq "play"B= $game->turn != $colour
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | my $move = $self->bot->choose($game, $colour); | |||||||||||||||||||||||||||
| 142 | 2 | ▶ | return (1, 'pass') unless $move && $move->kind eq 'play'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$move and $move->kind eq "play"
MC/DC0%0/2
$move and $move->kind eq "play"
$move
$move->kind eq "play"
Truth table33%1/3
A and B
A= $moveB= $move->kind eq "play"
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 2 | my ($col, $row) = $game->col_row($move->point); | |||||||||||||||||||||||||||
| 145 | 2 | my $where = Game::Go::Notation::to_human($game->size, $col, $row); | |||||||||||||||||||||||||||
| 146 | 2 | $game->play($colour, $move->point); | |||||||||||||||||||||||||||
| 147 | 2 | return (1, $where); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 9 | ▶ | if ($cmd eq 'undo') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 3 | my $events = $game->events; | |||||||||||||||||||||||||||
| 152 | 3 | my $cut = -1; | |||||||||||||||||||||||||||
| 153 | 3 | for my $i (reverse 0 .. $#$events) { | |||||||||||||||||||||||||||
| 154 | 3 | ▶ | next if $events->[$i]{actor} eq 'sys'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 2 | $cut = $i; | |||||||||||||||||||||||||||
| 156 | 2 | last; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 3 | ▶ | return (0, 'cannot undo') if $cut < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 2 | my @keep = @$events[0 .. $cut - 1]; | |||||||||||||||||||||||||||
| 161 | 2 | my $fresh = Game::Go->new( | |||||||||||||||||||||||||||
| 162 | size => $game->size, komi => $game->komi, | ||||||||||||||||||||||||||||
| 163 | seed => $self->seed, ko => 'simple', | ||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||
| 165 | 2 | ▶ | eval { $fresh->replay(\@keep); 1 } or return (0, 'cannot undo'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 2 | $self->game($fresh); | |||||||||||||||||||||||||||
| 167 | 2 | return (1, ''); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 6 | ▶ | if ($cmd eq 'showboard') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 2 | return (1, "\n" . $game->board->to_text); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 4 | ▶ | if ($cmd eq 'final_score') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 1 | my $raw = $game->raw_score; | |||||||||||||||||||||||||||
| 176 | 1 | my ($b, $w) = ($raw->{score_b} / 10, $raw->{score_w} / 10); | |||||||||||||||||||||||||||
| 177 | 1 | ▶ | return (1, '0') if $b == $w; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 1 | ▶ | return (1, $b > $w ? sprintf('B+%s', $b - $w) : sprintf('W+%s', $w - $b)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 3 | ▶ | if ($cmd eq 'final_status_list') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 3 | ▶ | my $what = lc($words->[0] // 'dead'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$words->[0] // "dead"
MC/DC0%0/1
$words->[0] // "dead"
$words->[0]
Truth table50%1/2
A
A= $words->[0]
| |||||||||||||||||||||||||||||
| 183 | 3 | ▶ | return (0, 'syntax error') unless $what =~ /\A(?:dead|alive)\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 2 | my $dead = $game->dead_guess_from(playouts => 60, seed => 1); | |||||||||||||||||||||||||||
| 186 | 2 | my %dead = map { $_ => 1 } @$dead; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 2 | my @out; | |||||||||||||||||||||||||||
| 189 | 2 | for my $row (0 .. $game->size - 1) { | |||||||||||||||||||||||||||
| 190 | 18 | for my $col (0 .. $game->size - 1) { | |||||||||||||||||||||||||||
| 191 | 162 | my $pt = $game->point($col, $row); | |||||||||||||||||||||||||||
| 192 | 162 | my $at = $game->board->at($col, $row); | |||||||||||||||||||||||||||
| 193 | 162 | ▶ | next unless Game::Go::Rules::is_colour($at); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 4 | ▶ | my $is_dead = $dead{$pt} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 4 | ▶ | next unless $what eq ($is_dead ? 'dead' : 'alive'); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 196 | 2 | push @out, Game::Go::Notation::to_human($game->size, $col, $row); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 2 | return (1, join ' ', @out); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | return (0, 'unknown command'); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 22 | ▶ | sub _colour { | ||||||||||||||||||||||||||
|
Subroutine
_colour: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 206 | 22 | my ($self, $word) = @_; | |||||||||||||||||||||||||||
| 207 | 22 | ▶ | return undef unless defined $word; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 22 | my $c = lc $word; | |||||||||||||||||||||||||||
| 209 | 22 | ▶ | return $B if $c eq 'b' || $c eq 'black'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c eq "b" or $c eq "black"
MC/DC50%1/2
$c eq "b" or $c eq "black"
$c eq "b"
$c eq "black"
Truth table66%2/3
A or B
A= $c eq "b"B= $c eq "black"
| |||||||||||||||||||||||||||||
| 210 | 8 | ▶ | return $W if $c eq 'w' || $c eq 'white'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c eq "w" or $c eq "white"
MC/DC50%1/2
$c eq "w" or $c eq "white"
$c eq "w"
$c eq "white"
Truth table66%2/3
A or B
A= $c eq "w"B= $c eq "white"
| |||||||||||||||||||||||||||||
| 211 | 1 | return undef; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 1 | my ($self, $in, $out) = @_; | |||||||||||||||||||||||||||
| 216 | 1 | ▶ | while (my $line = <$in>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 4 | my $response = $self->handle($line); | |||||||||||||||||||||||||||
| 218 | 4 | ▶ | next unless length $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 4 | print {$out} $response; | |||||||||||||||||||||||||||
| 220 | 4 | ▶ | last if $self->quit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | 1 | return 0; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 2 | 1; | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | __END__ | ||||||||||||||||||||||||||||