| 1 | package Game::RoyalUr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 81 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 81 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 81 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 81 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 81 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 81 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 81 | ▶ | use Game::RoyalUr::Engine qw(EMPTY SIDE_LIGHT SIDE_DARK ROUTE_SHORT ROUTE_LONG piece_of); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 81 | ▶ | use Game::RoyalUr::Rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 81 | ▶ | use Game::RoyalUr::Variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 81 | ▶ | use Game::RoyalUr::Dice (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 81 | ▶ | use Game::RoyalUr::Notation (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 81 | ▶ | use Game::RoyalUr::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 81 | ▶ | use Game::RoyalUr::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 81 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 81 | my $E = 'Game::RoyalUr::Engine'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 81 | my $X = 'Game::RoyalUr::Error'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 81 | my (%SIDE_OF, %ROUTE_OF, %OTHER); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 81 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 81 | %SIDE_OF = (light => SIDE_LIGHT, dark => SIDE_DARK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 81 | %ROUTE_OF = (short => ROUTE_SHORT, long => ROUTE_LONG); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 81 | %OTHER = (light => 'dark', dark => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 81 | has _seed => (is => 'ro', init_arg => 'seed', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 81 | has _rules_given => (is => 'ro', init_arg => 'rules', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 81 | has _first_given => (is => 'ro', init_arg => 'first', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 81 | has _position_given => (is => 'ro', init_arg => 'position', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 81 | has _script => (is => 'ro', init_arg => 'script', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 81 | has _variant => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 81 | has _game => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 81 | has _first => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 81 | has _opening => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 81 | has _rolls => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 81 | has _roll => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 81 | has _faces => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 81 | has _number => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 81 | has _log => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 81 | has _choices => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 81 | has _resigned => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 81 | has _error => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1559 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=16 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1559 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1559 | my ($seed, $script) = ($self->_seed, $self->_script); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1559 | ▶ | Carp::croak('Game::RoyalUr: a game wants a seed: some bytes that decide every throw of its dice') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
defined $seed and not ref $seed and length $seed or ref $script eq "ARRAY"
defined $seed and not ref $seed and length $seed
defined $seed and not ref $seed
MC/DC75%3/4
defined $seed and not ref $seed and length $seed or ref $script eq "ARRAY"
defined $seed
not ref $seed
length $seed
ref $script eq "ARRAY"
Truth table57%4/7
A and not(B) and C or D
A= defined $seedB= not ref $seedC= length $seedD= ref $script eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | unless (defined $seed && !ref $seed && length $seed) || ref $script eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1557 | my $variant = Game::RoyalUr::Variant->of($self->_rules_given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1555 | $self->_variant($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1555 | my $position = $self->_position_given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1555 | ▶ | if (defined $position) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 135 | my $code = Game::RoyalUr::Notation::validate_position($position); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 135 | ▶ | Carp::croak("Game::RoyalUr: the position was refused, code $code") if $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1554 | my $first = $self->_first_given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | Carp::croak("Game::RoyalUr: first is 'light' or 'dark'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1554 | ▶ | if defined $first && !exists $SIDE_OF{$first}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $first and not exists $SIDE_OF{$first}
MC/DC100%2/2
defined $first and not exists $SIDE_OF{$first}
defined $first
not exists $SIDE_OF{$first}
Truth table100%3/3
A and not(B)
A= defined $firstB= not exists $SIDE_OF{$first}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1553 | my @opening; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1553 | ▶ | if (!defined $first && !defined $position) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $first or defined $position
MC/DC100%2/2
defined $first or defined $position
defined $first
defined $position
Truth table100%3/3
A or B
A= defined $firstB= defined $position
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 791 | ▶ | Carp::croak('Game::RoyalUr: a game with no seed must be told who moves first') if $script; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 791 | my ($side, $used, $throws) = Game::RoyalUr::Dice::opening_for($seed, $variant->dice); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 791 | $first = $side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 791 | @opening = map { join '', @$_ } @$throws; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1553 | ▶ | my $game = Game::RoyalUr::Rules->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | rules => $variant->as_hash, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | (defined $position ? (position => $position) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | (defined $first ? (first => $first) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1553 | my $consistent = $game->board->consistent($variant->pieces); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1553 | ▶ | undef $game unless $consistent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1553 | ▶ | Carp::croak('Game::RoyalUr: the position does not hold ' . $variant->pieces . ' pieces a side') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | unless $consistent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1552 | $self->_game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1552 | $self->_first($game->side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1552 | $self->_opening(\@opening); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1552 | $self->_rolls(scalar @opening); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1552 | $self->_log([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1552 | $self->_choices([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1552 | $self->_settle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1552 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 210021 | ▶ | sub _settle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_settle: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 210021 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 210021 | my $game = $self->_game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 210021 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 210021 | $self->_roll(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 210021 | $self->_faces(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 210021 | $self->_number(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 210021 | ▶ | while (!$self->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 217938 | my $number = $self->_rolls; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 217938 | my ($roll, $faces); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 217938 | ▶ | if (my $script = $self->_script) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 133 | my $next = $script->[ $number - @{ $self->_opening } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 133 | ▶ | return unless $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 127 | ($roll, $faces) = ($next->{roll}, $next->{faces}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 217805 | my $throw = Game::RoyalUr::Dice::throw_for($self->_seed, $number, $variant->dice); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 217805 | $faces = join '', @$throw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 217805 | $roll = Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($throw), $variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 217932 | $self->_rolls($number + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 217932 | ▶ | if ($game->moves($roll)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 208845 | $self->_roll($roll); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 208845 | $self->_faces($faces); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 208845 | $self->_number($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 208845 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 9087 | push @{ $self->_log }, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ply => $game->ply, side => $game->side, throw => $number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | roll => $roll, faces => $faces, move => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 9087 | $game->forfeit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1170 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 47704 | ▶ | sub _refuse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refuse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 47704 | my ($self, $code, %detail) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 47704 | $self->_error($X->of($code, %detail)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 47704 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 79587 | ▶ | my $cell_named = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 79587 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 79587 | ▶ | return -1 unless Game::RoyalUr::Notation::square_ok($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 79586 | return $E->cell_of(ord(substr $name, 0, 1) - ord('a'), substr($name, 1, 1) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 81 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 41358 | ▶ | sub _why_not { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_why_not: called CC=15 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 41358 | my ($self, $from, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 41358 | my $game = $self->_game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 41358 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 41358 | my $side = $SIDE_OF{ $game->side }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 41358 | my $route = $ROUTE_OF{ $variant->route }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 41358 | my $board = $game->board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 41358 | my $roll = $self->_roll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 41358 | my $from_step = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 41358 | ▶ | if ($from eq 'hand') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1657 | ▶ | return 'no_piece' unless $board->hand($side) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 39701 | my $piece = $board->at($cell_named->($from)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 39701 | ▶ | return 'no_piece' if $piece == EMPTY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 17516 | ▶ | return 'not_your_piece' if $piece != piece_of($side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 8496 | $from_step = $E->route_step($route, $side, $cell_named->($from)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 8496 | ▶ | return 'no_piece' unless $from_step; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9921 | my $length = $E->route_len($route); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 9921 | my $lands = $from_step + $roll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9921 | ▶ | if ($to eq 'home') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 428 | ▶ | return 'overshoot' if $lands > $length + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 416 | ▶ | return 'wrong_distance' if $lands < $length + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return 'bad_move'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 9493 | my $cell = $cell_named->($to); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 9493 | ▶ | return 'wrong_distance' unless $lands <= $length && $E->route_cell($route, $side, $lands) == $cell; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lands <= $length and $E->route_cell($route, $side, $lands) == $cell
MC/DC100%2/2
$lands <= $length and $E->route_cell($route, $side, $lands) == $cell
$lands <= $length
$E->route_cell($route, $side, $lands) == $cell
Truth table100%3/3
A and B
A= $lands <= $lengthB= $E->route_cell($route, $side, $lands) == $cell
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 146 | my $piece = $board->at($cell); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 146 | ▶ | return 'own_piece' if $piece == piece_of($side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 2 | ▶ | return 'safe_rosette' if $piece != EMPTY && $variant->safe_rosettes && $E->is_rosette($cell); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$piece != 0 and $variant->safe_rosettes and $E->is_rosette($cell)
$piece != 0 and $variant->safe_rosettes
MC/DC0%0/3
$piece != 0 and $variant->safe_rosettes and $E->is_rosette($cell)
$piece != 0
$variant->safe_rosettes
$E->is_rosette($cell)
Truth table25%1/4
A and B and C
A= $piece != 0B= $variant->safe_rosettesC= $E->is_rosette($cell)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return 'bad_move'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 256173 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 256173 | my ($self, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 256173 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 256173 | ▶ | return $self->_refuse('game_over') if $self->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 256169 | ▶ | return $self->_refuse('no_roll') unless defined $self->_roll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 256167 | my ($from, $to); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 256167 | ▶ | if (Scalar::Util::blessed($what) && $what->isa('Game::RoyalUr::Move')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($what) and $what->isa("Game::RoyalUr::Move")
MC/DC50%1/2
builtin::blessed($what) and $what->isa("Game::RoyalUr::Move")
builtin::blessed($what)
$what->isa("Game::RoyalUr::Move")
Truth table66%2/3
A and B
A= builtin::blessed($what)B= $what->isa("Game::RoyalUr::Move")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 124447 | ($from, $to) = ($what->from, $what->to); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 131720 | my ($parsed, $why) = Game::RoyalUr::Notation::parse_move($what); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 131720 | ▶ | return $self->_refuse('bad_move', text => $what, why => $why) unless $parsed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 125380 | ($from, $to) = @{$parsed}{qw(from to)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 249827 | my $game = $self->_game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 249827 | my $roll = $self->_roll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 249827 | ▶ | my ($move) = grep { $_->from eq $from && $_->to eq $to } $game->moves($roll); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->from eq $from && $_->to eq $to
MC/DC100%2/2
$_->from eq $from && $_->to eq $to
$_->from eq $from
$_->to eq $to
Truth table100%3/3
A && B
A= $_->from eq $fromB= $_->to eq $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 249827 | ▶ | return $self->_refuse($self->_why_not($from, $to), from => $from, to => $to, roll => $roll) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 208469 | push @{ $self->_choices }, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 208469 | depth => $game->depth, log => scalar @{ $self->_log }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | rolls => $self->_rolls, roll => $roll, faces => $self->_faces, number => $self->_number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 208469 | push @{ $self->_log }, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ply => $game->ply, side => $game->side, throw => $self->_number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | roll => $roll, faces => $self->_faces, move => $from . '-' . $to, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | captures => $move->captures, rosette => $move->rosette, home => $move->home, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 208469 | $game->apply($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 208469 | $self->_settle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 208469 | return $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 75005 | ▶ | sub play_or_die { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_or_die: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 75005 | my ($self, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 75005 | my $move = $self->play($what); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 75005 | ▶ | return $move if $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | my $error = $self->_error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | Carp::croak('Game::RoyalUr: ' . $error->code . ': ' . $error->message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 642 | ▶ | sub undo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undo: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 642 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 642 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 642 | ▶ | if (defined $self->_resigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | $self->_resigned(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 640 | ▶ | my $choice = pop @{ $self->_choices } or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 639 | my $game = $self->_game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 639 | ▶ | $game->undo while $game->depth > $choice->{depth}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 639 | splice @{ $self->_log }, $choice->{log}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 639 | $self->_rolls($choice->{rolls}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 639 | $self->_roll($choice->{roll}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 639 | $self->_faces($choice->{faces}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 639 | $self->_number($choice->{number}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 639 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 20 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 20 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 20 | $self->_error(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 20 | ▶ | return 0 if $self->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 19 | ▶ | $side = $self->_game->side unless defined $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 19 | ▶ | Carp::croak("Game::RoyalUr: a side is 'light' or 'dark'") unless exists $SIDE_OF{$side}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 18 | $self->_resigned($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1368854 | ▶ | sub is_over { defined $_[0]->_resigned || $_[0]->_game->is_over ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_over: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
defined $_[0]->_resigned or $_[0]->_game->is_over
MC/DC100%2/2
defined $_[0]->_resigned or $_[0]->_game->is_over
defined $_[0]->_resigned
$_[0]->_game->is_over
Truth table100%3/3
A or B
A= defined $_[0]->_resignedB= $_[0]->_game->is_over
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 4309 | ▶ | sub result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 4309 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 4309 | ▶ | return undef unless $self->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2619 | my $game = $self->_game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 2619 | my $resigned = $self->_resigned; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | return Game::RoyalUr::Result->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2619 | ▶ | winner => (defined $resigned ? $OTHER{$resigned} : $game->winner), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | how => (defined $resigned ? 'resign' : $game->how), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | final => $game->position, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | home => { light => $game->home('light'), dark => $game->home('dark') }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | plies => $game->ply, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 41397 | ▶ | sub error { $_[0]->_error } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 241696 | ▶ | sub side { $_[0]->is_over ? undef : $_[0]->_game->side } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
side: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 390363 | ▶ | sub roll { $_[0]->is_over ? undef : $_[0]->_roll } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
roll: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 47470 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 47470 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 47470 | ▶ | my $faces = $self->is_over ? undef : $self->_faces; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 47470 | ▶ | return defined $faces ? [ split //, $faces ] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 166686 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 166686 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 166686 | my $roll = $self->roll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 166686 | ▶ | return wantarray ? () : 0 unless defined $roll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 166443 | return $self->_game->moves($roll); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 53404 | ▶ | sub variant { $_[0]->_variant } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
variant: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 7747 | ▶ | sub first { $_[0]->_first } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 6352 | ▶ | sub seed { $_[0]->_seed } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 7794 | ▶ | sub rolls { $_[0]->_rolls } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rolls: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 7021 | ▶ | sub opening { [ map { [ split //, $_ ] } @{ $_[0]->_opening } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opening: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 8621 | ▶ | sub ply { $_[0]->_game->ply } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 13938 | ▶ | sub position { $_[0]->_game->position } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 7554 | ▶ | sub key { $_[0]->_game->key } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 7893 | ▶ | sub hand { $_[0]->_game->hand($_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 7893 | ▶ | sub home { $_[0]->_game->home($_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
home: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 21897 | ▶ | sub at { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
at: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 21897 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 21897 | my $cell = $cell_named->($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 21897 | ▶ | Carp::croak("Game::RoyalUr: there is no square called '" . ($name // 'undef') . "'") if $cell < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$name // "undef"
MC/DC0%0/1
$name // "undef"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 21896 | my $piece = $self->_game->board->at($cell); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 21896 | ▶ | return $piece == EMPTY ? undef : $piece == piece_of(SIDE_LIGHT) ? 'light' : 'dark'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 6336 | ▶ | sub chances { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chances: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 6336 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 6336 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 6336 | return $E->chances($variant->dice, $variant->zero_rolls); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 8820 | ▶ | sub log { [ map { { %$_ } } @{ $_[0]->_log } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 6882 | ▶ | sub forfeits_since { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forfeits_since: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 6882 | my ($self, $ply) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6882 | ▶ | $ply = 0 unless defined $ply; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 6882 | ▶ | return map { { %$_ } } grep { !defined $_->{move} && $_->{ply} >= $ply } @{ $self->_log }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!defined($_->{'move'}) && $_->{'ply'} >= $ply
MC/DC100%2/2
!defined($_->{'move'}) && $_->{'ply'} >= $ply
!defined($_->{'move'})
$_->{'ply'} >= $ply
Truth table100%3/3
not(A) && B
A= !defined($_->{'move'})B= $_->{'ply'} >= $ply
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1825 | ▶ | sub to_record { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_record: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1825 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1825 | my $variant = $self->_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | my %record = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | rules => (defined $variant->name ? $variant->name : $variant->as_hash), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | first => $self->_first, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | (defined $self->_position_given ? (position => $self->_position_given) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | turns => [ map { { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | side => $_->{side}, roll => $_->{roll}, move => $_->{move}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 197537 | ▶ | (defined $_->{faces} ? (faces => $_->{faces}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1825 | ▶ | } } @{ $self->_log } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1825 | ▶ | if (defined $self->_seed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1773 | $record{seed} = unpack 'H*', $self->_seed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1773 | ▶ | $record{opening} = scalar @{ $self->_opening } if @{ $self->_opening }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1825 | ▶ | if (my $result = $self->result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 864 | ▶ | $record{result} = { winner => (defined $result->winner ? $result->winner : 'draw'), how => $result->how }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1825 | return Game::RoyalUr::Notation::format_record(\%record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 653 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=32 SCAR=36.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 653 | my ($class, $record, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 653 | ▶ | my $bad = sub { return (undef, $X->of('bad_record', @_)) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 653 | ▶ | if (!ref $record) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 639 | my ($parsed, $problem) = Game::RoyalUr::Notation::parse_record($record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 639 | ▶ | return $bad->(line => $problem->{line}, why => $problem->{error}) unless $parsed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 589 | $record = $parsed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 603 | ▶ | my @turns = @{ $record->{turns} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$record->{'turns'} || []
MC/DC0%0/1
$record->{'turns'} || []
$record->{'turns'}
Truth table50%1/2
A
A= $record->{'turns'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 603 | ▶ | my $opening = $record->{opening} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$record->{'opening'} || 0
MC/DC100%1/1
$record->{'opening'} || 0
$record->{'opening'}
Truth table100%2/2
A
A= $record->{'opening'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 603 | ▶ | my $rules = exists $option{rules} ? $option{rules} : $record->{rules}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 603 | my $game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 603 | ▶ | if (defined $record->{seed}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | $game = $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | seed => pack('H*', $record->{seed}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | rules => $rules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | (defined $record->{position} ? (position => $record->{position}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 599 | ▶ | ($opening ? () : (first => $record->{first})), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | return $bad->(ply => 0, why => 'opening') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 599 | ▶ | unless $game->first eq $record->{first} && @{ $game->opening } == $opening; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$game->first eq $record->{"first"} and @{$game->opening;} == $opening
MC/DC0%0/2
$game->first eq $record->{"first"} and @{$game->opening;} == $opening
$game->first eq $record->{"first"}
@{$game->opening;} == $opening
Truth table33%1/3
A and B
A= $game->first eq $record->{"first"}B= @{$game->opening;} == $opening
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | $game = $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 53 | ▶ | script => [ map { { roll => $_->{roll}, faces => $_->{faces} } } @turns ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | rules => $rules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | (defined $record->{position} ? (position => $record->{position}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | first => $record->{first}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 603 | for my $i (0 .. $#turns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 86999 | my $turn = $turns[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 86999 | my $made = $game->_log->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 86999 | ▶ | if ($made) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 3460 | ▶ | return $bad->(ply => $i, why => 'move') if defined $turn->{move} || defined $made->{move}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $turn->{"move"} or defined $made->{"move"}
MC/DC50%1/2
defined $turn->{"move"} or defined $made->{"move"}
defined $turn->{"move"}
defined $made->{"move"}
Truth table66%2/3
A or B
A= defined $turn->{"move"}B= defined $made->{"move"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 3459 | ▶ | return $bad->(ply => $i, why => 'side') unless $made->{side} eq $turn->{side}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 3459 | ▶ | return $bad->(ply => $i, why => 'roll') unless $made->{roll} == $turn->{roll}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 3459 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 83539 | ▶ | return $bad->(ply => $i, why => 'over') if $game->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 83539 | ▶ | return $bad->(ply => $i, why => 'forfeit') unless defined $turn->{move}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 83538 | ▶ | return $bad->(ply => $i, why => 'side') unless $game->side eq $turn->{side}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 83537 | ▶ | return $bad->(ply => $i, why => 'roll') unless defined $game->roll && $game->roll == $turn->{roll}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $game->roll and $game->roll == $turn->{"roll"}
MC/DC50%1/2
defined $game->roll and $game->roll == $turn->{"roll"}
defined $game->roll
$game->roll == $turn->{"roll"}
Truth table66%2/3
A and B
A= defined $game->rollB= $game->roll == $turn->{"roll"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 83535 | ▶ | unless ($game->play($turn->{move})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | my $error = $game->error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3 | return (undef, $X->of($error->code, %{ $error->detail }, ply => $i)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 595 | ▶ | if (my $result = $record->{result}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 447 | ▶ | if ($result->{how} eq 'resign') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 7 | ▶ | return $bad->(ply => scalar @turns, why => 'result') if $game->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 7 | $game->resign($OTHER{ $result->{winner} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 440 | my $ended = $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 440 | ▶ | my $winner = $ended && defined $ended->winner ? $ended->winner : 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ended and defined $ended->winner
MC/DC0%0/2
$ended and defined $ended->winner
$ended
defined $ended->winner
Truth table33%1/3
A and B
A= $endedB= defined $ended->winner
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | return $bad->(ply => scalar @turns, why => 'result') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 440 | ▶ | unless $ended && $ended->how eq $result->{how} && $winner eq $result->{winner}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$ended and $ended->how eq $result->{"how"} and $winner eq $result->{"winner"}
$ended and $ended->how eq $result->{"how"}
MC/DC0%0/3
$ended and $ended->how eq $result->{"how"} and $winner eq $result->{"winner"}
$ended
$ended->how eq $result->{"how"}
$winner eq $result->{"winner"}
Truth table25%1/4
A and B and C
A= $endedB= $ended->how eq $result->{"how"}C= $winner eq $result->{"winner"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 595 | return ($game, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 972 | ▶ | sub to_text { $_[0]->to_record } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 145 | ▶ | sub from_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_text: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 145 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 145 | ▶ | Carp::croak('Game::RoyalUr: from_text wants the text to_text wrote, and was given ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not defined $text or ref $text
MC/DC100%2/2
not defined $text or ref $text
not defined $text
ref $text
Truth table100%3/3
not(A) or B
A= not defined $textB= ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | . (defined $text ? 'a reference' : 'nothing')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | if !defined $text || ref $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 143 | my ($game, $error) = $class->replay($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 143 | ▶ | return $game if $game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 6 | my $detail = $error->detail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 6 | ▶ | my $where = $detail->{line} ? " at line $detail->{line}" : defined $detail->{line} ? '' : ' at turn ' . (($detail->{ply} // 0) + 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$detail->{"ply"} // 0
MC/DC0%0/1
$detail->{"ply"} // 0
$detail->{"ply"}
Truth table0%0/2
A
A= $detail->{"ply"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | Carp::croak('Game::RoyalUr: the text was refused' . $where . ': ' . $error->message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 6 | ▶ | . (defined $detail->{why} ? " ($detail->{why})" : '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 81 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||