| 1 | package Game::Merrills; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 80 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 80 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 80 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 80 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 80 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 80 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 80 | ▶ | use Game::Merrills::Points; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 80 | ▶ | use Game::Merrills::Board; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 80 | ▶ | use Game::Merrills::Move; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 80 | ▶ | use Game::Merrills::Notation; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 80 | ▶ | use Game::Merrills::Rules; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 80 | ▶ | use Game::Merrills::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 80 | ▶ | use Game::Merrills::Result; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 80 | ▶ | use constant NO_MILL_PLIES => 100; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 80 | our $NO_MILL_LIMIT = NO_MILL_PLIES; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 80 | my %OTHER = (white => 'black', black => 'white'); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 80 | my $OPENING = '........................ w 9 9 0 0'; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | has [qw/position turn/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | isa => Str | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | has flying => ( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | default => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | has [qw/result draw_offered_by _legal _position/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | has [qw/history _undo/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 40248 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | has [qw/no_mill _base_ply/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 48 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | has repetition => ( | ||||||||||||||||||||||||||||||||||||||||||
| 54 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 20124 | ▶ | default => sub { {} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 80 | ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 20124 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 20124 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 20124 | ▶ | my $start = Game::Merrills::Notation::parse_position( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | defined $self->position ? $self->position : $OPENING | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 20122 | $self->position(Game::Merrills::Notation::format_position($start)); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 20122 | $self->_position([ @{ $start->{cells} }, @{ $start->{hand} }{qw/white black/} ]); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 20122 | $self->turn($start->{turn}); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 20122 | $self->no_mill($start->{no_mill}); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 20122 | $self->_base_ply($start->{ply}); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 20122 | ▶ | $self->flying($self->flying ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 20122 | ▶ | $self->repetition->{ $self->_key }++ if $self->_counting; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 20122 | $self->_check_end; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 20122 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 82899 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 82899 | ▶ | return $_[0]->result ? 'finished' : 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 126929 | ▶ | sub ply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 126929 | return $_[0]->_base_ply + scalar @{ $_[0]->history }; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 5135 | ▶ | sub board { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 5135 | return Game::Merrills::Rules::board($_[0]->_position); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 193346 | ▶ | sub in_hand { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_hand: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 193346 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 193346 | ▶ | return $self->_position->[ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | $self->_side($side) eq 'white' | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ? Game::Merrills::Rules::HAND_WHITE | ||||||||||||||||||||||||||||||||||||||||||
| 92 | : Game::Merrills::Rules::HAND_BLACK | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 188515 | ▶ | sub on_board { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 188515 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 188515 | my $value = $Game::Merrills::Board::VALUE{ $self->_side($side) }; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 188515 | return scalar grep { $_ == $value } @{ $self->_position }[ 0 .. 23 ]; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 186999 | ▶ | sub men { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
men: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 186999 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 186999 | return $self->on_board($side) + $self->in_hand($side); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 42687 | ▶ | sub phase { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
phase: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 42687 | return $_[0]->phase_of($_[0]->turn); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 42690 | ▶ | sub phase_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
phase_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 42690 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 42690 | return Game::Merrills::Rules::phase($self->_position, $self->_side($side), $self->flying); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 193913 | ▶ | sub legal_moves { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal_moves: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 193913 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 193913 | my $legal = $self->_legal; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 193913 | ▶ | return $legal if $legal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 94967 | $legal = []; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 94967 | ▶ | unless ($self->result) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 94967 | my $turn = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 123 | $legal = [ | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 1402447 | map { Game::Merrills::Move->from_raw($_, $turn) } | |||||||||||||||||||||||||||||||||||||||||
| 125 | 94967 | @{ Game::Merrills::Rules::generate($self->_position, $turn, $self->flying) } | |||||||||||||||||||||||||||||||||||||||||
| 126 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 94967 | $self->_legal($legal); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 94967 | return $legal; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | sub legal_moves_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal_moves_for: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | my ($self, $point) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | Game::Merrills::Points::_check($point); | |||||||||||||||||||||||||||||||||||||||||
| 135 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | grep { (defined $_->from ? $_->from : $_->to) == $point } @{ $self->legal_moves } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 89706 | ▶ | sub move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 89706 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 89706 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 89702 | ▶ | my $want = $self->_parse($move) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | or return $self->_error('not_a_move'); | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 89686 | for my $legal (@{ $self->legal_moves }) { | |||||||||||||||||||||||||||||||||||||||||
| 148 | 795533 | ▶ | next unless $legal->to == $want->{to}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 118962 | ▶ | next unless _same($legal->from, $want->{from}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 93330 | ▶ | next unless _same($legal->remove, $want->{remove}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 72774 | return $self->_play($legal); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 16912 | return $self->_diagnose($want); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 4304 | ▶ | sub undo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undo: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 4304 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 4304 | ▶ | my $record = pop @{ $self->_undo } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | or return $self->_error('nothing_to_undo'); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 4262 | my $move = pop @{ $self->history }; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 4262 | ▶ | if ($record->{counted}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3542 | my $key = $self->_key; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 3542 | ▶ | delete $self->repetition->{$key} unless --$self->repetition->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 4262 | ▶ | $self->repetition($record->{repetition}) if $record->{repetition}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 4262 | $self->turn($OTHER{ $self->turn }); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 4262 | Game::Merrills::Rules::unapply($self->_position, $self->turn, $record->{raw}); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 4262 | $self->no_mill($record->{no_mill}); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 4262 | $self->draw_offered_by($record->{draw_offered_by}); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 4262 | $self->result(undef); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 4262 | $self->_legal(undef); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 4262 | return $move; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 19 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 19 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 18 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 17 | return $self->_finish($OTHER{$side}, 'resign'); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | ▶ | sub timeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | return $self->_finish($OTHER{$side}, 'timeout'); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 12 | ▶ | sub offer_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer_draw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 12 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 12 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 12 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 11 | $self->draw_offered_by($side); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 11 | return $side; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | ▶ | sub accept_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_draw: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 10 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 10 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 10 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | my $offered = $self->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | return $self->_finish(undef, 'agreement'); | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 6 | ▶ | sub decline_draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decline_draw: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | $side = $self->_side($side); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | ▶ | return $self->_error('game_over') if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | my $offered = $self->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | $self->draw_offered_by(undef); | |||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | return $side; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 25650 | ▶ | sub to_position { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 25650 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 25650 | my $position = $self->_position; | |||||||||||||||||||||||||||||||||||||||||
| 221 | return Game::Merrills::Notation::format_position({ | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 25650 | cells => [ @{$position}[ 0 .. 23 ] ], | |||||||||||||||||||||||||||||||||||||||||
| 223 | turn => $self->turn, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | hand => { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | white => $position->[Game::Merrills::Rules::HAND_WHITE], | ||||||||||||||||||||||||||||||||||||||||||
| 226 | black => $position->[Game::Merrills::Rules::HAND_BLACK], | ||||||||||||||||||||||||||||||||||||||||||
| 227 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 228 | no_mill => $self->no_mill, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | ply => $self->ply, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | sub from_position { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | my ($class, $position, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | return $class->new(%option, position => $position); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 43 | ▶ | sub to_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_text: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 43 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | return Game::Merrills::Notation::format_record( | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 43 | ▶ | [ map { $_->notation } @{ $self->history } ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | $self->position eq $OPENING ? () : (position => $self->position) | ||||||||||||||||||||||||||||||||||||||||||
| 243 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 18 | ▶ | sub from_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_text: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 18 | my ($class, $text, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 18 | my $moves = Game::Merrills::Notation::parse_record($text); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 16 | my $position = Game::Merrills::Notation::record_position($text); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 16 | ▶ | my $self = $class->new(%option, defined $position ? (position => $position) : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 16 | my $number = 0; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 16 | for my $move (@{$moves}) { | |||||||||||||||||||||||||||||||||||||||||
| 253 | 399 | $number++; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 399 | my $played = $self->move($move); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 399 | ▶ | next unless ref $played eq 'Game::Merrills::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | die "illegal record: move $number, '" | |||||||||||||||||||||||||||||||||||||||||
| 257 | . Game::Merrills::Notation::format_move($move) . "': " . $played->message . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 17714 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 17714 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 17714 | my $clone = ref($self)->new(position => $self->position, flying => $self->flying); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 17714 | $clone->_position([ @{ $self->_position } ]); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 17714 | $clone->turn($self->turn); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 17714 | $clone->history([ @{ $self->history } ]); | |||||||||||||||||||||||||||||||||||||||||
| 268 | $clone->_undo([ | ||||||||||||||||||||||||||||||||||||||||||
| 269 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 536604 | ▶ | { %{$_}, $_->{repetition} ? (repetition => { %{ $_->{repetition} } }) : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 17714 | } @{ $self->_undo } | |||||||||||||||||||||||||||||||||||||||||
| 272 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 17714 | $clone->no_mill($self->no_mill); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 17714 | $clone->repetition({ %{ $self->repetition } }); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 17714 | $clone->draw_offered_by($self->draw_offered_by); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 17714 | $clone->result($self->result); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 17714 | $clone->_legal(undef); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 17714 | return $clone; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 212569 | ▶ | sub _same { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_same: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 212569 | my ($one, $two) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 212569 | ▶ | return defined $one ? (defined $two && $one == $two) : !defined $two; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $two and $one == $two
MC/DC100%2/2
defined $two and $one == $two
defined $two
$one == $two
Truth table100%3/3
A and B
A= defined $twoB= $one == $two
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 424601 | ▶ | sub _side { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_side: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 424601 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 424601 | ▶ | $side = $self->turn unless defined $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 424601 | ▶ | die "side must be white or black, got '$side'" unless $OTHER{$side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 424600 | return $side; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 42163 | ▶ | sub _key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 42163 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 42163 | return join '', @{ $self->_position }[ 0 .. 23 ], $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 92896 | ▶ | sub _counting { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_counting: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 92896 | my $position = $_[0]->_position; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 92896 | ▶ | return !$position->[Game::Merrills::Rules::HAND_WHITE] | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$position->[24] || $position->[25]
MC/DC100%2/2
$position->[24] || $position->[25]
$position->[24]
$position->[25]
Truth table100%3/3
A || B
A= $position->[24]B= $position->[25]
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | && !$position->[Game::Merrills::Rules::HAND_BLACK]; | ||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 16986 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 16986 | my ($self, $flag, %extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 16986 | return Game::Merrills::Error->throw( | |||||||||||||||||||||||||||||||||||||||||
| 307 | $flag, | ||||||||||||||||||||||||||||||||||||||||||
| 308 | legal => $self->legal_moves, | ||||||||||||||||||||||||||||||||||||||||||
| 309 | %extra | ||||||||||||||||||||||||||||||||||||||||||
| 310 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 89702 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 89702 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 89702 | ▶ | if (ref $move eq 'Game::Merrills::Move') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 71291 | $move = { from => $move->from, to => $move->to, remove => $move->remove }; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 89702 | ▶ | return Game::Merrills::Notation::parse_move($move) unless ref $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 89460 | ▶ | return undef unless ref $move eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 89459 | my %want; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 89459 | for my $part (qw/from to remove/) { | |||||||||||||||||||||||||||||||||||||||||
| 323 | 268373 | my $point = $move->{$part}; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 268373 | ▶ | next unless defined $point; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 153616 | ▶ | return undef if ref $point; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 153615 | ▶ | $point = Game::Merrills::Points::point($point) if $point =~ m/^[a-g][1-7]$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 153615 | ▶ | return undef unless defined $point && $point =~ m/^[0-9]+$/ && $point < 24; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $point and $point =~ /^[0-9]+$/ and $point < 24
defined $point and $point =~ /^[0-9]+$/
MC/DC66%2/3
defined $point and $point =~ /^[0-9]+$/ and $point < 24
defined $point
$point =~ /^[0-9]+$/
$point < 24
Truth table75%3/4
A and B and C
A= defined $pointB= $point =~ /^[0-9]+$/C= $point < 24
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 153612 | $want{$part} = $point + 0; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 89455 | ▶ | return undef unless defined $want{to}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 89454 | return \%want; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 16912 | ▶ | sub _diagnose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_diagnose: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 16912 | my ($self, $want) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 16912 | my ($from, $to, $remove) = @{$want}{qw/from to remove/}; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 16912 | my $position = $self->_position; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 16912 | my $side = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 16912 | my $value = $Game::Merrills::Board::VALUE{$side}; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 16912 | my $phase = $self->phase; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 16912 | ▶ | if (defined $from) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 11826 | ▶ | return $self->_error('men_in_hand') if $phase eq 'placing'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 8094 | ▶ | return $self->_error('not_your_man') unless $position->[$from] == $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 2021 | ▶ | return $self->_error('occupied') if $position->[$to]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 914 | ▶ | return $self->_error('not_adjacent') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$phase eq "moving" and not Game::Merrills::Points::is_adjacent($from, $to)
MC/DC100%2/2
$phase eq "moving" and not Game::Merrills::Points::is_adjacent($from, $to)
$phase eq "moving"
not Game::Merrills::Points::is_adjacent($from, $to)
Truth table100%3/3
A and not(B)
A= $phase eq "moving"B= not Game::Merrills::Points::is_adjacent($from, $to)
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | if $phase eq 'moving' && !Game::Merrills::Points::is_adjacent($from, $to); | ||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 5086 | ▶ | return $self->_error('no_men_in_hand') unless $phase eq 'placing'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 1128 | ▶ | return $self->_error('occupied') if $position->[$to]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 485 | my $closes = Game::Merrills::Rules::closes($position, $side, $from, $to); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 485 | ▶ | unless (defined $remove) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 58 | ▶ | return $self->_error('not_legal') unless $closes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | return $self->_error('must_remove', legal => [ | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 58 | ▶ | grep { $_->to == $to && _same($_->from, $from) } @{ $self->legal_moves } | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->to == $to && _same($_->from, $from)
MC/DC100%2/2
$_->to == $to && _same($_->from, $from)
$_->to == $to
_same($_->from, $from)
Truth table100%3/3
A && B
A= $_->to == $toB= _same($_->from, $from)
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 427 | ▶ | return $self->_error('nothing_to_remove') unless $closes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 18 | ▶ | return $self->_error('no_man_there') unless $position->[$remove] == -$value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | return $self->_error('man_in_mill') | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 6 | ▶ | unless grep { $_ == $remove } Game::Merrills::Rules::removable($position, $side); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return $self->_error('not_legal'); | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 72774 | ▶ | sub _play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_play: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 72774 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 72774 | my $raw = $move->to_raw; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 72774 | my $mover = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 72774 | my $position = $self->_position; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 72774 | my %record = ( | |||||||||||||||||||||||||||||||||||||||||
| 375 | raw => $raw, | ||||||||||||||||||||||||||||||||||||||||||
| 376 | no_mill => $self->no_mill, | ||||||||||||||||||||||||||||||||||||||||||
| 377 | draw_offered_by => $self->draw_offered_by, | ||||||||||||||||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 72774 | push @{ $self->history }, $move; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 72774 | Game::Merrills::Rules::apply($position, $mover, $raw); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 72774 | $self->_legal(undef); | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 72774 | my $offered = $self->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 72774 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 72774 | ▶ | if ($move->is_placement || $move->is_capture) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$move->is_placement or $move->is_capture
MC/DC100%2/2
$move->is_placement or $move->is_capture
$move->is_placement
$move->is_capture
Truth table100%3/3
A or B
A= $move->is_placementB= $move->is_capture
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 41797 | $record{repetition} = $self->repetition; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 41797 | $self->repetition({}); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 41797 | $self->no_mill(0); | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 30977 | $self->no_mill($self->no_mill + 1); | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 72774 | $self->turn($OTHER{$mover}); | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 72774 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 72774 | ▶ | if ($self->_counting) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 38462 | $count = ++$self->repetition->{ $self->_key }; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 38462 | $record{counted} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 72774 | push @{ $self->_undo }, \%record; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 72774 | $self->_check_end; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 72774 | ▶ | return $move if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 72472 | ▶ | if ($count >= 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 12 | $self->_finish(undef, 'repetition'); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | ▶ | elsif ($NO_MILL_LIMIT && $self->no_mill >= $NO_MILL_LIMIT) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$Game::Merrills::NO_MILL_LIMIT and $self->no_mill >= $Game::Merrills::NO_MILL_LIMIT
MC/DC100%2/2
$Game::Merrills::NO_MILL_LIMIT and $self->no_mill >= $Game::Merrills::NO_MILL_LIMIT
$Game::Merrills::NO_MILL_LIMIT
$self->no_mill >= $Game::Merrills::NO_MILL_LIMIT
Truth table100%3/3
A and B
A= $Game::Merrills::NO_MILL_LIMITB= $self->no_mill >= $Game::Merrills::NO_MILL_LIMIT
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 4 | $self->_finish(undef, 'no_mill'); | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 72472 | return $move; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 92896 | ▶ | sub _check_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_end: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 92896 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 92896 | ▶ | return if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 92896 | my $turn = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 92896 | ▶ | return $self->_finish($OTHER{$turn}, 'few') if $self->men($turn) < 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 92601 | ▶ | return $self->_finish($turn, 'few') if $self->men($OTHER{$turn}) < 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 92600 | ▶ | return if Game::Merrills::Rules::has_move($self->_position, $turn, $self->flying); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 10 | return $self->_finish($OTHER{$turn}, 'blocked'); | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 345 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 345 | my ($self, $winner, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 345 | $self->result(Game::Merrills::Result->new( | |||||||||||||||||||||||||||||||||||||||||
| 429 | winner => $winner, | ||||||||||||||||||||||||||||||||||||||||||
| 430 | reason => $reason | ||||||||||||||||||||||||||||||||||||||||||
| 431 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 345 | $self->_legal([]); | |||||||||||||||||||||||||||||||||||||||||
| 433 | 345 | return $self->result; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 80 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | __END__ | ||||||||||||||||||||||||||||||||||||||||||