| 1 | package Game::RoyalUr::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 51 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 51 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 51 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 51 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 51 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 51 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 51 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 51 | ▶ | use Game::RoyalUr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 51 | ▶ | use Game::RoyalUr::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 51 | ▶ | use Game::RoyalUr::Variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 51 | ▶ | use Game::RoyalUr::Notation (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 51 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 51 | my (%CONTROL, %SEQUENCE, %STYLE, %GLYPH, %OTHER, @FILES); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 51 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 51 | %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | "\n" => 'enter', "\r" => 'enter', "\t" => 'tab', ' ' => 'space', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | "\x7f" => 'backspace', "\b" => 'backspace', "\x03" => 'interrupt', "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 51 | %SEQUENCE = (A => 'up', B => 'down', C => 'right', D => 'left', Z => 'backtab'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 51 | %STYLE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | title => '1;38;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | grid => '38;5;241', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | label => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | light => '1;38;5;229', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | dark => '1;38;5;39', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | rosette => '1;38;5;205', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | cursor => '1;38;5;16;48;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | landing => '1;38;5;16;48;5;114', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | capture => '1;38;5;231;48;5;160', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | marked => '1;38;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | unmarked => '38;5;240', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | key => '1;38;5;214', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | good => '1;38;5;114', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | bad => '1;38;5;203', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | quiet => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | step => '38;5;109', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 51 | %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | light => "\x{25CF}", dark => "\x{25CB}", rosette => "\x{2726}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | marked => "\x{25B2}", unmarked => "\x{25B3}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | h => "\x{2500}", v => "\x{2502}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | tl => "\x{256D}", tr => "\x{256E}", bl => "\x{2570}", br => "\x{256F}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | td => "\x{252C}", tu => "\x{2534}", lt => "\x{251C}", rt => "\x{2524}", x => "\x{253C}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | light => 'O', dark => '@', rosette => '*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | marked => '^', unmarked => '.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | h => '-', v => '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | tl => '+', tr => '+', bl => '+', br => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | td => '+', tu => '+', lt => '+', rt => '+', x => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 51 | %OTHER = (light => 'dark', dark => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 51 | @FILES = ('a' .. 'h'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 51 | has game => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 51 | has [qw/in out/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 51 | has [qw/interactive colour unicode picking/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 51 | has mode => (is => 'rw', default => 'bot'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 51 | has side => (is => 'rw', default => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 51 | has level => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 51 | has rules => (is => 'rw', default => 'finkel'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 51 | has first => (is => 'rw', default => 'roll'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 51 | has seed => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 51 | has pace => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 51 | has route => (is => 'rw', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 51 | has record => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 51 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 51 | has sleeper => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 51 | has _raw => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 51 | has _pending => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 51 | has _events => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 51 | has _told => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 51 | has _cursor => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 51 | has _note => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 113 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=27 SCAR=33.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 113 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 113 | ▶ | $self->in(\*STDIN) unless $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 113 | ▶ | $self->out(\*STDOUT) unless $self->out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 113 | ▶ | $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 113 | ▶ | $self->colour($self->interactive && !$ENV{NO_COLOR} ? 1 : 0) unless defined $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->interactive and not $ENV{"NO_COLOR"}
MC/DC0%0/2
$self->interactive and not $ENV{"NO_COLOR"}
$self->interactive
not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 113 | ▶ | $self->unicode($self->interactive ? 1 : 0) unless defined $self->unicode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 113 | ▶ | $self->picking($self->interactive ? 1 : 0) unless defined $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 113 | ▶ | $self->picking(0) unless $self->_keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 113 | ▶ | $self->pace($self->interactive && !$self->keysource ? 1 : 0) unless defined $self->pace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->interactive and not $self->keysource
MC/DC0%0/2
$self->interactive and not $self->keysource
$self->interactive
not $self->keysource
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $self->keysource
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 113 | ▶ | Carp::croak("Game::RoyalUr::Terminal: mode is bot, hotseat or watch, not '" . $self->mode . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | unless $self->mode =~ /\A(?:bot|hotseat|watch)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 111 | ▶ | Carp::croak("Game::RoyalUr::Terminal: side is light or dark, not '" . $self->side . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | unless $self->side =~ /\A(?:light|dark)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 109 | ▶ | Carp::croak("Game::RoyalUr::Terminal: first is light, dark or roll, not '" . $self->first . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | unless $self->first =~ /\A(?:light|dark|roll)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 107 | ▶ | Carp::croak('Game::RoyalUr::Terminal: pace is a number of seconds, 0 or more') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | unless $self->pace =~ /\A\d+(?:\.\d+)?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 104 | my $variant = Game::RoyalUr::Variant->of($self->rules); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 102 | my @levels = Game::RoyalUr::Bot->levels($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 102 | ▶ | $self->level($levels[-1]) unless defined $self->level; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 102 | ▶ | Carp::croak('Game::RoyalUr::Terminal: level is a whole number from 1 to ' . $levels[-1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->level =~ /\A\d+\z/ and $self->level >= 1 and $self->level <= $levels[-1]
$self->level =~ /\A\d+\z/ and $self->level >= 1
MC/DC66%2/3
$self->level =~ /\A\d+\z/ and $self->level >= 1 and $self->level <= $levels[-1]
$self->level =~ /\A\d+\z/
$self->level >= 1
$self->level <= $levels[-1]
Truth table75%3/4
A and B and C
A= $self->level =~ /\A\d+\z/B= $self->level >= 1C= $self->level <= $levels[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | unless $self->level =~ /\A\d+\z/ && $self->level >= 1 && $self->level <= $levels[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 99 | ▶ | $self->seed(Digest::SHA::sha256(join '|', 'royalur', $$, time, rand)) unless defined $self->seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 99 | $self->_raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 99 | $self->_pending([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 99 | $self->_events([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 99 | $self->_told(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 99 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 99 | ▶ | if ($self->game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 49 | $self->_told(scalar @{ $self->game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 50 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 50 | $self->_announce_opening; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 99 | ▶ | binmode $self->out, ':encoding(UTF-8)' if $self->unicode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 99 | my $previous = select $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 99 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 99 | select $previous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 99 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 51 | ▶ | sub _fresh_game { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fresh_game: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 51 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 51 | ▶ | return Game::RoyalUr->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | seed => $self->seed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | rules => $self->rules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ($self->first eq 'roll' ? () : (first => $self->first)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 51 | ▶ | sub _announce_opening { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_announce_opening: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 51 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 51 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 51 | my @throws = @{ $game->opening }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 51 | ▶ | return unless @throws; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | while (@throws) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | my ($light, $dark) = splice @throws, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | my ($l, $d) = (scalar(grep { $_ } @$light), scalar(grep { $_ } @$dark)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | ▶ | $self->_event(undef, sprintf 'To see who starts, light threw %s %d and dark %s %d%s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $self->_dice($light), $l, $self->_dice($dark), $d, $l == $d ? ': a tie, again.' : '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | $self->_event($game->first, ucfirst($game->first) . ' moves first.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 17839 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 17839 | my ($self, $text, $style) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 17839 | ▶ | return $text unless $self->colour && defined $style && $STYLE{$style}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->colour and defined $style and $STYLE{$style}
$self->colour and defined $style
MC/DC33%1/3
$self->colour and defined $style and $STYLE{$style}
$self->colour
defined $style
$STYLE{$style}
Truth table50%2/4
A and B and C
A= $self->colourB= defined $styleC= $STYLE{$style}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 234 | return "\e[$STYLE{$style}m$text\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 21655 | ▶ | sub _glyph { $GLYPH{ $_[0]->unicode ? 'wide' : 'ascii' }{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glyph: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 359 | ▶ | sub _dice { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dice: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 359 | my ($self, $faces) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 359 | ▶ | return join ' ', map { $self->_paint($self->_glyph($_ ? 'marked' : 'unmarked'), $_ ? 'marked' : 'unmarked') } @$faces; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 743 | ▶ | sub _event { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 743 | my ($self, $side, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 743 | push @{ $self->_events }, { side => $side, text => $text }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 743 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | ▶ | sub events { [ map { $_->{text} } @{ $_[0]->_events } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1372 | ▶ | sub _person { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_person: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1372 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1372 | ▶ | return 0 if $self->mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 386 | ▶ | return 1 if $self->mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 310 | ▶ | return $side eq $self->side ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1076 | ▶ | sub _who { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_who: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1076 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1076 | ▶ | return ucfirst $side if $self->mode ne 'bot'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 403 | ▶ | return $side eq $self->side ? 'You' : ucfirst $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 661 | ▶ | my $said = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 661 | my ($entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 661 | ▶ | return Game::RoyalUr::Notation::format_forfeit($entry->{roll}) unless defined $entry->{move}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 657 | my ($from, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 657 | return Game::RoyalUr::Notation::format_display({ from => $from, to => $to, %$entry }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 703 | ▶ | sub _tell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tell: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 703 | my ($self, $pause) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 703 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 703 | my $log = $game->log; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 703 | my $told = $self->_told; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 703 | ▶ | while ($told < @$log) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 729 | my $entry = $log->[ $told++ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 729 | my $who = $self->_who($entry->{side}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 729 | my $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 729 | ▶ | if (!defined $entry->{move}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 75 | ▶ | $text = $entry->{roll} == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | ? "$who rolled nothing and lost the turn." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | : "$who rolled $entry->{roll} and could not move: the turn is lost."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 654 | $text = "$who played " . $said->($entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 654 | ▶ | $text .= ', capturing' if $entry->{captures}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | $text .= $entry->{home} ? ', home.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 654 | ▶ | : $entry->{rosette} ? ', onto a rosette: another roll.' : '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 729 | $self->_event($entry->{side}, $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 729 | $self->_told($told); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 729 | ▶ | my $slow = !defined $entry->{move} || !$self->_person($entry->{side}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $entry->{'move'} && $self->_person($entry->{'side'})
MC/DC100%2/2
defined $entry->{'move'} && $self->_person($entry->{'side'})
defined $entry->{'move'}
$self->_person($entry->{'side'})
Truth table100%3/3
A && B
A= defined $entry->{'move'}B= $self->_person($entry->{'side'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 729 | ▶ | if ($pause && $slow && $self->_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$pause and $slow and $self->_raw
$pause and $slow
MC/DC66%2/3
$pause and $slow and $self->_raw
$pause
$slow
$self->_raw
Truth table75%3/4
A and B and C
A= $pauseB= $slowC= $self->_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 87 | $self->show('wait'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 87 | $self->_wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 703 | $self->_told($told); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 703 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 87 | ▶ | sub _wait { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 87 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 87 | my $pace = $self->pace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 87 | ▶ | return unless $pace > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 85 | ▶ | return $self->sleeper->($pace) if $self->sleeper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | select undef, undef, undef, $pace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 112299 | ▶ | my $coordinates = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 112299 | my ($place, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 112299 | ▶ | return (4.5, $side eq 'light' ? 0 : 2) if $place eq 'hand'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 93372 | return (ord(substr $place, 0, 1) - ord('a'), substr($place, 1, 1) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 36706 | ▶ | sub candidates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
candidates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 36706 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 36706 | return $self->game->legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 36311 | ▶ | sub steer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
steer: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 36311 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 36311 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 36311 | ▶ | return $self->_cursor unless @moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 36311 | my $at = $self->_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 36311 | ▶ | $at = $#moves if $at > $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 36311 | ▶ | if ($key eq 'tab') { $at = ($at + 1) % @moves } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 36311 | ▶ | if ($key eq 'backtab') { $at = ($at - 1) % @moves } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 36311 | ▶ | if ($key =~ /\A[1-7]\z/ && $key <= @moves) { $at = $key - 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key =~ /\A[1-7]\z/ and $key <= @moves
MC/DC100%2/2
$key =~ /\A[1-7]\z/ and $key <= @moves
$key =~ /\A[1-7]\z/
$key <= @moves
Truth table100%3/3
A and B
A= $key =~ /\A[1-7]\z/B= $key <= @moves
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 36311 | ▶ | if ($key =~ /\A(?:left|right|up|down)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 34159 | my $side = $self->game->side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 34159 | my @xy = map { [ $coordinates->($_->from, $side) ] } @moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | my @order = $key eq 'left' || $key eq 'right' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 61553 | ▶ | ? sort { $xy[$a][0] <=> $xy[$b][0] || $xy[$a][1] <=> $xy[$b][1] } 0 .. $#moves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$xy[$a][0] <=> $xy[$b][0] || $xy[$a][1] <=> $xy[$b][1]
MC/DC0%0/2
$xy[$a][0] <=> $xy[$b][0] || $xy[$a][1] <=> $xy[$b][1]
$xy[$a][0] <=> $xy[$b][0]
$xy[$a][1] <=> $xy[$b][1]
Truth table66%2/3
A || B
A= $xy[$a][0] <=> $xy[$b][0]B= $xy[$a][1] <=> $xy[$b][1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 34159 | ▶ | : sort { $xy[$b][1] <=> $xy[$a][1] || $xy[$a][0] <=> $xy[$b][0] } 0 .. $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$key eq "left" or $key eq "right"
$xy[$b][1] <=> $xy[$a][1] || $xy[$a][0] <=> $xy[$b][0]
MC/DC100%2/2
$key eq "left" or $key eq "right"
$key eq "left"
$key eq "right"
MC/DC0%0/2
$xy[$b][1] <=> $xy[$a][1] || $xy[$a][0] <=> $xy[$b][0]
$xy[$b][1] <=> $xy[$a][1]
$xy[$a][0] <=> $xy[$b][0]
Truth table100%3/3
A or B
A= $key eq "left"B= $key eq "right"
Truth table66%2/3
A || B
A= $xy[$b][1] <=> $xy[$a][1]B= $xy[$a][0] <=> $xy[$b][0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 34159 | my ($where) = grep { $order[$_] == $at } 0 .. $#order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 34159 | ▶ | $where += ($key eq 'right' || $key eq 'down') ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "right" or $key eq "down"
MC/DC100%2/2
$key eq "right" or $key eq "down"
$key eq "right"
$key eq "down"
Truth table100%3/3
A or B
A= $key eq "right"B= $key eq "down"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 34159 | ▶ | $at = $order[$where] if $where >= 0 && $where <= $#order; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$where >= 0 and $where <= $#order
MC/DC100%2/2
$where >= 0 and $where <= $#order
$where >= 0
$where <= $#order
Truth table100%3/3
A and B
A= $where >= 0B= $where <= $#order
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 36311 | $self->_cursor($at); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 36311 | return $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 391 | ▶ | my $cells_after = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 391 | my ($game, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 391 | my (%cell, %hand, %home, %mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 391 | for my $file (@FILES) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 3128 | for my $row (1 .. 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 9384 | my $name = "$file$row"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 9384 | ▶ | next unless Game::RoyalUr::Notation::square_ok($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 7820 | $cell{$name} = $game->at($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 391 | for my $side (qw(light dark)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 782 | $hand{$side} = $game->hand($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 782 | $home{$side} = $game->home($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 391 | ▶ | return (\%cell, \%hand, \%home, \%mark) unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 125 | my $side = $move->side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 125 | ▶ | if ($move->from eq 'hand') { $hand{$side}--; $mark{"hand $side"} = 'cursor' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 76 | else { $cell{ $move->from } = undef; $mark{ $move->from } = 'cursor' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 125 | ▶ | if ($move->captures) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 13 | $hand{ $OTHER{$side} }++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 13 | $mark{"hand $OTHER{$side}"} = 'capture'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 125 | ▶ | if ($move->home) { $home{$side}++; $mark{"home $side"} = 'landing' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 123 | else { $cell{ $move->to } = $side; $mark{ $move->to } = 'landing' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 125 | return (\%cell, \%hand, \%home, \%mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 51 | my %BRACKET; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 51 | ▶ | BEGIN { %BRACKET = (cursor => [ '[', ']' ], landing => [ '(', ')' ], capture => [ '<', '>' ], last => [ '_', '_' ]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 7884 | ▶ | sub _framed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_framed: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 7884 | my ($self, $what, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 7884 | ▶ | my ($open, $close) = $mark ? @{ $BRACKET{$mark} } : (' ', ' '); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 7884 | ▶ | my $inside = defined $what ? $self->_glyph($what) : ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 7884 | ▶ | return $self->_paint($open . $inside . $close, $mark) if $mark && $mark ne 'last'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mark and $mark ne "last"
MC/DC100%2/2
$mark and $mark ne "last"
$mark
$mark ne "last"
Truth table100%3/3
A and B
A= $markB= $mark ne "last"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 7621 | ▶ | return $open . (defined $what ? $self->_paint($inside, $what) : $inside) . $close; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1173 | ▶ | sub _row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_row: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1173 | my ($self, $row, $cell, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1173 | my $v = $self->_paint($self->_glyph('v'), 'grid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1173 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1173 | for my $file (@FILES) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 9384 | my $name = "$file$row"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 9384 | ▶ | if (!Game::RoyalUr::Notation::square_ok($name)) { push @parts, undef; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 7820 | ▶ | my $rosette = $name =~ /\A(?:a1|g1|a3|g3|d2)\z/ ? $self->_paint($self->_glyph('rosette'), 'rosette') : ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 7820 | push @parts, $rosette . $self->_framed($cell->{$name}, $mark->{$name}) . ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1173 | my $line = $self->_paint($row, 'label') . ' ' . $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1173 | ▶ | if (defined $parts[4]) { $line .= join($v, @parts) . $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 782 | else { $line .= join($v, @parts[0 .. 3]) . $v . (' ' x 11) . $v . join($v, @parts[6, 7]) . $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1173 | return ' ' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1564 | ▶ | sub _border { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_border: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1564 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1564 | ▶ | my $g = sub { $self->_glyph($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1564 | my $bar = $g->('h') x 5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1564 | ▶ | my $block = sub { my ($left, $mid, $right, $n) = @_; $g->($left) . join($g->($mid), ($bar) x $n) . $g->($right) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1564 | ▶ | my $line = $kind eq 'top' ? $block->('tl', 'td', 'tr', 4) . (' ' x 11) . $block->('tl', 'td', 'tr', 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | : $kind eq 'bottom' ? $block->('bl', 'tu', 'br', 4) . (' ' x 11) . $block->('bl', 'tu', 'br', 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | : $g->('lt') . join($g->('x'), ($bar) x 4) . $g->('x') . $bar . $g->($kind eq 'upper' ? 'td' : 'tu') . $bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | . $g->('x') . join($g->('x'), ($bar) x 2) . $g->('rt'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1564 | return ' ' . $self->_paint($line, 'grid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 782 | ▶ | sub _tray { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tray: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 782 | my ($self, $side, $hand, $home, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1564 | ▶ | my $pieces = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1564 | my ($count, $which) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1564 | my @shown = map { $self->_paint($self->_glyph($side), $side) } 1 .. $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1564 | my $m = $mark->{"$which $side"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1564 | ▶ | if ($m && $m eq 'cursor') { push @shown, $self->_framed(undef, 'cursor') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$m and $m eq "cursor"
MC/DC100%2/2
$m and $m eq "cursor"
$m
$m eq "cursor"
Truth table100%3/3
A and B
A= $mB= $m eq "cursor"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 15 | ▶ | elsif ($m && @shown) { $shown[-1] = $self->_framed($side, $m) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$m and @shown
MC/DC50%1/2
$m and @shown
$m
@shown
Truth table66%2/3
A and B
A= $mB= @shown
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1564 | ▶ | return @shown ? join(' ', @shown) : $self->_paint('none', 'quiet'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 782 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | return sprintf ' %s hand %s home %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 782 | $self->_paint(sprintf('%-5s', $side), $side), $pieces->($hand->{$side}, 'hand'), $pieces->($home->{$side}, 'home'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 391 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 391 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 391 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 391 | my ($cell, $hand, $home, $mark) = $cells_after->($game, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 391 | ▶ | if (!$move) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 266 | my %latest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 266 | for my $entry (@{ $game->log }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 12088 | ▶ | $latest{ $entry->{side} } = $entry if defined $entry->{move}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 266 | for my $entry (values %latest) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 368 | my (undef, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 368 | ▶ | $mark->{$to} = 'last' if $to ne 'home' && defined $cell->{$to} && $cell->{$to} eq $entry->{side}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$to ne "home" and defined $cell->{$to} and $cell->{$to} eq $entry->{"side"}
$to ne "home" and defined $cell->{$to}
MC/DC66%2/3
$to ne "home" and defined $cell->{$to} and $cell->{$to} eq $entry->{"side"}
$to ne "home"
defined $cell->{$to}
$cell->{$to} eq $entry->{"side"}
Truth table75%3/4
A and B and C
A= $to ne "home"B= defined $cell->{$to}C= $cell->{$to} eq $entry->{"side"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 391 | my @lines = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | $self->_tray('dark', $hand, $home, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ' ' . $self->_paint(join(' ', @FILES), 'label'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | $self->_border('top'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | $self->_row(3, $cell, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | $self->_border('upper'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | $self->_row(2, $cell, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | $self->_border('lower'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $self->_row(1, $cell, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $self->_border('bottom'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | $self->_tray('light', $hand, $home, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 391 | ▶ | push @lines, '', @{ $self->_route_lines } if $self->route; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 391 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | ▶ | sub _route_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_route_lines: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 3 | ▶ | my $side = $game->side || $game->first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$game->side || $game->first
MC/DC0%0/2
$game->side || $game->first
$game->side
$game->first
Truth table33%1/3
A || B
A= $game->sideB= $game->first
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | ▶ | my $route = $variant->route eq 'long' ? Game::RoyalUr::Engine::ROUTE_LONG() : Game::RoyalUr::Engine::ROUTE_SHORT(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | ▶ | my $index = $side eq 'light' ? Game::RoyalUr::Engine::SIDE_LIGHT() : Game::RoyalUr::Engine::SIDE_DARK(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | my @lines = (' ' . $self->_paint('The ' . $variant->route . " route, as $side travels it:", 'quiet')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | for my $row (reverse 0 .. 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 9 | my $line = ' ' . $self->_paint($row + 1, 'label') . ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 9 | for my $file (0 .. 7) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 72 | my $cell = Game::RoyalUr::Engine->cell_of($file, $row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 72 | ▶ | my $step = $cell < 0 ? 0 : Game::RoyalUr::Engine->route_step($route, $index, $cell); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 72 | ▶ | $line .= $cell < 0 ? ' ' : $step ? $self->_paint(sprintf(' %2d ', $step), 'step') : $self->_paint(' . ', 'quiet'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 9 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 3 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 356 | ▶ | sub _roll_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_roll_line: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 356 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 356 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 356 | ▶ | return () if $game->is_over || !defined $game->roll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$game->is_over or not defined $game->roll
MC/DC50%1/2
$game->is_over or not defined $game->roll
$game->is_over
not defined $game->roll
Truth table66%2/3
A or not(B)
A= $game->is_overB= not defined $game->roll
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 347 | my $throw = $game->throw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 347 | my $roll = $game->roll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 347 | my $marked = grep { $_ } @$throw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 347 | my $text = sprintf ' %s rolled %s %s', $self->_who($game->side), $self->_paint($roll, 'key'), $self->_dice($throw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 347 | ▶ | $text .= $self->_paint(' (nothing marked is worth four)', 'quiet') if !$marked && $roll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $marked and $roll
MC/DC50%1/2
not $marked and $roll
not $marked
$roll
Truth table66%2/3
not(A) and B
A= not $markedB= $roll
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 347 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 356 | ▶ | sub _result_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_line: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 356 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 356 | ▶ | my $result = $self->game->result or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 9 | my $home = $result->home; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 9 | ▶ | return ' ' . $self->_paint('The game ran its full length with no end. It is drawn.', 'bad') if $result->is_draw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 9 | my $winner = $result->winner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 9 | ▶ | return ' ' . $self->_paint(sprintf('%s won: %s resigned.', ucfirst $winner, $result->loser), 'good') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | if $result->how eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | return ' ' . $self->_paint(sprintf('%s won, all %d home to %d, in %d plies.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 9 | ucfirst $winner, $home->{$winner}, $home->{ $result->loser }, $result->plies), 'good'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 356 | ▶ | sub _event_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event_lines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 356 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 356 | my @recent = @{ $self->_events }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 356 | ▶ | @recent = @recent[ -4 .. -1 ] if @recent > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 356 | ▶ | return map { ' ' . $self->_paint($_->{text}, $_->{side} || 'quiet') } @recent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->{'side'} || 'quiet'
MC/DC100%1/1
$_->{'side'} || 'quiet'
$_->{'side'}
Truth table100%2/2
A
A= $_->{'side'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 188 | ▶ | sub _readout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_readout: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 188 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 188 | my $text = Game::RoyalUr::Notation::format_display($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 188 | my @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 188 | ▶ | push @does, 'enters the board' if $move->from eq 'hand'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 188 | ▶ | push @does, 'captures' if $move->captures; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 188 | ▶ | push @does, 'lands on a rosette: roll again' if $move->rosette; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 188 | ▶ | push @does, 'comes home' if $move->home; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 188 | ▶ | return ' ' . $self->_paint($text, 'key') . (@does ? ' ' . join(', ', @does) : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 262 | ▶ | sub _legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legend: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 262 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 262 | ▶ | my $k = sub { $self->_paint($_[0], 'key') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 262 | ▶ | return ' ' . join(' ', $k->('n') . ' new game', $k->('u') . ' take back', $k->('q') . ' leave') if $mode eq 'ended'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 261 | ▶ | return ' ' . $self->_paint('...', 'quiet') if $mode eq 'wait'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 103 | return ' ' . join(' ', $k->('arrows') . ' choose a piece', $k->('enter') . ' move it', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | $k->('u') . ' take back', $k->('r') . ' route', $k->('?') . ' help', $k->('q') . ' leave'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 357 | ▶ | sub screen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
screen: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 357 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 357 | ▶ | $mode = 'plain' unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 357 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 357 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 357 | ▶ | my @lines = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | ' ' . $self->_paint('The Royal Game of Ur', 'title') . ' ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | . $self->_paint(join(', ', (defined $variant->name ? $variant->name : $variant->describe), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | ($self->mode eq 'bot' ? 'you are ' . $self->side . ', against level ' . $self->level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | : $self->mode eq 'hotseat' ? 'two players' : 'level ' . $self->level . ' against itself')), 'quiet'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 357 | ▶ | if ($mode eq 'help') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | push @lines, map { " $_" } @{ $self->help_lines }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 356 | ▶ | my @moves = $mode eq 'pick' ? $self->candidates : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 356 | my $at = $self->_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 356 | ▶ | $at = $#moves if $at > $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 356 | ▶ | my $move = @moves ? $moves[$at] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 356 | push @lines, @{ $self->board_lines($move) }, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 356 | push @lines, $self->_roll_line, $self->_result_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 356 | ▶ | push @lines, $self->_readout($move) if $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 356 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 356 | push @lines, $self->_event_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 356 | ▶ | push @lines, ' ' . $self->_paint($self->_note, 'bad') if defined $self->_note; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 356 | ▶ | push @lines, '', $self->_legend($mode) if $mode eq 'pick' || $mode eq 'ended' || $mode eq 'wait'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$mode eq "pick" or $mode eq "ended" or $mode eq "wait"
$mode eq "pick" or $mode eq "ended"
MC/DC100%3/3
$mode eq "pick" or $mode eq "ended" or $mode eq "wait"
$mode eq "pick"
$mode eq "ended"
$mode eq "wait"
Truth table100%4/4
A or B or C
A= $mode eq "pick"B= $mode eq "ended"C= $mode eq "wait"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 356 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 261 | ▶ | sub show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 261 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 261 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 261 | my $lines = $self->screen($mode); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 261 | ▶ | if ($self->interactive) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 261 | print {$out} "\e[H", join('', map { "$_\e[K\n" } @$lines), "\e[J"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | print {$out} "$_\n" for @$lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 261 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 2 | ▶ | sub help_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | 'A move is a piece. The roll says how far it goes, so choosing the piece is', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 'the whole move.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ' arrows, tab walk the pieces that can move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | ' 1 to 7 go straight to one of them', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ' enter, space move it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | ' u take back your last move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | ' r show or hide the route', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | ' n a new game', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | ' q leave (asked twice)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 'The board shows what the move would leave: [ ] where the piece was, ( ) where', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 'it lands, and < > round a piece it sends back to its owner\'s hand.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 'Typing instead: a number from the list, or a move such as hand-b1 or a2-d2;', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 'and undo, new, route, moves, record FILE, level N, help, quit.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 113 | ▶ | sub _keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys_available: called CC=5 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 113 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 113 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 74 | ▶ | return 0 unless defined $self->in && -t $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->in and -t $self->in
MC/DC0%0/2
defined $self->in and -t $self->in
defined $self->in
-t $self->in
Truth table33%1/3
A and B
A= defined $self->inB= -t $self->in
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 3 | ▶ | sub _enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_raw: called CC=5 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 3 | ▶ | return 1 if $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 3 | ▶ | if ($self->keysource) { $self->_raw(1); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | return 0 unless $self->_keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | return 0 unless eval { Term::ReadKey::ReadMode(3, $self->in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $self->_raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | print {$out} "\e[?25l\e[2J"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 49 | ▶ | sub _leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_leave_raw: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 49 | ▶ | return unless $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | ▶ | unless ($self->keysource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | eval { Term::ReadKey::ReadMode(0, $self->in) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | print {$out} "\e[?25h"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 3 | $self->_raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 111 | ▶ | sub _read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_char: called CC=6 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 111 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 111 | my $pending = $self->_pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 111 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 111 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | return $char if defined $char || $wait; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $char or $wait
MC/DC0%0/2
defined $char or $wait
defined $char
$wait
Truth table0%0/3
A or B
A= defined $charB= $wait
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | return Term::ReadKey::ReadKey(-1, $self->in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 103 | ▶ | sub _read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_key: called CC=11 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 103 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 103 | my $char = $self->_read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 103 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 102 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 21 | ▶ | return $char unless $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 4 | my $opener = $self->_read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 4 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 4 | ▶ | unless ($opener eq '[' || $opener eq 'O') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opener eq "[" or $opener eq "O"
MC/DC0%0/2
$opener eq "[" or $opener eq "O"
$opener eq "["
$opener eq "O"
Truth table33%1/3
A or B
A= $opener eq "["B= $opener eq "O"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | unshift @{ $self->_pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 4 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 4 | my $next = $self->_read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 4 | ▶ | last unless defined $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 4 | $tail .= $next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 4 | ▶ | last if $next =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 4 | ▶ | return $SEQUENCE{$tail} || 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$SEQUENCE{$tail} || 'unknown'
MC/DC0%0/1
$SEQUENCE{$tail} || 'unknown'
$SEQUENCE{$tail}
Truth table50%1/2
A
A= $SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 87 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 87 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 87 | my $leaving = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 87 | ▶ | $self->_cursor(0) if $self->_cursor > $self->candidates - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 87 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 101 | $self->show('pick'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 101 | my $key = $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 101 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC66%2/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table75%3/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 99 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 99 | ▶ | if ($key eq 'q' || $key eq 'escape') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "q" or $key eq "escape"
MC/DC50%1/2
$key eq "q" or $key eq "escape"
$key eq "q"
$key eq "escape"
Truth table66%2/3
A or B
A= $key eq "q"B= $key eq "escape"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 8 | ▶ | return 'quit' if $leaving; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 5 | $leaving = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 5 | $self->_note('Press q again to leave the game, or any other key to stay.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 91 | $leaving = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 91 | ▶ | if ($key eq 'enter' || $key eq 'space') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "enter" or $key eq "space"
MC/DC100%2/2
$key eq "enter" or $key eq "space"
$key eq "enter"
$key eq "space"
Truth table100%3/3
A or B
A= $key eq "enter"B= $key eq "space"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 78 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 78 | return Game::RoyalUr::Notation::format_move($moves[ $self->_cursor ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 13 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 11 | ▶ | return 'new' if $key eq 'n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 10 | ▶ | return 'route' if $key eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 9 | ▶ | if ($key eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | $self->show('help'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 8 | $self->steer($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | ▶ | sub _ended_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ended_key: called CC=9 SCAR=27.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 1 | $self->show('ended'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | my $key = $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC0%0/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table25%1/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 1 | ▶ | return 'new' if $key eq 'n' || $key eq 'enter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "n" or $key eq "enter"
MC/DC0%0/2
$key eq "n" or $key eq "enter"
$key eq "n"
$key eq "enter"
Truth table33%1/3
A or B
A= $key eq "n"B= $key eq "enter"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | ▶ | return 'quit' if $key eq 'q' || $key eq 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "q" or $key eq "escape"
MC/DC0%0/2
$key eq "q" or $key eq "escape"
$key eq "q"
$key eq "escape"
Truth table33%1/3
A or B
A= $key eq "q"B= $key eq "escape"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 159 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 159 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 159 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 159 | print {$out} "$_\n" for @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 159 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 75 | ▶ | sub _read_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_line: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 75 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 75 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 75 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 75 | $self->_say(@{ $self->screen('plain') }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 75 | ▶ | if (!$game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 75 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 75 | $self->_say(map { sprintf ' %s %s', $self->_paint($_ + 1, 'key'), substr($self->_readout($moves[$_]), 4) } 0 .. $#moves); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 75 | ▶ | print {$out} $game->is_over ? 'new, undo or quit> ' : $game->side . ' (' . $game->roll . ')> '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 75 | my $line = readline $self->in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 75 | ▶ | print {$out} "\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 75 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 73 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 73 | $line =~ s/\A\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 73 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 153 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=34 SCAR=36.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 153 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 153 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 153 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 153 | ▶ | return 0 unless defined $line && length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $line and length $line
MC/DC0%0/2
defined $line and length $line
defined $line
length $line
Truth table33%1/3
A and B
A= defined $lineB= length $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 153 | my ($word, $rest) = split ' ', $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 153 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 153 | ▶ | return 1 if $word eq 'quit' || $word eq 'q' || $word eq 'exit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$word eq "quit" or $word eq "q" or $word eq "exit"
$word eq "quit" or $word eq "q"
MC/DC33%1/3
$word eq "quit" or $word eq "q" or $word eq "exit"
$word eq "quit"
$word eq "q"
$word eq "exit"
Truth table50%2/4
A or B or C
A= $word eq "quit"B= $word eq "q"C= $word eq "exit"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 109 | ▶ | if ($word eq 'help' || $word eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "help" or $word eq "?"
MC/DC50%1/2
$word eq "help" or $word eq "?"
$word eq "help"
$word eq "?"
Truth table66%2/3
A or B
A= $word eq "help"B= $word eq "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | $self->_say(map { " $_" } @{ $self->help_lines }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 108 | ▶ | if ($word eq 'new' || $word eq 'n') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "new" or $word eq "n"
MC/DC50%1/2
$word eq "new" or $word eq "n"
$word eq "new"
$word eq "n"
Truth table66%2/3
A or B
A= $word eq "new"B= $word eq "n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 1 | $self->seed(Digest::SHA::sha256($self->seed . 'next')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | $self->_events([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | $self->_told(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 1 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 1 | $self->_announce_opening; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 107 | ▶ | if ($word eq 'undo' || $word eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "undo" or $word eq "u"
MC/DC50%1/2
$word eq "undo" or $word eq "u"
$word eq "undo"
$word eq "u"
Truth table66%2/3
A or B
A= $word eq "undo"B= $word eq "u"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 4 | my $taken = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 4 | ▶ | while ($game->undo) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 3 | $taken++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 3 | ▶ | last if $game->is_over || $self->_person($game->side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$game->is_over or $self->_person($game->side)
MC/DC0%0/2
$game->is_over or $self->_person($game->side)
$game->is_over
$self->_person($game->side)
Truth table33%1/3
A or B
A= $game->is_overB= $self->_person($game->side)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 4 | $self->_told(scalar @{ $game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 4 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 4 | ▶ | $taken ? $self->_event(undef, 'Taken back.') : $self->_note('There is nothing to take back.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 103 | ▶ | if ($word eq 'route' || $word eq 'r') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "route" or $word eq "r"
MC/DC50%1/2
$word eq "route" or $word eq "r"
$word eq "route"
$word eq "r"
Truth table66%2/3
A or B
A= $word eq "route"B= $word eq "r"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 2 | ▶ | $self->route($self->route ? 0 : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 101 | ▶ | if ($word eq 'moves') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 3 | $self->_say(map { ' ' . $said->($_) } @{ $game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 98 | ▶ | if ($word eq 'record') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 2 | ▶ | if (!defined $rest || !length $rest) { $self->_note('record wants the name of a file.') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $rest && length $rest
MC/DC50%1/2
defined $rest && length $rest
defined $rest
length $rest
Truth table66%2/3
A && B
A= defined $restB= length $rest
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 1 | elsif ($self->save($rest)) { $self->_event(undef, "The game is written to $rest.") } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | else { $self->_note("I could not write '$rest'.") } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 96 | ▶ | if ($word eq 'level') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 2 | my @levels = Game::RoyalUr::Bot->levels($game->variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 2 | ▶ | if (defined $rest && $rest =~ /\A\d+\z/ && $rest >= 1 && $rest <= $levels[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1
defined $rest and $rest =~ /\A\d+\z/
MC/DC25%1/4
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]
defined $rest
$rest =~ /\A\d+\z/
$rest >= 1
$rest <= $levels[-1]
Truth table40%2/5
A and B and C and D
A= defined $restB= $rest =~ /\A\d+\z/C= $rest >= 1D= $rest <= $levels[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 1 | $self->level($rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 1 | $self->_event(undef, "The program now plays at level $rest."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 1 | else { $self->_note('A level is a number from 1 to ' . $levels[-1] . '.') } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 94 | ▶ | if ($game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 1 | $self->_note('The game is over. Type new, undo or quit.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 93 | my $move = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 93 | ▶ | if ($line =~ /\A[1-7]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 9 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 9 | ▶ | if ($line > @moves) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 1 | $self->_note("There are only " . scalar(@moves) . " moves to choose from."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 8 | $move = $moves[ $line - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 92 | ▶ | if ($game->play($move)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 87 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 87 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 5 | my $error = $game->error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 5 | ▶ | $self->_note($error->code eq 'bad_move' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | ? "I do not know '$line'. A move is two places, like hand-b1 or a2-d2, or its number in the list." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | : ucfirst($error->message) . '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 92 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 2 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 2 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 2 | ▶ | open my $fh, '>', $file or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 2 | print {$fh} $self->game->to_record; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 2 | ▶ | return close $fh ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 567 | ▶ | sub _bot_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_move: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 567 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 567 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 567 | ▶ | $self->show('wait') if $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 567 | my $bot = Game::RoyalUr::Bot->new(level => $self->level); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 567 | ▶ | my $move = $bot->choose($game) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 567 | $game->play_or_die($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 567 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 567 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 49 | ▶ | sub _turns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_turns: called CC=12 SCAR=25.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 49 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 49 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 720 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 720 | ▶ | my $picking = $self->picking && $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->picking && $self->_raw
MC/DC50%1/2
$self->picking && $self->_raw
$self->picking
$self->_raw
Truth table66%2/3
A && B
A= $self->pickingB= $self->_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 720 | ▶ | if ($game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 5 | ▶ | last if $self->mode eq 'watch' && !$self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->mode eq "watch" and not $self->interactive
MC/DC50%1/2
$self->mode eq "watch" and not $self->interactive
$self->mode eq "watch"
not $self->interactive
Truth table66%2/3
A and not(B)
A= $self->mode eq "watch"B= not $self->interactive
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 1 | ▶ | my $line = $picking ? $self->_ended_key : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 1 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 1 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 715 | ▶ | if (!$self->_person($game->side)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 567 | $self->_bot_move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 567 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 148 | ▶ | my $line = $picking ? $self->pick : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 148 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 146 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 49 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 49 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=7 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 49 | ▶ | $self->picking(0) if $self->picking && !$self->_enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->picking and not $self->_enter_raw
MC/DC0%0/2
$self->picking and not $self->_enter_raw
$self->picking
not $self->_enter_raw
Truth table66%2/3
A and not(B)
A= $self->pickingB= not $self->_enter_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 49 | my $interrupt = $SIG{INT}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | local $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | $self->_leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | ▶ | $SIG{INT} = defined $interrupt ? $interrupt : 'DEFAULT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | kill 'INT', $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 49 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 49 | my $played = eval { $self->_turns; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 49 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 49 | $self->_leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 49 | ▶ | die $error unless $played; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 49 | ▶ | $self->_say(@{ $self->screen('plain') }) if $self->mode eq 'watch' || $self->game->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->mode eq "watch" or $self->game->is_over
MC/DC100%2/2
$self->mode eq "watch" or $self->game->is_over
$self->mode eq "watch"
$self->game->is_over
Truth table100%3/3
A or B
A= $self->mode eq "watch"B= $self->game->is_over
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 49 | ▶ | $self->save($self->record) if defined $self->record; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 49 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 3 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 3 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | royalur - the Royal Game of Ur, in a terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | royalur [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | --mode HOW bot (the default): you against the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | hotseat: two people at one keyboard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | watch: the program against itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | --rules NAME finkel (the default) or masters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | --level N how well the program plays, 1 upward; the top by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | --side WHICH light (the default) or dark: your side against the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | --first WHO light, dark, or roll (the default): throw the dice for it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | --seed HEX hexadecimal; the same seed throws the same dice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | --pace SECONDS how long a lost turn and the program's move stay up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | --route show the order the squares are visited in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | --record FILE write the game to FILE when you leave | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | --replay FILE carry on from a game written by --record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | --ascii plain letters and lines, for a terminal with no Unicode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | --unicode line and shape characters, where they are not the default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | --no-colour no colour; nothing is lost without it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | --no-pick type moves instead of choosing them with the arrow keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | --version the version, and stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | --help this, and stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | In a terminal, the pieces that can move are walked with the arrow keys and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | board shows what each move would leave; press ? for the keys. Anywhere else, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | type a number from the list, a move such as hand-b1 or a2-d2, or help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 48 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=22 SCAR=31.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 48 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 48 | my %given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 48 | my $parsed = Getopt::Long::GetOptionsFromArray( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | \@argv, \%given, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 'mode=s', 'rules=s', 'level=i', 'side=s', 'first=s', 'seed=s', 'pace=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 'record=s', 'replay=s', 'ascii', 'unicode!', 'route', 'colour|color!', 'pick!', 'version', 'help', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 48 | ▶ | if (!$parsed || @argv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $parsed or @argv
MC/DC100%2/2
not $parsed or @argv
not $parsed
@argv
Truth table100%3/3
not(A) or B
A= not $parsedB= @argv
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 2 | ▶ | print STDERR "royalur: I do not know '@argv'.\n" if $parsed && @argv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$parsed and @argv
MC/DC50%1/2
$parsed and @argv
$parsed
@argv
Truth table66%2/3
A and B
A= $parsedB= @argv
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 2 | print STDERR _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 46 | ▶ | if ($given{help}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 1 | print _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 45 | ▶ | if ($given{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 1 | print "royalur $Game::RoyalUr::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 44 | my %with; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 44 | $with{$_} = $given{$_} for grep { defined $given{$_} } qw(mode rules level side first pace record route); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 44 | ▶ | $with{colour} = $given{colour} if defined $given{colour}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 44 | ▶ | $with{picking} = $given{pick} if defined $given{pick}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 44 | ▶ | $with{unicode} = $given{unicode} if defined $given{unicode}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 44 | ▶ | $with{unicode} = 0 if $given{ascii}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 44 | ▶ | if (defined $given{seed}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 35 | ▶ | if ($given{seed} !~ /\A(?:[0-9a-fA-F]{2})+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 2 | print STDERR "royalur: a seed is hexadecimal, two characters a byte.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 33 | $with{seed} = pack 'H*', $given{seed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 42 | ▶ | if (defined $given{replay}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 3 | ▶ | open my $fh, '<', $given{replay} or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 1 | print STDERR "royalur: I could not read '$given{replay}'.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 1 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 2 | my $text = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 2 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 2 | my ($game, $error) = Game::RoyalUr->replay($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 2 | ▶ | if (!$game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 1 | my $detail = $error->detail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | print STDERR "royalur: '$given{replay}' is not a game I can replay: ", $error->message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 1 | ▶ | (defined $detail->{line} ? " (line $detail->{line})" : defined $detail->{ply} ? ' (turn ' . ($detail->{ply} + 1) . ')' : ''), ".\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 1 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 1 | $with{game} = $game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 1 | $with{rules} = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 1 | ▶ | $with{seed} = $game->seed if defined $game->seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 40 | my $terminal = eval { $class->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 40 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 7 | (my $why = $@) =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 7 | $why =~ s/\AGame::RoyalUr(?:::\w+)*: //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 7 | print STDERR "royalur: $why.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 7 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 33 | local @SIG{qw(INT TERM HUP)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 33 | for my $sig (qw(INT TERM HUP)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 99 | ▶ | $SIG{$sig} = sub { $terminal->_leave_raw; $SIG{$sig} = 'DEFAULT'; kill $sig, $$ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 33 | return $terminal->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 51 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||