| 1 | package Game::Dominoes::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Game::Dominoes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Game::Dominoes::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Game::Dominoes::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Game::Dominoes::Rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Game::Dominoes::Scoring; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our @PIPS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | [[1, 1]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | [[0, 0], [2, 2]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | [[0, 0], [1, 1], [2, 2]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | [[0, 0], [0, 2], [2, 0], [2, 2]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | [[0, 0], [0, 2], [1, 1], [2, 0], [2, 2]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | [[0, 0], [0, 2], [1, 0], [1, 2], [2, 0], [2, 2]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | our %CHARS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | pip => "\x{25CF}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | h => "\x{2500}", v => "\x{2502}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | tl => "\x{250C}", tr => "\x{2510}", bl => "\x{2514}", br => "\x{2518}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | t => "\x{252C}", b => "\x{2534}", l => "\x{251C}", r => "\x{2524}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | pip => '*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | h => '-', v => '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | tl => '+', tr => '+', bl => '+', br => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | t => '+', b => '+', l => '+', r => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | our %MARKED = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | recent => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | h => "\x{2550}", v => "\x{2551}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | tl => "\x{2554}", tr => "\x{2557}", bl => "\x{255A}", br => "\x{255D}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | t => "\x{2566}", b => "\x{2569}", l => "\x{2560}", r => "\x{2563}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | h => '=', v => '#', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | tl => '#', tr => '#', bl => '#', br => '#', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | t => '#', b => '#', l => '#', r => '#', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | preview => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | h => "\x{2501}", v => "\x{2503}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | tl => "\x{250F}", tr => "\x{2513}", bl => "\x{2517}", br => "\x{251B}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | t => "\x{2533}", b => "\x{253B}", l => "\x{2523}", r => "\x{252B}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | h => '=', v => '!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | tl => '+', tr => '+', bl => '+', br => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | t => '+', b => '+', l => '+', r => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | our %MARK_INK = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | new => '1;32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | recent => '32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | preview => '1;36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | our %MARK_FRAME = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | new => 'recent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | recent => 'recent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | preview => 'preview', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | our %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 'A' => 'up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'B' => 'down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'C' => 'right', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 'H' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | '1~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | '4~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | '5~' => 'page_up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | '7~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | our %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | "\r" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | "\n" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | "\x7f" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | "\x03" => 'interrupt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | our $WINDOW = 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | has game => (is => 'rw', isa => Object); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | has bots => (is => 'rw', isa => HashRef, default => {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | has in => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | has out => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | has colour => (is => 'rw', isa => Bool); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | has ascii => (is => 'rw', isa => Bool, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | has compact => (is => 'rw', isa => Bool, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | has width => (is => 'rw', isa => Int, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | has handover => (is => 'rw', isa => Bool); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | has quit => (is => 'rw', isa => Bool, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | has recent => (is => 'rw', isa => ArrayRef, default => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | has raw => (is => 'rw', isa => Bool, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | has pending => (is => 'rw', isa => ArrayRef, default => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | has _encoded => (is => 'rw', isa => Bool, default => 0, private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | has _picking => (is => 'rw', init_arg => 'picking', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 31 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=10 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 31 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 31 | ▶ | $self->in(\*STDIN) unless $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 31 | ▶ | $self->out(\*STDOUT) unless $self->out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 31 | ▶ | $self->game(Game::Dominoes->new(seed => "\0" x 32)) unless $self->game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 31 | ▶ | unless (defined $self->colour) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | my $tty = eval { -t $self->out } || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
-t $self->out
}
} || 0
MC/DC0%0/1
eval {
do {
-t $self->out
}
} || 0
eval {
do {
-t $self->out
}
}
Truth table50%1/2
A
A= eval {
do {
-t $self->out
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | $self->colour(($tty && !$ENV{NO_COLOR}) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tty and not $ENV{"NO_COLOR"}
MC/DC0%0/2
$tty and not $ENV{"NO_COLOR"}
$tty
not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= $ttyB= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 31 | ▶ | unless (defined $self->handover) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | ▶ | $self->handover($self->_humans > 1 ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 31 | $self->_encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 31 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 31 | ▶ | sub _encode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 31 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 31 | ▶ | return $self if $self->ascii || $self->_encoded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->ascii or $self->_encoded
MC/DC50%1/2
$self->ascii or $self->_encoded
$self->ascii
$self->_encoded
Truth table66%2/3
A or B
A= $self->asciiB= $self->_encoded
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | $self->_encoded(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 12 | eval { binmode $self->out, ':encoding(UTF-8)'; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 8 | ▶ | sub _humans { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_humans: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | return scalar grep { !$self->bots->{$_} } $self->game->seats; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 90 | ▶ | sub remember { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remember: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 90 | my ($self, $seat, $play) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 90 | ▶ | return $self unless ref $play && $play->can('tile') && $play->tile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $play and $play->can("tile") and $play->tile
ref $play and $play->can("tile")
MC/DC0%0/3
ref $play and $play->can("tile") and $play->tile
ref $play
$play->can("tile")
$play->tile
Truth table25%1/4
A and B and C
A= ref $playB= $play->can("tile")C= $play->tile
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 90 | my $recent = $self->recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 90 | push @$recent, { seat => $seat, play => $play }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 90 | ▶ | shift @$recent while @$recent > $self->game->players; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 90 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 84 | ▶ | sub table_marks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_marks: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 84 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 84 | my $recent = $self->recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 84 | my %mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 84 | for my $i (0 .. $#$recent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | $mark{ $recent->[$i]{play}->tile->id } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 31 | ▶ | = $i == $#$recent ? 'new' : 'recent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 84 | return \%mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 49 | ▶ | sub recent_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recent_lines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 49 | my $recent = $self->recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 49 | ▶ | return () unless @$recent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | return map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 12 | "seat $_->{seat} played " . $_->{play}->tile->stringify | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | . ' on ' . $_->{play}->arm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | . ($_->{play}->points ? ' for ' . $_->{play}->points : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 27 | ▶ | . ($_->{play}->spinner ? ', the spinner' : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } @$recent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2439 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2439 | my ($self, @text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 2439 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2439 | ▶ | print {$out} @text ? join('', @text) : '', "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2439 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 28 | ▶ | sub _ask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ask: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 28 | my ($self, $prompt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 28 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 28 | print {$out} $prompt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 28 | my $in = $self->in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 28 | my $line = <$in>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 28 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 27 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 27 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 83 | ▶ | sub table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 83 | my ($self, $view, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 83 | my $layout = $view->{layout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 83 | ▶ | $marks ||= $self->table_marks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$marks ||= $self->table_marks
MC/DC0%0/2
$marks ||= $self->table_marks
$marks
$self->table_marks
Truth table66%2/3
A ||= B
A= $marksB= $self->table_marks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 83 | ▶ | return (' (nothing on the table yet)') unless $layout->count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 46 | ▶ | return $self->_compact_table($layout, $marks) if $self->compact; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 45 | my $spinner = $layout->spinner_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 45 | my $line = $layout->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | my @cell = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 45 | $self->_tile_art($line->[$_]{left}, $line->[$_]{right}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | $line->[$_]{tile}->is_double, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | defined $spinner && $_ == $spinner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | $marks->{ $line->[$_]{tile}->id }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 78 | ▶ | } 0 .. $#$line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $spinner && $_ == $spinner
MC/DC100%2/2
defined $spinner && $_ == $spinner
defined $spinner
$_ == $spinner
Truth table100%3/3
A && B
A= defined $spinnerB= $_ == $spinner
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 45 | my @band = $self->_wrap(\@cell); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 45 | my ($first, $last) = ($band[0], $band[-1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | my $at = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | my ($run) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | return 2 unless defined $spinner && $run && $spinner >= $run->{from} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | ▶ | && $spinner <= $run->{to}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $spinner and $run and $spinner >= $run->{"from"} and $spinner <= $run->{"to"}
defined $spinner and $run and $spinner >= $run->{"from"}
defined $spinner and $run
MC/DC0%0/4
defined $spinner and $run and $spinner >= $run->{"from"} and $spinner <= $run->{"to"}
defined $spinner
$run
$spinner >= $run->{"from"}
$spinner <= $run->{"to"}
Truth table20%1/5
A and B and C and D
A= defined $spinnerB= $runC= $spinner >= $run->{"from"}D= $spinner <= $run->{"to"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | return $run->{x}[ $spinner - $run->{from} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 45 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 45 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 45 | ▶ | if (@{ $layout->u }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | my @arm = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | $self->_tile_art($_->{inner}, $_->{outer}, $_->{tile}->is_double, 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | $marks->{ $_->{tile}->id }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | } @{ $layout->u }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | my $indent = $at->($first); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | push @rows, map { $self->_band($_, $indent) } $self->_wrap(\@arm, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | push @rows, $self->_stem($indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 45 | push @rows, map { $self->_band($_, 2) } @band; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 45 | ▶ | if (@{ $layout->d }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | my @arm = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | $self->_tile_art($_->{inner}, $_->{outer}, $_->{tile}->is_double, 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $marks->{ $_->{tile}->id }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | } @{ $layout->d }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | my $indent = $at->($last); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | push @rows, $self->_stem($indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | push @rows, map { $self->_band($_, $indent) } $self->_wrap(\@arm, $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 45 | return @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | ▶ | sub _compact_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compact_table: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | my ($self, $layout, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | ▶ | $marks ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$marks ||= {}
MC/DC0%0/1
$marks ||= {}
$marks
Truth table50%1/2
A
A= $marks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | push @rows, ' ' . join(' ', map { $self->_tile($_->{tile}, $marks) } @{ $layout->u }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | if @{ $layout->u }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | push @rows, ' ' . join(' ', map { $self->_tile($_->{tile}, $marks) } @{ $layout->line }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | push @rows, ' ' . join(' ', map { $self->_tile($_->{tile}, $marks) } @{ $layout->d }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | if @{ $layout->d }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | return @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 54 | ▶ | sub _tile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tile: called CC=7 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 54 | my ($self, $tile, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 54 | ▶ | my $mark = $marks ? $marks->{ $tile->id } : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 54 | ▶ | my $text = ($mark ? '{' : '[') . $tile->high . '|' . $tile->low | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | . ($mark ? '}' : ']'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 54 | ▶ | return $text unless $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | return $self->_paint($text, $MARK_INK{$mark}) if $mark; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | return $tile->is_double ? "\e[1;33m$text\e[0m" : $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 609 | ▶ | sub _tile_art { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tile_art: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 609 | my ($self, $one, $two, $across, $bright, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 609 | ▶ | my $kind = $self->ascii ? 'ascii' : 'wide'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | my $c = $mark && $MARK_FRAME{$mark} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ? $MARKED{ $MARK_FRAME{$mark} }{$kind} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 609 | ▶ | : $CHARS{$kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mark and $Game::Dominoes::Terminal::MARK_FRAME{$mark}
MC/DC50%1/2
$mark and $Game::Dominoes::Terminal::MARK_FRAME{$mark}
$mark
$Game::Dominoes::Terminal::MARK_FRAME{$mark}
Truth table66%2/3
A and B
A= $markB= $Game::Dominoes::Terminal::MARK_FRAME{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 609 | my @face = ($self->_face($one, $across), $self->_face($two, $across)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 609 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 609 | ▶ | if ($across) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 31 | push @lines, $c->{tl} . ($c->{h} x 3) . $c->{tr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 31 | push @lines, map { $c->{v} . $_ . $c->{v} } @{ $face[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 31 | push @lines, $c->{l} . ($c->{h} x 3) . $c->{r}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 31 | push @lines, map { $c->{v} . $_ . $c->{v} } @{ $face[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 31 | push @lines, $c->{bl} . ($c->{h} x 3) . $c->{br}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 578 | push @lines, $c->{tl} . ($c->{h} x 3) . $c->{t} . ($c->{h} x 3) . $c->{tr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | push @lines, map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 578 | $c->{v} . $face[0][$_] . $c->{v} . $face[1][$_] . $c->{v} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1734 | } 0 .. 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 578 | push @lines, $c->{bl} . ($c->{h} x 3) . $c->{b} . ($c->{h} x 3) . $c->{br}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 609 | ▶ | my $ink = $mark ? $MARK_INK{$mark} : ($bright ? '1;33' : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 609 | ▶ | @lines = map { $self->_paint($_, $ink) } @lines if defined $ink; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 609 | ▶ | return { width => $across ? 5 : 9, lines => \@lines }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1218 | ▶ | sub _face { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_face: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1218 | my ($self, $pips, $turned) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1218 | ▶ | my $pip = $CHARS{ $self->ascii ? 'ascii' : 'wide' }{pip}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1218 | my @grid = map { [ (' ') x 3 ] } 0 .. 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1218 | ▶ | for my $spot (@{ $PIPS[$pips] || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Dominoes::Terminal::PIPS[$pips] || []
MC/DC0%0/1
$Game::Dominoes::Terminal::PIPS[$pips] || []
$Game::Dominoes::Terminal::PIPS[$pips]
Truth table50%1/2
A
A= $Game::Dominoes::Terminal::PIPS[$pips]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 2920 | my ($row, $col) = @$spot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2920 | ▶ | ($row, $col) = ($col, 2 - $row) if $turned; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 2920 | $grid[$row][$col] = $pip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1218 | return [ map { join '', @$_ } @grid ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 543 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 543 | my ($self, $text, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 543 | ▶ | return $text unless $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return "\e[${code}m" . $text . "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 121 | ▶ | sub _wrap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 121 | my ($self, $cells, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 121 | ▶ | $indent = 2 unless defined $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 121 | ▶ | my $room = ($self->width || $ENV{COLUMNS} || 80) - $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$self->width || $ENV{'COLUMNS'} || 80
$self->width or $ENV{"COLUMNS"}
MC/DC50%1/2
$self->width || $ENV{'COLUMNS'} || 80
$self->width
$ENV{"COLUMNS"}
Truth table66%2/3
A or B
A= $self->widthB= $ENV{"COLUMNS"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 121 | ▶ | $room = 20 if $room < 20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 121 | my @run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 121 | my ($cells_in, $x, @at) = ([], $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 121 | my $from = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 121 | for my $i (0 .. $#$cells) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 609 | my $cell = $cells->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 609 | ▶ | if (@$cells_in && $x + $cell->{width} - $indent > $room) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$cells_in and $x + $cell->{"width"} - $indent > $room
MC/DC100%2/2
@$cells_in and $x + $cell->{"width"} - $indent > $room
@$cells_in
$x + $cell->{"width"} - $indent > $room
Truth table100%3/3
A and B
A= @$cells_inB= $x + $cell->{"width"} - $indent > $room
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 9 | push @run, { cells => $cells_in, x => [@at], from => $from, to => $i - 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 9 | ($cells_in, $x, @at) = ([], $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 9 | $from = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 609 | push @$cells_in, $cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 609 | push @at, $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 609 | $x += $cell->{width}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 121 | ▶ | push @run, { cells => $cells_in, x => [@at], from => $from, to => $#$cells } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | if @$cells_in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 121 | return @run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 130 | ▶ | sub _band { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_band: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 130 | my ($self, $run, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 130 | my @cells = @{ $run->{cells} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 130 | my $height = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 130 | for my $cell (@cells) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 609 | ▶ | $height = scalar @{ $cell->{lines} } if @{ $cell->{lines} } > $height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 130 | my @rows = map { ' ' x $indent } 1 .. $height; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 130 | for my $cell (@cells) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 609 | my $top = int(($height - scalar @{ $cell->{lines} }) / 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 609 | for my $row (0 .. $height - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3826 | my $line = $cell->{lines}[ $row - $top ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | $rows[$row] .= ($row >= $top && defined $line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 3826 | ▶ | ? $line : ' ' x $cell->{width}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$row >= $top and defined $line
MC/DC100%2/2
$row >= $top and defined $line
$row >= $top
defined $line
Truth table100%3/3
A and B
A= $row >= $topB= defined $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 130 | s/\s+\z// for @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 130 | return @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 2 | ▶ | sub _stem { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stem: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | my ($self, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | ▶ | my $c = $CHARS{ $self->ascii ? 'ascii' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | return (' ' x ($indent + 2)) . $c->{v}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 45 | ▶ | sub _ends_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ends_line: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 45 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 45 | my $count = $view->{count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 45 | my $short = (5 - $count % 5) % 5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 45 | my $text = 'ends ' . join(' ', @{ $view->{ends} }) . ' count ' . $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 45 | ▶ | $text .= $short ? " ($short more would score)" : ' (scores)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 45 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 80 | ▶ | sub _scores_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scores_line: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 80 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | return 'scores ' . join(' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 200 | "seat $_: $view->{scores}{$_}" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 80 | } sort { $a <=> $b } keys %{ $view->{scores} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 77 | ▶ | sub _hands_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hands_line: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 77 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | return 'tiles ' . join(' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 192 | "seat $_: $view->{counts}{$_}" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 128 | } sort { $a <=> $b } keys %{ $view->{counts} }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 77 | . ' boneyard: ' . $view->{boneyard}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 81 | ▶ | sub hand_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_lines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 81 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 81 | ▶ | my @tiles = @{ $view->{hand} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$view->{'hand'} || []
MC/DC0%0/1
$view->{'hand'} || []
$view->{'hand'}
Truth table50%1/2
A
A= $view->{'hand'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 81 | ▶ | return ('your tiles: (none)') unless @tiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 81 | ▶ | return ('your tiles: ' . join ' ', map { $self->_tile($_) } @tiles) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | if $self->compact; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | my @cell = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 74 | my $art = $self->_tile_art($_->high, $_->low, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 529 | push @{ $art->{lines} }, sprintf '%-9s', ' ' . $_->stringify . ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 529 | $art; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } @tiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 74 | return ('your tiles:', map { $self->_band($_, 2) } $self->_wrap(\@cell)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 28 | ▶ | sub show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 28 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 28 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 28 | $self->_say("hand $view->{hand_number} " . $self->_scores_line($view)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 28 | $self->_say($self->_hands_line($view)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 28 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 28 | $self->_say($_) for $self->table($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 28 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 28 | ▶ | $self->_say($self->_ends_line($view)) if $view->{layout}->count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 28 | $self->_say($_) for $self->hand_lines($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 28 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 51 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 51 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 51 | ▶ | $self->_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 51 | ▶ | return $self->_picking ? 1 : 0 if defined $self->_picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 25 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 27 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=5 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 27 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 27 | ▶ | return 0 unless defined $self->in && eval { -t $self->in }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->in and eval {
do {
-t $self->in
}
}
MC/DC0%0/2
defined $self->in and eval {
do {
-t $self->in
}
}
defined $self->in
eval {
do {
-t $self->in
}
}
Truth table33%1/3
A and B
A= defined $self->inB= eval {
do {
-t $self->in
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 23 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 23 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 23 | ▶ | if ($self->keysource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 22 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 22 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 22 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 22 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 22 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 22 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 132 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 132 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 132 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 132 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 130 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | return Term::ReadKey::ReadKey(-1, $self->in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 68 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 68 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 68 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 68 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 62 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 49 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 17 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 32 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 32 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 32 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 32 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 32 | ▶ | unless ($opener eq '[' || $opener eq 'O') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opener eq "[" or $opener eq "O"
MC/DC100%2/2
$opener eq "[" or $opener eq "O"
$opener eq "["
$opener eq "O"
Truth table100%3/3
A or B
A= $opener eq "["B= $opener eq "O"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 30 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 30 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 32 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 32 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 32 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 32 | ▶ | last if $char =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 30 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Dominoes::Terminal::SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$Game::Dominoes::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Dominoes::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Dominoes::Terminal::SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 41 | ▶ | sub preview { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preview: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 41 | my ($self, $view, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 41 | my $trial = $view->{layout}->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 41 | my $play = $trial->place($move->{tile}, $move->{arm}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | return ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 41 | %$view, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | layout => $trial, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | count => Game::Dominoes::Scoring::count($trial), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | ends => [ $trial->open_ends ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | }, $play); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 49 | ▶ | sub choice_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
choice_lines: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 49 | my ($self, $moves, $at) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 49 | my $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 49 | ▶ | if (@$moves > $WINDOW) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 15 | $first = $at - int($WINDOW / 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 15 | ▶ | $first = 0 if $first < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 15 | ▶ | $first = @$moves - $WINDOW if $first > @$moves - $WINDOW; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 49 | my $last = $first + $WINDOW - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 49 | ▶ | $last = $#$moves if $last > $#$moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 49 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 49 | ▶ | push @lines, sprintf ' %d further up', $first if $first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 49 | for my $i ($first .. $last) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 306 | my $move = $moves->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | my $line = sprintf '%2d. %-8s %s', $i + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | $move->{tile}->stringify . '@' . $move->{arm}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 306 | ▶ | $move->{points} ? "scores $move->{points}" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 306 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 306 | ▶ | push @lines, $i == $at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | ? ' ' . $self->_paint("> $line", '1;7') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | : " $line"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 49 | ▶ | push @lines, sprintf ' %d further down', $#$moves - $last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | if $last < $#$moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 49 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 49 | ▶ | sub legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 49 | 'arrows to choose, enter to play, a number to jump to it', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 'v for the table as it stands, ? for the commands, t to type, q to quit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 23 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=25 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 23 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 23 | my $seat = $view->{seat}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 23 | my $moves = $self->game->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 23 | ▶ | return $self->_typed_turn($view) unless @$moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 23 | ▶ | unless ($self->enter_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 1 | return $self->_typed_turn($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 22 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 22 | my $live = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 22 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 22 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 49 | $self->_show_choice($view, $moves, $at, \@notice, $live); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 49 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 49 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 49 | ▶ | if (!defined $key || $key eq 'eof' || $key eq 'interrupt' || $key eq 'q') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q"
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC50%2/4
not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q"
not defined $key
$key eq "eof"
$key eq "interrupt"
$key eq "q"
Truth table60%3/5
not(A) or B or C or D
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"D= $key eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 12 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 12 | $self->quit(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 12 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 37 | ▶ | if ($key eq 'up' || $key eq 'left') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "up" or $key eq "left"
MC/DC50%1/2
$key eq "up" or $key eq "left"
$key eq "up"
$key eq "left"
Truth table66%2/3
A or B
A= $key eq "up"B= $key eq "left"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 7 | $at = ($at - 1) % @$moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 30 | ▶ | if ($key eq 'down' || $key eq 'right' || $key eq 'tab') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$key eq "down" or $key eq "right" or $key eq "tab"
$key eq "down" or $key eq "right"
MC/DC33%1/3
$key eq "down" or $key eq "right" or $key eq "tab"
$key eq "down"
$key eq "right"
$key eq "tab"
Truth table50%2/4
A or B or C
A= $key eq "down"B= $key eq "right"C= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 15 | $at = ($at + 1) % @$moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 15 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 15 | ▶ | if ($key eq 'home' || $key eq 'page_up') { $at = 0; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "home" or $key eq "page_up"
MC/DC0%0/2
$key eq "home" or $key eq "page_up"
$key eq "home"
$key eq "page_up"
Truth table33%1/3
A or B
A= $key eq "home"B= $key eq "page_up"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 15 | ▶ | if ($key eq 'end' || $key eq 'page_down') { $at = $#$moves; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "end" or $key eq "page_down"
MC/DC50%1/2
$key eq "end" or $key eq "page_down"
$key eq "end"
$key eq "page_down"
Truth table66%2/3
A or B
A= $key eq "end"B= $key eq "page_down"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 14 | ▶ | if ($key eq 'enter' || $key eq ' ') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "enter" or $key eq " "
MC/DC50%1/2
$key eq "enter" or $key eq " "
$key eq "enter"
$key eq " "
Truth table66%2/3
A or B
A= $key eq "enter"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 8 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 8 | return $self->_play($seat, $moves->[$at]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 6 | ▶ | if ($key =~ /\A[1-9]\z/ && $key <= @$moves) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key =~ /\A[1-9]\z/ and $key <= @$moves
MC/DC50%1/2
$key =~ /\A[1-9]\z/ and $key <= @$moves
$key =~ /\A[1-9]\z/
$key <= @$moves
Truth table66%2/3
A and B
A= $key =~ /\A[1-9]\z/B= $key <= @$moves
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | $at = $key - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 5 | ▶ | if ($key eq 'v') { $live = !$live; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 3 | ▶ | if ($key eq '?') { @notice = $self->help; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 3 | ▶ | if ($key eq 't' || $key eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "t" or $key eq ":"
MC/DC100%2/2
$key eq "t" or $key eq ":"
$key eq "t"
$key eq ":"
Truth table100%3/3
A or B
A= $key eq "t"B= $key eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 2 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | ▶ | $self->picking(0) if $key eq 't'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 2 | return $self->_typed_turn($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | @notice = ('that key does nothing here. ? for the ones that do'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 49 | ▶ | sub _clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=2 SCAR=9.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 49 | ▶ | return unless eval { -t $self->out }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | print {$out} "\e[2J\e[3J\e[H"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 49 | ▶ | sub _show_choice { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_choice: called CC=12 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 49 | my ($self, $view, $moves, $at, $notice, $live) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 49 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 49 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 49 | $self->_say("hand $view->{hand_number} " . $self->_scores_line($view)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 49 | $self->_say($self->_hands_line($view)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 49 | ▶ | if (my @said = $self->recent_lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 12 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 12 | $self->_say(' ', $_) for @said; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 49 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 49 | my ($shown, $title); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 49 | ▶ | if ($live) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 8 | $shown = $view; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 8 | $title = ' the table as it stands:'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 41 | my ($peek) = $self->preview($view, $moves->[$at]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 41 | $shown = $peek; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | $title = ' if you play ' . $moves->[$at]{tile}->stringify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 41 | . ' on ' . $moves->[$at]{arm} . ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 49 | $self->_say($title); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 49 | ▶ | $self->_say($_) for $self->table($shown, $live ? undef : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 41 | %{ $self->table_marks }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | $moves->[$at]{tile}->id => 'preview', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 49 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 49 | ▶ | $self->_say($self->_ends_line($shown)) if $shown->{layout}->count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 49 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 49 | $self->_say($_) for $self->hand_lines($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 49 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 49 | $self->_say($_) for $self->choice_lines($moves, $at); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 49 | ▶ | if (@$notice) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 1 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 1 | $self->_say(' ', $_) for @$notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 49 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 49 | $self->_say(' ', $_) for $self->legend; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 49 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 28 | ▶ | sub _typed_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_typed_turn: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 28 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 28 | $self->show($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 28 | $self->_say($_) for $self->_legal_lines($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 28 | my $line = $self->_ask("seat $view->{seat}> "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 28 | return $self->command($line, $view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 31 | ▶ | sub _legal_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legal_lines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 31 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 31 | my $moves = $self->game->legal($view->{seat}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 31 | ▶ | return (' (nothing to play)') unless @$moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 31 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | return map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 31 | my $line = sprintf(' %2d. %-8s %s', ++$i, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | $_->{tile}->stringify . '@' . $_->{arm}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 212 | ▶ | $_->{points} ? "scores $_->{points}" : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 212 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 212 | $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } @$moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 28 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=36 SCAR=45.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 28 | my ($self, $line, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 28 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 28 | my $seat = $view->{seat}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 28 | ▶ | return 0 unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 27 | $line =~ s/\A\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 27 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 27 | ▶ | return 1 unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 27 | my ($word, @rest) = split /\s+/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 27 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 27 | ▶ | if ($word eq 'quit' || $word eq 'q') { $self->quit(1); return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "quit" or $word eq "q"
MC/DC50%1/2
$word eq "quit" or $word eq "q"
$word eq "quit"
$word eq "q"
Truth table66%2/3
A or B
A= $word eq "quit"B= $word eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 19 | ▶ | if ($word eq 'help' || $word eq '?') { $self->_say($_) for $self->help; return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 18 | ▶ | if ($word eq 'table' || $word eq 'board') { $self->_say($_) for $self->table($view); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "table" or $word eq "board"
MC/DC50%1/2
$word eq "table" or $word eq "board"
$word eq "table"
$word eq "board"
Truth table66%2/3
A or B
A= $word eq "table"B= $word eq "board"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 15 | ▶ | if ($word eq 'hand' || $word eq 'tiles') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "hand" or $word eq "tiles"
MC/DC50%1/2
$word eq "hand" or $word eq "tiles"
$word eq "hand"
$word eq "tiles"
Truth table66%2/3
A or B
A= $word eq "hand"B= $word eq "tiles"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 3 | $self->_say($_) for $self->hand_lines($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 12 | ▶ | if ($word eq 'ends' || $word eq 'count') { $self->_say($self->_ends_line($view)); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "ends" or $word eq "count"
MC/DC50%1/2
$word eq "ends" or $word eq "count"
$word eq "ends"
$word eq "count"
Truth table66%2/3
A or B
A= $word eq "ends"B= $word eq "count"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 10 | ▶ | if ($word eq 'scores') { $self->_say($self->_scores_line($view)); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 7 | ▶ | if ($word eq 'legal' || $word eq 'moves') { $self->_say($_) for $self->_legal_lines($view); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "legal" or $word eq "moves"
MC/DC50%1/2
$word eq "legal" or $word eq "moves"
$word eq "legal"
$word eq "moves"
Truth table66%2/3
A or B
A= $word eq "legal"B= $word eq "moves"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 4 | ▶ | if ($word eq 'ascii') { $self->ascii(!$self->ascii); $self->_encode; return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 4 | ▶ | if ($word eq 'type') { $self->picking(0); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 4 | ▶ | if ($word eq 'pick') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if ($self->keys_available) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | $self->picking(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | return $self->pick($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | $self->_say('the keys are not available here, so this game is typed.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | . ' Term::ReadKey and a terminal are what it takes'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 4 | ▶ | if ($word eq 'compact') { $self->compact(!$self->compact); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 4 | ▶ | if ($word eq 'colour' || $word eq 'color') { $self->colour(!$self->colour); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word eq "colour" or $word eq "color"
MC/DC0%0/2
$word eq "colour" or $word eq "color"
$word eq "colour"
$word eq "color"
Truth table33%1/3
A or B
A= $word eq "colour"B= $word eq "color"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 4 | ▶ | if ($word eq 'history' || $word eq 'log') { $self->_say($game->to_text); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word eq "history" or $word eq "log"
MC/DC0%0/2
$word eq "history" or $word eq "log"
$word eq "history"
$word eq "log"
Truth table33%1/3
A or B
A= $word eq "history"B= $word eq "log"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 4 | ▶ | if ($word eq 'hint') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 1 | my $bot = Game::Dominoes::Bot->new(level => 4, seed => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 1 | my $move = $bot->choose($game, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | $self->_say($move | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | ? 'try ' . $move->{tile}->stringify . '@' . $move->{arm} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 1 | ▶ | : 'nothing to suggest'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 3 | ▶ | if ($word eq 'play' || $word eq 'p') { return $self->_play($seat, join(' ', @rest)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word eq "play" or $word eq "p"
MC/DC0%0/2
$word eq "play" or $word eq "p"
$word eq "play"
$word eq "p"
Truth table33%1/3
A or B
A= $word eq "play"B= $word eq "p"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 3 | ▶ | return $self->_play($seat, $line) if $line =~ /\A[0-6]-[0-6]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 1 | ▶ | if ($word =~ /\A\d+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | my $moves = $game->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my $pick = $moves->[ $word - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | unless ($pick) { $self->_say('no such move'); return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | return $self->_play($seat, $pick); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 1 | $self->_say("I do not know '$word'. Try help."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 10 | ▶ | sub _play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_play: called CC=9 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 10 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 10 | ▶ | if (!ref $move && $move =~ /\A([0-6]-[0-6])\s+([LRUDlrud])\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $move and $move =~ /\A([0-6]-[0-6])\s+([LRUDlrud])\z/
MC/DC0%0/2
not ref $move and $move =~ /\A([0-6]-[0-6])\s+([LRUDlrud])\z/
not ref $move
$move =~ /\A([0-6]-[0-6])\s+([LRUDlrud])\z/
Truth table66%2/3
not(A) and B
A= not ref $moveB= $move =~ /\A([0-6]-[0-6])\s+([LRUDlrud])\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | $move = "$1\@" . uc $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 10 | ▶ | if (!ref $move && $move =~ /\A([0-6]-[0-6])\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $move and $move =~ /\A([0-6]-[0-6])\z/
MC/DC50%1/2
not ref $move and $move =~ /\A([0-6]-[0-6])\z/
not ref $move
$move =~ /\A([0-6]-[0-6])\z/
Truth table66%2/3
not(A) and B
A= not ref $moveB= $move =~ /\A([0-6]-[0-6])\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 2 | my $want = Game::Dominoes::Notation::parse_tile($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 2 | my @fit = grep { $_->{tile}->id == $want->id } @{ $self->game->legal($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 2 | ▶ | if (@fit > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | $self->_say('which arm? ' . join(' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | map { $_->{tile}->stringify . '@' . $_->{arm} } @fit)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 2 | ▶ | $move = @fit ? { tile => $want, arm => $fit[0]{arm} } : { tile => $want }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 10 | my $out = $self->game->play($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 10 | ▶ | if (ref $out eq 'Game::Dominoes::Error') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 1 | $self->_say('no: ' . $out->message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 9 | $self->remember($seat, $out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 9 | ▶ | $self->_say('played ' . $out->tile->stringify . ' on ' . $out->arm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | . ($out->points ? ' for ' . $out->points : '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 1 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 1 | ' play <tile> [arm] or just 6-4, or the number from `legal`', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | ' legal table hand ends scores history hint', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | ' pick type ascii colour compact quit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | ' arms are L and R along the line, U and D off the spinner', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | ' a double is laid crosswise, which is how the table is drawn', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | ' a tile in a heavy frame is one played since you last looked', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 21 | ▶ | sub _handover { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handover: called CC=3 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 21 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 21 | ▶ | return 1 unless $self->handover; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | $self->_say(('') x 30); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | my $line = $self->_ask("Pass to seat $seat, then press return: "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | ▶ | return defined $line ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 25 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=15 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 25 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 25 | $self->_say('Dominoes: All Fives, ' . $game->players . ' seats, to ' . $game->target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 25 | $self->_say('Type help for the commands.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 25 | my $last_seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 25 | ▶ | while ($game->status eq 'active' && !$self->quit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$game->status eq "active" and not $self->quit
MC/DC50%1/2
$game->status eq "active" and not $self->quit
$game->status eq "active"
not $self->quit
Truth table66%2/3
A and not(B)
A= $game->status eq "active"B= not $self->quit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 128 | my $seat = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 128 | ▶ | last unless defined $seat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 128 | ▶ | if (my $bot = $self->bots->{$seat}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 80 | ▶ | my $move = $bot->choose($game, $seat) or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 80 | my $out = $game->play($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 80 | ▶ | last if ref $out eq 'Game::Dominoes::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 80 | $self->remember($seat, $out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 80 | ▶ | $self->_say("seat $seat played " . $out->tile->stringify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | . ' on ' . $out->arm . ($out->points ? ' for ' . $out->points : '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 80 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 48 | ▶ | if (!defined $last_seat || $last_seat != $seat) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $last_seat or $last_seat != $seat
MC/DC50%1/2
not defined $last_seat or $last_seat != $seat
not defined $last_seat
$last_seat != $seat
Truth table66%2/3
not(A) or B
A= not defined $last_seatB= $last_seat != $seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 21 | ▶ | last unless $self->_handover($seat); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 21 | $last_seat = $seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 48 | my $view = $game->view($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 48 | ▶ | if ($self->picking) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 23 | ▶ | last unless $self->pick($view); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 8 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 25 | ▶ | last unless $self->_typed_turn($view); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 25 | ▶ | if (my $result = $game->result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 4 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 4 | $self->_say($result->stringify); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 4 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 21 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 21 | $self->_say('stopped'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 21 | return $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | dominoes - draw dominoes with All Fives scoring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | dominoes [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | --players=N 2, 3 or 4 (default 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | --seat=N which seat the human takes (default 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | --hotseat every seat is a person, with a hand-over between turns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | --bot-vs-bot nobody is a person | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | --level=N bot level 1 to 5, repeatable, one per bot seat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | --target=N default 250 at two seats, 200 at three or four | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | --scale=N divide every score, for the cribbage board variation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | (use --scale=5 --target=61 together, never one alone) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | --variant=S all_fives, draw or block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | --reserve=N tiles at the back of the boneyard nobody may draw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | --seed=S reproduce a game exactly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | --ascii plain ASCII only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | --compact tiles as [6|4] on one line instead of drawn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | --width=N what the drawn table may use before it wraps (default 80) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | --colour force colour on or off (--nocolour) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | --nopick type the moves out instead of choosing them with the keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | --version print the version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | --help this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | Arms are L and R along the main line, U and D off the spinner. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | On a terminal the legal moves are listed under the table and chosen with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | the arrow keys: the table above the list is the one the move under the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | cursor would make, with its new count and what it would score, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | placement is seen before it is played. Enter plays it, v shows the table as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | it stands, t goes back to typing and ? prints the commands. Needs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | Term::ReadKey; without it, or off a terminal, the moves are typed out. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | The tile each seat just played is marked on the table, because at four | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | seats three of them land between your turns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | Exit status is 0 if your seat won or nobody was playing a seat, 1 if you | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | lost or stopped early, 2 for a bad option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | ▶ | sub _bad { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bad: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | my ($why) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | $why =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 0 | $why =~ s/\A[\w:]+: //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | chomp $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | print {\*STDERR} "dominoes: $why\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | my $saved = Getopt::Long::Configure(qw(bundling no_ignore_case)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | my $status = $class->_run(\@argv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | Getopt::Long::Configure($saved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: not called CC=34 SCAR=70.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | my ($class, $argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | my %opt = (players => 2, seat => 1, level => [], variant => 'all_fives'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | Getopt::Long::GetOptionsFromArray($argv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 'players=i' => \$opt{players}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 'seat=i' => \$opt{seat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 'hotseat' => \$opt{hotseat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 'bot-vs-bot' => \$opt{botonly}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 'level=i@' => $opt{level}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 'target=i' => \$opt{target}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 'scale=i' => \$opt{scale}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 'variant=s' => \$opt{variant}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 'seed=s' => \$opt{seed}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 'reserve=i' => \$opt{reserve}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 'ascii' => \$opt{ascii}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 'compact' => \$opt{compact}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 'width=i' => \$opt{width}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 'colour!' => \$opt{colour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 'color!' => \$opt{colour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 'pick!' => \$opt{pick}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 'version' => \$opt{version}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 'help|h|?' => \$opt{help}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | ▶ | ) or do { print {\*STDERR} _usage(); return 2 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | ▶ | if ($opt{help}) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | if ($opt{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | print "dominoes (Game::Dominoes) $Game::Dominoes::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | if (@{$argv}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | print {\*STDERR} "dominoes: there is nothing to do with '$argv->[0]': options begin with --\n", _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | ▶ | return _bad('--players must be 2, 3 or 4') unless $opt{players} =~ /\A[234]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | return _bad("--seat must be a seat from 1 to $opt{players}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | unless $opt{seat} =~ /\A\d+\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | && $opt{seat} >= 1 && $opt{seat} <= $opt{players}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opt{"seat"} =~ /\A\d+\z/ and $opt{"seat"} >= 1 and $opt{"seat"} <= $opt{"players"}
$opt{"seat"} =~ /\A\d+\z/ and $opt{"seat"} >= 1
MC/DC0%0/3
$opt{"seat"} =~ /\A\d+\z/ and $opt{"seat"} >= 1 and $opt{"seat"} <= $opt{"players"}
$opt{"seat"} =~ /\A\d+\z/
$opt{"seat"} >= 1
$opt{"seat"} <= $opt{"players"}
Truth table0%0/4
A and B and C
A= $opt{"seat"} =~ /\A\d+\z/B= $opt{"seat"} >= 1C= $opt{"seat"} <= $opt{"players"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | my $seed = defined $opt{seed} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | ? substr(($opt{seed} x 32), 0, 32) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | ▶ | : pack('N8', map { int rand 2**32 } 1 .. 8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | my $game = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | Game::Dominoes->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | seed => $seed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | players => $opt{players}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | variant => $opt{variant}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | (defined $opt{target} ? (target => $opt{target}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | (defined $opt{scale} ? (scale => $opt{scale}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | ▶ | (defined $opt{reserve} ? (reserve => $opt{reserve}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | ▶ | return _bad($@ || 'could not deal') unless $game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$@ || 'could not deal'
MC/DC0%0/1
$@ || 'could not deal'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | my @bot_seats = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | $opt{hotseat} ? () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | : $opt{botonly} ? ($game->seats) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | ▶ | : (grep { $_ != $opt{seat} } $game->seats); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | my @levels = @{ $opt{level} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | my %bots; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | for my $seat (@bot_seats) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | my $level = $levels[$i] // $levels[-1] // 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
($levels[$i] // $levels[-1]) // 3
$levels[$i] // $levels[-1]
MC/DC0%0/2
($levels[$i] // $levels[-1]) // 3
$levels[$i]
$levels[-1]
Truth table0%0/3
A // B
A= $levels[$i]B= $levels[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | $bots{$seat} = Game::Dominoes::Bot->new(level => $level, seed => $seat * 7919); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | my $terminal = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | game => $game, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | bots => \%bots, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | (defined $opt{colour} ? (colour => $opt{colour}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | ($opt{ascii} ? (ascii => 1) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | ($opt{compact} ? (compact => 1) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | (defined $opt{width} ? (width => $opt{width}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | ▶ | (defined $opt{pick} ? (picking => $opt{pick} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | ▶ | return _bad($@ || 'could not start') unless $terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$@ || 'could not start'
MC/DC0%0/1
$@ || 'could not start'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | local @SIG{qw(INT TERM HUP)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 0 | for my $sig (qw(INT TERM HUP)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | ▶ | $SIG{$sig} = sub { $terminal->leave_raw; $SIG{$sig} = 'DEFAULT'; kill $sig, $$ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | my $result = eval { $terminal->start }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | $terminal->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | ▶ | die $died if $died; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | ▶ | return 1 unless $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | return 0 if $opt{hotseat} || $opt{botonly}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt{"hotseat"} or $opt{"botonly"}
MC/DC0%0/2
$opt{"hotseat"} or $opt{"botonly"}
$opt{"hotseat"}
$opt{"botonly"}
Truth table0%0/3
A or B
A= $opt{"hotseat"}B= $opt{"botonly"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | ▶ | return 0 if grep { $_ == $opt{seat} } @{ $result->winners }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||