| 1 | package Game::Xiangqi; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Game::Xiangqi::Engine ':all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Game::Xiangqi::Notation; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Game::Xiangqi::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | my $E = 'Game::Xiangqi::Engine'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | my $N = 'Game::Xiangqi::Notation'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | my $R = 'Game::Xiangqi::Error'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | has red => (is => 'ro', isa => Str, default => 'p1'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | has status => (is => 'rw', isa => Str, default => 'active'); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | has _held_seed => (is => 'ro', init_arg => 'seed'); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | has _pos => (is => 'rw', init_arg => 'position', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | has _start => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | has _log => (is => 'ro', isa => ArrayRef, default => [], private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | has _played => (is => 'ro', isa => ArrayRef, default => [], private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | has _result => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 84 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 84 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 84 | my $seed = $self->_held_seed; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 84 | ▶ | Carp::croak('Game::Xiangqi: seed must be exactly thirty-two bytes') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $seed and length $seed == 32
MC/DC100%2/2
defined $seed and length $seed == 32
defined $seed
length $seed == 32
Truth table100%3/3
A and B
A= defined $seedB= length $seed == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | unless defined $seed && length($seed) == 32; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 82 | my $red = $self->red; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 82 | ▶ | Carp::croak("Game::Xiangqi: red must be 'p1' or 'p2', not '$red'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$red eq "p1" or $red eq "p2"
MC/DC100%2/2
$red eq "p1" or $red eq "p2"
$red eq "p1"
$red eq "p2"
Truth table100%3/3
A or B
A= $red eq "p1"B= $red eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | unless $red eq 'p1' || $red eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 81 | ▶ | my $pos = $self->_pos ? $self->_pos->clone : $E->new; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 81 | $self->_pos($pos); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 81 | $self->_start($pos->clone); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 81 | $self->_result({ winner => undef, reason => undef, rule => 0, loop => undef }); | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 81 | $self->_settle; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 81 | return; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 188 | ▶ | sub position { $_[0]->_pos } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | ▶ | sub signature { $_[0]->_pos->key_hex } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 24 | ▶ | sub log { [ @{ $_[0]->_log } ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 242 | ▶ | sub _seat_of { $_[1] == RED ? $_[0]->red : ($_[0]->red eq 'p1' ? 'p2' : 'p1') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seat_of: called CC=3 SCAR=11.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub _colour_of { $_[1] eq $_[0]->red ? RED : BLACK } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colour_of: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 234 | ▶ | sub turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 234 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 234 | ▶ | return undef unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 234 | return $self->_seat_of($self->_pos->side); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 15 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 15 | ▶ | return [] unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 14 | return [ map { $N->iccs_of($_) } $self->_pos->legal ]; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | sub seed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seed: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | ▶ | return undef unless $self->status eq 'finished'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | return $self->_held_seed; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 237 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 237 | my ($self, $iccs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 237 | ▶ | return $R->throw('game_over') unless $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 236 | my $mv = $N->move_of_iccs($iccs); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 236 | ▶ | return $R->throw('bad_move') unless defined $mv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 227 | my $why = $self->_refuse($mv); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 227 | ▶ | return $why if $why; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 195 | push @{ $self->_log }, $N->iccs_of($mv); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 195 | push @{ $self->_played }, $mv; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 195 | $self->_pos->do_move($mv); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 195 | $self->_settle; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 195 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 276 | ▶ | sub _settle { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_settle: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 276 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 276 | my ($winner, $reason) = $self->_pos->outcome; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 276 | ▶ | if ($winner) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | $self->status('finished'); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | ▶ | $self->_result({ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | winner => $self->_seat_of($winner), | ||||||||||||||||||||||||||||||||||||||||||
| 107 | reason => $reason == BY_CHECKMATE ? 'checkmate' : 'stalemate', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | rule => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | loop => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 270 | my $v = $self->_start->judge($self->_played); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 270 | ▶ | return unless $v->{reason} != J_ONGOING; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | my %name = ( | |||||||||||||||||||||||||||||||||||||||||
| 118 | J_PERPETUAL_CHECK() => 'perpetual_check', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | J_PERPETUAL_CHASE() => 'perpetual_chase', | ||||||||||||||||||||||||||||||||||||||||||
| 120 | J_MUTUAL() => 'mutual', | ||||||||||||||||||||||||||||||||||||||||||
| 121 | J_NO_VIOLATION() => 'no_violation', | ||||||||||||||||||||||||||||||||||||||||||
| 122 | J_EFFECTIVE() => 'effective', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | J_PROGRESS() => 'progress', | ||||||||||||||||||||||||||||||||||||||||||
| 124 | J_MOVES() => 'moves', | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | $self->status('finished'); | |||||||||||||||||||||||||||||||||||||||||
| 127 | $self->_result({ | ||||||||||||||||||||||||||||||||||||||||||
| 128 | winner => $v->{winner} ? $self->_seat_of($v->{winner}) : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | reason => $name{ $v->{reason} }, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | rule => $v->{rule}, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | loop => $v->{loop_from} >= 0 | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | ▶ | ? [ @{ $self->_log }[ $v->{loop_from} .. $#{ $self->_log } ] ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 227 | ▶ | sub _refuse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refuse: called CC=27 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 227 | my ($self, $mv) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 227 | my $p = $self->_pos; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 227 | my ($from, $to) = ($E->move_from($mv), $E->move_to($mv)); | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 227 | my $piece = $p->at($from); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 227 | ▶ | return $R->throw('no_piece') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$piece and $piece != 32 and Game::Xiangqi::Engine::kind_of($piece)
$piece and $piece != 32
MC/DC33%1/3
$piece and $piece != 32 and Game::Xiangqi::Engine::kind_of($piece)
$piece
$piece != 32
Game::Xiangqi::Engine::kind_of($piece)
Truth table50%2/4
A and B and C
A= $pieceB= $piece != 32C= Game::Xiangqi::Engine::kind_of($piece)
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | unless $piece && $piece != BORDER && Game::Xiangqi::Engine::kind_of($piece); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 224 | ▶ | return $R->throw('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | unless Game::Xiangqi::Engine::colour_of($piece) == $p->side; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 220 | ▶ | return 0 if grep { $_ == $mv } $p->legal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 25 | ▶ | if (grep { $_ == $mv } $p->moves) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | my (undef, $u) = $p->do_move($mv); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | my $face = $p->generals_face; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | $p->undo_move($u); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | return $R->throw($face ? 'generals_face' : 'in_check', legal => $self->legal); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 23 | my $kind = Game::Xiangqi::Engine::kind_of($piece); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 23 | my $colour = Game::Xiangqi::Engine::colour_of($piece); | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 23 | ▶ | return $R->throw('own_piece') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | if Game::Xiangqi::Engine::colour_of($p->at($to)) == $colour; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 17 | ▶ | if ($kind == GENERAL) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | return $R->throw('general_leaves_palace') unless $E->in_palace($to, $colour); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | elsif ($kind == ADVISOR) { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | return $R->throw('advisor_leaves_palace') unless $E->in_palace($to, $colour); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | elsif ($kind == ELEPHANT) { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | ▶ | return $R->throw('elephant_crosses_river') if $E->crossed_river($to, $colour); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | my $eye = $p->elephant_eye($from, $to); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | return $R->throw('elephant_eye_blocked') if $eye >= 0 && $p->at($eye) != EMPTY; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$eye >= 0 and $p->at($eye) != 0
MC/DC0%0/2
$eye >= 0 and $p->at($eye) != 0
$eye >= 0
$p->at($eye) != 0
Truth table33%1/3
A and B
A= $eye >= 0B= $p->at($eye) != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | elsif ($kind == HORSE) { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | my $leg = $p->horse_leg($from, $to); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | return $R->throw('horse_leg_blocked') if $leg >= 0 && $p->at($leg) != EMPTY; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$leg >= 0 and $p->at($leg) != 0
MC/DC0%0/2
$leg >= 0 and $p->at($leg) != 0
$leg >= 0
$p->at($leg) != 0
Truth table33%1/3
A and B
A= $leg >= 0B= $p->at($leg) != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | elsif ($kind == CANNON) { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my $n = $p->cannon_screens($from, $to); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | return $R->throw('cannon_needs_one_screen') if $n >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | elsif ($kind == SOLDIER) { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | my ($fr, $tr) = ($E->rank_of($from), $E->rank_of($to)); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | ▶ | my $back = $colour == RED ? $tr < $fr : $tr > $fr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | ▶ | return $R->throw('soldier_no_retreat') if $back; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | return $R->throw('soldier_no_sideways') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fr == $tr and not $E->crossed_river($from, $colour)
MC/DC0%0/2
$fr == $tr and not $E->crossed_river($from, $colour)
$fr == $tr
not $E->crossed_river($from, $colour)
Truth table33%1/3
A and not(B)
A= $fr == $trB= not $E->crossed_river($from, $colour)
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | if $fr == $tr && !$E->crossed_river($from, $colour); | ||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | return $R->throw('not_legal', legal => $self->legal); | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 14 | ▶ | sub result { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | return { winner => undef, reason => undef, rule => 0, loop => undef } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | if $self->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 11 | return { %{ $self->_result } }; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub winner { $_[0]->result->{winner} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
winner: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 21 | ▶ | sub bot { require Game::Xiangqi::Bot; 'Game::Xiangqi::Bot' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 16 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 16 | my ($proto, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 16 | ▶ | if (ref $proto) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | ▶ | my $moves = ref $rest[0] eq 'ARRAY' ? $rest[0] : [ grep { defined } @rest ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | return $proto->_replayed($moves); | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 12 | ▶ | return undef if @rest % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 10 | my %o = @rest; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 10 | my $self = $proto->new(%o); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 10 | ▶ | return $self->_walk($o{moves} || []); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o{'moves'} || []
MC/DC0%0/1
$o{'moves'} || []
$o{'moves'}
Truth table50%1/2
A
A= $o{'moves'}
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | sub _replayed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replayed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | my ($self, $moves) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | my $fresh = (ref $self)->new( | |||||||||||||||||||||||||||||||||||||||||
| 220 | seed => $self->_held_seed, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | red => $self->red, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | position => $self->_start, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | return $fresh->_walk($moves); | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | ▶ | sub _walk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_walk: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 14 | my ($self, $moves) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 14 | for my $i (0 .. $#$moves) { | |||||||||||||||||||||||||||||||||||||||||
| 230 | 43 | my $why = $self->play($moves->[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 43 | ▶ | return wantarray ? ($self, $why, $i) : undef if $why; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 10 | ▶ | return wantarray ? ($self, 0, scalar @$moves) : $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | __END__ | ||||||||||||||||||||||||||||||||||||||||||