| 1 | package Game::Checkers; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 27 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 27 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 27 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 27 | ▶ | use Game::Checkers::Squares; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 27 | ▶ | use Game::Checkers::Piece; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 27 | ▶ | use Game::Checkers::Move; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 27 | ▶ | use Game::Checkers::Notation; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 27 | ▶ | use Game::Checkers::Board; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 27 | ▶ | use Game::Checkers::Rules; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 27 | ▶ | use Game::Checkers::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 27 | ▶ | use Game::Checkers::Result; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 27 | ▶ | use constant NO_PROGRESS_PLIES => 80; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 27 | my $STEP = \@Game::Checkers::Squares::STEP; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 27 | my $JUMP_OVER = \@Game::Checkers::Squares::JUMP_OVER; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 27 | my $JUMP_TO = \@Game::Checkers::Squares::JUMP_TO; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 27 | my %FORWARD = ( | |||||||||||||||||||||||||||||||||||||||||
| 26 | black => { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | Game::Checkers::Squares::SE, 1, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | Game::Checkers::Squares::SW, 1 | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | white => { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | Game::Checkers::Squares::NE, 1, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | Game::Checkers::Squares::NW, 1 | ||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | has board => ( | ||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 27 | ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | has [qw/turn variant fen/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 27 | ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | has [qw/result draw_offered_by _legal/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 27 | ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | has [qw/history _undo/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | default => [] | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 27 | ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | has no_progress => ( | ||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 27 | ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | has repetition => ( | ||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | default => {} | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 27 | ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 188 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 188 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 188 | ▶ | $self->variant('english') unless defined $self->variant; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 188 | ▶ | die "variant must be english, got '" . $self->variant . "'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | unless $self->variant eq 'english'; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 188 | ▶ | if (!$self->board) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 173 | ▶ | if (my $fen = $self->fen) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 62 | my ($board, $turn) = Game::Checkers::Board->from_fen($fen); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 62 | $self->board($board); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 62 | $self->turn($turn); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 111 | $self->board(Game::Checkers::Board->new); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 188 | ▶ | $self->turn('black') unless defined $self->turn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | die "turn must be black or white, got '" . $self->turn . "'" | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 188 | ▶ | unless $FORWARD{$self->turn}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 188 | ▶ | $self->fen($self->board->to_fen($self->turn)) unless defined $self->fen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | $self->repetition->{$self->board->to_fen($self->turn)}++ | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 188 | ▶ | unless %{$self->repetition}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 188 | $self->_check_end; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 188 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1291 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1291 | ▶ | return $_[0]->result ? 'finished' : 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5242 | ▶ | sub ply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 5242 | return scalar @{$_[0]->history}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 1690 | ▶ | sub to_fen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_fen: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1690 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1690 | return $self->board->to_fen($self->turn); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 4344 | ▶ | sub legal_moves { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal_moves: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4344 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4344 | my $legal = $self->_legal; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 4344 | ▶ | return $legal if $legal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1647 | $legal = []; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 1647 | ▶ | unless ($self->result) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1647 | my $turn = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 114 | $legal = [ | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 9834 | map { Game::Checkers::Move->from_raw($_, $turn) } | |||||||||||||||||||||||||||||||||||||||||
| 116 | 1647 | @{Game::Checkers::Rules::generate($self->board->position, $turn)} | |||||||||||||||||||||||||||||||||||||||||
| 117 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1647 | $self->_legal($legal); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1647 | return $legal; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub legal_moves_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal_moves_for: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my ($self, $square) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return [grep { $_->from == $square } @{$self->legal_moves}]; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 61 | ▶ | sub must_capture { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
must_capture: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 61 | my $legal = $_[0]->legal_moves; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 61 | ▶ | return @{$legal} && $legal->[0]->is_jump ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$legal;} and $legal->[0]->is_jump
MC/DC50%1/2
@{$legal;} and $legal->[0]->is_jump
@{$legal;}
$legal->[0]->is_jump
Truth table66%2/3
A and B
A= @{$legal;}B= $legal->[0]->is_jump
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1603 | ▶ | sub move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1603 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1603 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1601 | ▶ | my $parsed = $self->_parse($move) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | or return $self->_error('not_a_move'); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1595 | my ($from, $to) = @{$parsed}{qw/from to/}; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1595 | my $value = $self->board->at($from); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1595 | ▶ | return $self->_error('not_your_piece') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$value and ($value > 0 ? "black" : "white") eq $self->turn
MC/DC100%2/2
$value and ($value > 0 ? "black" : "white") eq $self->turn
$value
($value > 0 ? "black" : "white") eq $self->turn
Truth table100%3/3
A and B
A= $valueB= ($value > 0 ? "black" : "white") eq $self->turn
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | unless $value && ($value > 0 ? 'black' : 'white') eq $self->turn; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1590 | ▶ | my @match = grep { $_->from == $from && $_->to == $to } @{$self->legal_moves}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->from == $from && $_->to == $to
MC/DC100%2/2
$_->from == $from && $_->to == $to
$_->from == $from
$_->to == $to
Truth table100%3/3
A && B
A= $_->from == $fromB= $_->to == $to
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1590 | ▶ | if (@{$parsed->{squares}} > 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 26 | my $path = join '.', @{$parsed->{squares}}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 26 | @match = grep { join('.', @{$_->path}) eq $path } @match; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 1590 | ▶ | return $self->_error('ambiguous', legal => \@match) if @match > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1588 | ▶ | return $self->_diagnose($parsed) unless @match; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1570 | return $self->_play($match[0]); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 39 | ▶ | sub undo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undo: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 39 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 39 | ▶ | my $record = pop @{$self->_undo} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | or return $self->_error('nothing_to_undo'); | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 38 | my $move = pop @{$self->history}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 38 | my $fen = $self->to_fen; | |||||||||||||||||||||||||||||||||||||||||
| 162 | delete $self->repetition->{$fen} | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 38 | ▶ | unless --$self->repetition->{$fen}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 38 | Game::Checkers::Rules::unapply($self->board->position, $record->{raw}); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 38 | ▶ | $self->turn($self->turn eq 'black' ? 'white' : 'black'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 38 | $self->no_progress($record->{no_progress}); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 38 | $self->draw_offered_by($record->{draw_offered_by}); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 38 | $self->result(undef); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 38 | $self->_legal(undef); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 38 | return $move; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | ▶ | return $self->_finish($side eq 'black' ? 'white' : 'black', 'resign'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | ▶ | sub offer_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer_draw: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | $self->draw_offered_by($side); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | return $side; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 5 | ▶ | sub accept_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_draw: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | my $offered = $self->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | return $self->_error('no_offer') unless $offered && $offered ne $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$offered and $offered ne $side
MC/DC100%2/2
$offered and $offered ne $side
$offered
$offered ne $side
Truth table100%3/3
A and B
A= $offeredB= $offered ne $side
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | return $self->_finish(undef, 'agreement'); | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | sub decline_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decline_draw: called CC=3 SCAR=13.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | my $offered = $self->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | return $self->_error('no_offer') unless $offered && $offered ne $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$offered and $offered ne $side
MC/DC0%0/2
$offered and $offered ne $side
$offered
$offered ne $side
Truth table33%1/3
A and B
A= $offeredB= $offered ne $side
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->draw_offered_by(undef); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | return $side; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 7 | ▶ | sub to_pdn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pdn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 7 | my ($self, %tags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 7 | my $opening = Game::Checkers::Board->new->to_fen('black'); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | ▶ | if ($self->fen ne $opening) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | $tags{FEN} = $self->fen; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | $tags{SetUp} = '1'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | return Game::Checkers::Notation::format_pdn({ | ||||||||||||||||||||||||||||||||||||||||||
| 215 | tags => \%tags, | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 7 | ▶ | moves => [map { $_->notation } @{$self->history}], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | result => $self->result ? $self->result->pdn : '*' | ||||||||||||||||||||||||||||||||||||||||||
| 218 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | sub from_pdn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_pdn: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | my $parsed = Game::Checkers::Notation::parse_pdn($text); | |||||||||||||||||||||||||||||||||||||||||
| 224 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | ▶ | $parsed->{tags}{FEN} ? (fen => $parsed->{tags}{FEN}) : () | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 5 | my $number = 0; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | for my $notation (@{$parsed->{moves}}) { | |||||||||||||||||||||||||||||||||||||||||
| 229 | 259 | $number++; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 259 | my $move = $self->move($notation); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 259 | ▶ | next unless ref $move eq 'Game::Checkers::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | die "illegal PDN: move $number, '$notation': " . $move->message . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 15 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 15 | my $clone = ref($self)->new( | |||||||||||||||||||||||||||||||||||||||||
| 240 | variant => $self->variant, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | fen => $self->fen, | ||||||||||||||||||||||||||||||||||||||||||
| 242 | board => $self->board->clone, | ||||||||||||||||||||||||||||||||||||||||||
| 243 | turn => $self->turn | ||||||||||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 15 | $clone->history([@{$self->history}]); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 15 | $clone->_undo([@{$self->_undo}]); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 15 | $clone->no_progress($self->no_progress); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 15 | $clone->repetition({%{$self->repetition}}); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 15 | $clone->draw_offered_by($self->draw_offered_by); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 15 | $clone->result($self->result); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 15 | $clone->_legal(undef); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 15 | return $clone; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 13 | ▶ | sub _side { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_side: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 13 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 13 | ▶ | $side = $self->turn unless defined $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 13 | ▶ | die "side must be black or white, got '$side'" unless $FORWARD{$side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 13 | return $side; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 39 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 39 | my ($self, $flag, %extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 39 | return Game::Checkers::Error->throw( | |||||||||||||||||||||||||||||||||||||||||
| 265 | $flag, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | legal => $self->legal_moves, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | %extra | ||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1601 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=12 SCAR=27.0
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 1601 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1601 | ▶ | if (ref $move eq 'Game::Checkers::Move') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | from => $move->from, | ||||||||||||||||||||||||||||||||||||||||||
| 276 | to => $move->to, | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 1239 | squares => [@{$move->path}], | |||||||||||||||||||||||||||||||||||||||||
| 278 | jump => $move->is_jump | ||||||||||||||||||||||||||||||||||||||||||
| 279 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 362 | ▶ | if (ref $move eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | my @squares = $move->{squares} ? @{$move->{squares}} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | : $move->{path} ? @{$move->{path}} | |||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | : grep { defined } $move->{from}, $move->{to}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | ▶ | return undef unless @squares > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | for my $square (@squares) { | |||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | ▶ | return undef unless $square =~ m/^[0-9]+$/ && $square >= 1 && $square <= 32; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$square =~ /^[0-9]+$/ and $square >= 1 and $square <= 32
$square =~ /^[0-9]+$/ and $square >= 1
MC/DC0%0/3
$square =~ /^[0-9]+$/ and $square >= 1 and $square <= 32
$square =~ /^[0-9]+$/
$square >= 1
$square <= 32
Truth table25%1/4
A and B and C
A= $square =~ /^[0-9]+$/B= $square >= 1C= $square <= 32
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | from => $squares[0], | ||||||||||||||||||||||||||||||||||||||||||
| 291 | to => $squares[-1], | ||||||||||||||||||||||||||||||||||||||||||
| 292 | squares => \@squares, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | jump => @squares > 2 ? 1 : $move->{jump} | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 360 | ▶ | return undef if ref $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 359 | return Game::Checkers::Notation::parse_move($move); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 18 | ▶ | sub _diagnose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_diagnose: called CC=14 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 18 | my ($self, $parsed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 18 | my ($from, $to) = @{$parsed}{qw/from to/}; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 18 | my $position = $self->board->position; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 18 | my $value = $position->[$from]; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 18 | ▶ | my $king = abs($value) == 2 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 18 | my $base = $from * 4; | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 18 | for my $dir (@Game::Checkers::Squares::DIRS) { | |||||||||||||||||||||||||||||||||||||||||
| 309 | 56 | ▶ | my $forward = $king || $FORWARD{$self->turn}{$dir}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$king || $FORWARD{$self->turn}{$dir}
MC/DC100%2/2
$king || $FORWARD{$self->turn}{$dir}
$king
$FORWARD{$self->turn}{$dir}
Truth table100%3/3
A || B
A= $kingB= $FORWARD{$self->turn}{$dir}
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 56 | ▶ | if ($STEP->[$base + $dir] && $STEP->[$base + $dir] == $to) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$STEP[$base + $dir] and $$STEP[$base + $dir] == $to
MC/DC50%1/2
$$STEP[$base + $dir] and $$STEP[$base + $dir] == $to
$$STEP[$base + $dir]
$$STEP[$base + $dir] == $to
Truth table66%2/3
A and B
A= $$STEP[$base + $dir]B= $$STEP[$base + $dir] == $to
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | ▶ | return $self->_error('occupied') if $position->[$to]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 5 | ▶ | return $self->_error('wrong_direction') unless $forward; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | ▶ | return $self->_error('must_capture') if $self->must_capture; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return $self->_error('not_legal'); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 48 | ▶ | if ($JUMP_TO->[$base + $dir] && $JUMP_TO->[$base + $dir] == $to) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$$JUMP_TO[$base + $dir] and $$JUMP_TO[$base + $dir] == $to
MC/DC100%2/2
$$JUMP_TO[$base + $dir] and $$JUMP_TO[$base + $dir] == $to
$$JUMP_TO[$base + $dir]
$$JUMP_TO[$base + $dir] == $to
Truth table100%3/3
A and B
A= $$JUMP_TO[$base + $dir]B= $$JUMP_TO[$base + $dir] == $to
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | ▶ | return $self->_error('occupied') if $position->[$to]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | ▶ | return $self->_error('wrong_direction') unless $forward; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 7 | return $self->_error('not_legal'); | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | return $self->_error('must_capture') if $self->must_capture; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 3 | return $self->_error('not_legal'); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 1570 | ▶ | sub _play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_play: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 1570 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 1570 | my $raw = $move->to_raw; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 1570 | my $mover = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 1570 | push @{$self->_undo}, { | |||||||||||||||||||||||||||||||||||||||||
| 332 | raw => $raw, | ||||||||||||||||||||||||||||||||||||||||||
| 333 | no_progress => $self->no_progress, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | draw_offered_by => $self->draw_offered_by | ||||||||||||||||||||||||||||||||||||||||||
| 335 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 1570 | push @{$self->history}, $move; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 1570 | Game::Checkers::Rules::apply($self->board->position, $raw); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 1570 | $self->_legal(undef); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | # an offer stands until the other side answers it with a move | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 1570 | my $offered = $self->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 1570 | ▶ | $self->draw_offered_by(undef) if $offered && $offered ne $mover; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$offered and $offered ne $mover
MC/DC100%2/2
$offered and $offered ne $mover
$offered
$offered ne $mover
Truth table100%3/3
A and B
A= $offeredB= $offered ne $mover
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 1570 | ▶ | $self->no_progress( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | Game::Checkers::Rules::progress($raw) ? 0 : $self->no_progress + 1 | ||||||||||||||||||||||||||||||||||||||||||
| 347 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 1570 | ▶ | $self->turn($mover eq 'black' ? 'white' : 'black'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 1570 | my $count = ++$self->repetition->{$self->to_fen}; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | # a player with no move has lost, which beats either drawing counter | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 1570 | $self->_check_end; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 1570 | ▶ | return $move if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 1556 | ▶ | if ($count >= 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | $self->_finish(undef, 'repetition'); | |||||||||||||||||||||||||||||||||||||||||
| 358 | } elsif ($self->no_progress >= NO_PROGRESS_PLIES) { | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | $self->_finish(undef, 'no_progress'); | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 1556 | return $move; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 1758 | ▶ | sub _check_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_end: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 1758 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 1758 | ▶ | return if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 1758 | ▶ | return if Game::Checkers::Rules::has_move($self->board->position, $self->turn); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 17 | ▶ | return $self->_finish($self->turn eq 'black' ? 'white' : 'black', 'no_moves'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 26 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 26 | my ($self, $winner, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 26 | $self->result(Game::Checkers::Result->new( | |||||||||||||||||||||||||||||||||||||||||
| 374 | winner => $winner, | ||||||||||||||||||||||||||||||||||||||||||
| 375 | reason => $reason | ||||||||||||||||||||||||||||||||||||||||||
| 376 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 26 | $self->_legal([]); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 26 | return $self->result; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 27 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | __END__ | ||||||||||||||||||||||||||||||||||||||||||