| 1 | package Game::Gin::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Game::Gin (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Game::Gin::Bot (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Game::Gin::Card qw(name_of long_name_of id_of deadwood_of rank_of suit_of); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Game::Gin::Deadwood qw(best deadwood KNOCK_AT); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | our @RANK_TEXT = ('', 'A', 2 .. 9, '10', 'J', 'Q', 'K'); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our %SUIT = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | S => { wide => "\x{2660}", ascii => 'S', colour => '90' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | H => { wide => "\x{2665}", ascii => 'H', colour => '31' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | D => { wide => "\x{2666}", ascii => 'D', colour => '31' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | C => { wide => "\x{2663}", ascii => 'C', colour => '90' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | CARD_WIDTH => 11, | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | FAN_WIDTH => 4, | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | our %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'A' => 'up', | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'B' => 'down', | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'C' => 'right', | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'H' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | '1~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | '4~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | '5~' => 'page_up', | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | '7~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | our %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | "\r" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | "\n" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | "\x7f" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | "\x03" => 'interrupt', | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | our %MARK_INK = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | drew => '1;32', | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | took => '1;36', | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | cursor => '1;7', | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | our %FRAME = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | plain => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | wide => [ "\x{250C}", "\x{2510}", "\x{2514}", "\x{2518}", | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | "\x{2500}", "\x{2502}" ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ascii => [ '+', '+', '+', '+', '-', '|' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | fresh => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | wide => [ "\x{2554}", "\x{2557}", "\x{255A}", "\x{255D}", | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | "\x{2550}", "\x{2551}" ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ascii => [ '#', '#', '#', '#', '=', '#' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | cursor => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | wide => [ "\x{250F}", "\x{2513}", "\x{2517}", "\x{251B}", | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | "\x{2501}", "\x{2503}" ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ascii => [ '>', '>', '>', '>', '=', '!' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | our %MARK_FRAME = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | drew => 'fresh', | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | took => 'fresh', | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | cursor => 'cursor', | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | has game => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | has out => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | has in => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | has mode => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | has level => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | has seat => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | has ascii => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | has colour => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | has quit => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | has raw => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | has keysource => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | has pending => (is => 'rw', isa => ArrayRef, default => []); | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | has marks => (is => 'rw', isa => HashRef, default => {}); | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | has _painting => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | has _picking => (is => 'rw', isa => Any, init_arg => 'picking'); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | has _staring => (is => 'rw', isa => Any, init_arg => 'interactive'); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2470 | ▶ | sub _out { return $_[0]->out || \*STDOUT } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_out: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->out || \*STDOUT
MC/DC0%0/1
$_[0]->out || \*STDOUT
$_[0]->out
Truth table50%1/2
A
A= $_[0]->out
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 57 | ▶ | sub _in { return $_[0]->in || \*STDIN } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->in || \*STDIN
MC/DC0%0/1
$_[0]->in || \*STDIN
$_[0]->in
Truth table50%1/2
A
A= $_[0]->in
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3440 | ▶ | sub _mode { return $_[0]->mode || 'bot' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mode: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->mode || 'bot'
MC/DC0%0/1
$_[0]->mode || 'bot'
$_[0]->mode
Truth table50%1/2
A
A= $_[0]->mode
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1118 | ▶ | sub _level { return $_[0]->level || 2 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_level: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->level || 2
MC/DC0%0/1
$_[0]->level || 2
$_[0]->level
Truth table50%1/2
A
A= $_[0]->level
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 110 | ▶ | sub _seat { return $_[0]->seat || 'p1' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seat: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->seat || 'p1'
MC/DC0%0/1
$_[0]->seat || 'p1'
$_[0]->seat
Truth table50%1/2
A
A= $_[0]->seat
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1724 | ▶ | sub _ascii { return $_[0]->ascii ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ascii: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 27 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 27 | ▶ | binmode $self->_out, ':encoding(UTF-8)' unless $self->_ascii; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 27 | my $previous = select $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 27 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 27 | select $previous; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 27 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4507 | ▶ | sub _colour { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colour: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4507 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4507 | my $on = $self->_painting; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4507 | ▶ | return $on if defined $on; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | $on = defined $self->colour ? ($self->colour ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 22 | ▶ | : ((eval { -t $self->_out } && !$ENV{NO_COLOR}) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
eval {
do {
-t $self->_out
}
} and not $ENV{"NO_COLOR"}
MC/DC0%0/2
eval {
do {
-t $self->_out
}
} and not $ENV{"NO_COLOR"}
eval {
do {
-t $self->_out
}
}
not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= eval {
do {
-t $self->_out
}
}B= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 22 | $self->_painting($on); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 22 | return $on; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4507 | ▶ | sub paint { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paint: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4507 | my ($self, $text, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 4507 | ▶ | return $text unless $self->_colour; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return "\e[${code}m" . $text . "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2383 | ▶ | sub say_to { my ($self, @what) = @_; my $fh = $self->_out; print {$fh} @what, "\n"; return } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 36 | ▶ | sub interactive { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 36 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 36 | my $want = $self->_staring; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 36 | ▶ | return $want ? 1 : 0 if defined $want; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | return (eval { -t $self->_out }) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 60 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 60 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 60 | ▶ | $self->_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 60 | ▶ | return $self->_picking ? 1 : 0 if defined $self->_picking; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 10 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=4 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 10 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 10 | ▶ | return 0 unless eval { -t $self->_in }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 27 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 27 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 13 | ▶ | if ($self->keysource) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->_in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 16 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 16 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->_in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 74 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 74 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 74 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 74 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 72 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->_in); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return Term::ReadKey::ReadKey(-1, $self->_in); | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 50 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 50 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 50 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 50 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 48 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 40 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 28 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 12 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 12 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 12 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 12 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 10 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 10 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 12 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 12 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 12 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | 12 | ▶ | last if $char =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 10 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Gin::Terminal::SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$Game::Gin::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Gin::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Gin::Terminal::SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 32 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=10.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 32 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 32 | ▶ | return $self unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $fh = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | print {$fh} "\e[2J\e[3J\e[H"; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 15 | ▶ | sub handover { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handover: called CC=8 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 15 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 15 | ▶ | return 1 unless $self->_mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | ▶ | $self->say_to('') for 1 .. ($self->interactive ? 2 : 30); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | $self->say_to("pass the keyboard to $seat, then press return"); | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | ▶ | return defined $self->read_key ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$self->picking and $self->enter_raw
MC/DC50%1/2
$self->picking and $self->enter_raw
$self->picking
$self->enter_raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->enter_raw
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | if $self->picking && $self->enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | ▶ | return defined $self->ask('') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 47 | ▶ | sub ask { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ask: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 47 | my ($self, $prompt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 47 | my $fh = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 47 | print {$fh} $prompt; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 47 | my $in = $self->_in; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 47 | my $line = <$in>; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 47 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 44 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 44 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 828 | ▶ | sub pretty { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pretty: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 828 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | 828 | ▶ | return '-' unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 828 | my $suit = $SUIT{ suit_of($id) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | return $self->paint( | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | $RANK_TEXT[ rank_of($id) ] . $suit->{ $self->_ascii ? 'ascii' : 'wide' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | $suit->{colour} | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 828 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 397 | ▶ | sub _card_rows { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_card_rows: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 397 | my ($self, $id, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | 397 | my $rank = $RANK_TEXT[ rank_of($id) ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 397 | my $suit = $SUIT{ suit_of($id) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 397 | ▶ | my $pip = $suit->{ $self->_ascii ? 'ascii' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 397 | ▶ | my $set = $FRAME{ ($mark && $MARK_FRAME{$mark}) || 'plain' }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$mark && $Game::Gin::Terminal::MARK_FRAME{$mark} || 'plain'
$mark and $Game::Gin::Terminal::MARK_FRAME{$mark}
MC/DC50%1/2
$mark && $Game::Gin::Terminal::MARK_FRAME{$mark} || 'plain'
$mark
$Game::Gin::Terminal::MARK_FRAME{$mark}
Truth table66%2/3
A and B
A= $markB= $Game::Gin::Terminal::MARK_FRAME{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | my ($tl, $tr, $bl, $br, $h, $v) | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 397 | ▶ | = @{ $set->{ $self->_ascii ? 'ascii' : 'wide' } }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | return ([ | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $tl . ($h x 9) . $tr, | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $v . sprintf('%-9s', $rank) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $v . sprintf('%-9s', $pip) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | $v . (' ' x 9) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | $v . ' ' . $pip . ' ' . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | $v . (' ' x 9) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | $v . sprintf('%9s', $pip) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | $v . sprintf('%9s', $rank) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | $bl . ($h x 9) . $br, | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 397 | ], $suit->{colour}); | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 30 | ▶ | sub card_art { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_art: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 30 | my ($self, $id, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 30 | my ($rows, $colour) = $self->_card_rows($id, $mark); | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | 30 | ▶ | my $ink = $mark && $MARK_INK{$mark} ? $MARK_INK{$mark} : $colour; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mark and $Game::Gin::Terminal::MARK_INK{$mark}
MC/DC50%1/2
$mark and $Game::Gin::Terminal::MARK_INK{$mark}
$mark
$Game::Gin::Terminal::MARK_INK{$mark}
Truth table66%2/3
A and B
A= $markB= $Game::Gin::Terminal::MARK_INK{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 30 | return [ map { $self->paint($_, $ink) } @$rows ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | ▶ | sub card_space { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_space: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | my ($h, $v) = $self->_ascii ? ('-', ':') : ("\x{2504}", "\x{250A}"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 54 | return [ map { $self->paint($_, '90') } ( | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | ' ' . ($h x 9) . ' ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 6 | (map { $v . (' ' x 9) . $v } 1 .. 7), | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | ' ' . ($h x 9) . ' ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 34 | ▶ | sub card_back { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_back: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 34 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 34 | ▶ | my ($tl, $tr, $bl, $br, $h, $v, $fill) = $self->_ascii | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ? ('+', '+', '+', '+', '-', '|', '#') | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | : ("\x{250C}", "\x{2510}", "\x{2514}", "\x{2518}", "\x{2500}", "\x{2502}", "\x{2591}"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | $tl . ($h x 9) . $tr, | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 34 | (map { $v . ($fill x 9) . $v } 1 .. 7), | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | $bl . ($h x 9) . $br, | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 35 | ▶ | sub fan { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fan: called CC=9 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 35 | my ($self, $ids, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 35 | ▶ | return [ ('') x 9 ] unless $ids && @$ids; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ids and @$ids
MC/DC0%0/2
$ids and @$ids
$ids
@$ids
Truth table33%1/3
A and B
A= $idsB= @$ids
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 35 | ▶ | $marks ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$marks ||= {}
MC/DC0%0/1
$marks ||= {}
$marks
Truth table50%1/2
A
A= $marks
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 35 | my @out = ('') x 9; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 35 | for my $i (0 .. $#$ids) { | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | 367 | my $mark = $marks->{ $ids->[$i] }; | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | 367 | my ($rows, $colour) = $self->_card_rows($ids->[$i], $mark); | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 367 | ▶ | my $ink = $mark && $MARK_INK{$mark} ? $MARK_INK{$mark} : $colour; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mark and $Game::Gin::Terminal::MARK_INK{$mark}
MC/DC50%1/2
$mark and $Game::Gin::Terminal::MARK_INK{$mark}
$mark
$Game::Gin::Terminal::MARK_INK{$mark}
Truth table66%2/3
A and B
A= $markB= $Game::Gin::Terminal::MARK_INK{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 367 | my $last = $i == $#$ids; | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 367 | for my $row (0 .. 8) { | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3303 | ▶ | my $part = $last ? $rows->[$row] : substr $rows->[$row], 0, FAN_WIDTH; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3303 | $out[$row] .= $self->paint($part, $ink); | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 35 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 36 | ▶ | sub fan_width { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fan_width: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 36 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 36 | ▶ | return 0 unless $n; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 36 | return (($n - 1) * FAN_WIDTH) + CARD_WIDTH; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 34 | ▶ | sub _beside { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_beside: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 34 | my ($self, $gap, @blocks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 34 | my $height = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 34 | for my $block (@blocks) { | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | 68 | ▶ | $height = scalar @{ $block->{lines} } if @{ $block->{lines} } > $height; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 34 | my @rows = ('') x $height; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | 34 | for my $i (0 .. $#blocks) { | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 68 | my $block = $blocks[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 68 | for my $row (0 .. $height - 1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 612 | ▶ | $rows[$row] .= ' ' x $gap if $i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 612 | my $line = $block->{lines}[$row]; | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 612 | ▶ | $rows[$row] .= defined $line ? $line : ' ' x $block->{width}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 34 | s/\s+\z// for @rows; | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | 34 | return @rows; | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 34 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 34 | my ($self, $seat, $without, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 34 | my $deal = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 34 | my $hand = $deal->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 34 | my @cards = @{ $hand->cards }; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 34 | ▶ | @cards = grep { $_ != $without } @cards if defined $without; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 34 | my $melding = best(\@cards); | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 34 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | 34 | push @lines, sprintf('deal %d, dealt by %s', $deal->number, $deal->dealer); | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | push @lines, sprintf('score p1 %d p2 %d (to %d)', | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | $self->game->scores->{p1}, $self->game->scores->{p2}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 34 | $self->game->target); | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 34 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 34 | push @lines, $self->table_lines($deal, $seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 34 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | 34 | push @lines, $self->hand_lines($melding, $marks); | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | 34 | push @lines, $self->knock_line($melding); | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 34 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 34 | ▶ | sub knock_line { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
knock_line: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 34 | my ($self, $melding) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | return $melding->{deadwood} <= KNOCK_AT | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | ? sprintf('you may knock (%d)', $melding->{deadwood}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 34 | ▶ | : sprintf('%d to go before you may knock', $melding->{deadwood} - KNOCK_AT); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 16 | ▶ | sub preview { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preview: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 16 | my ($self, $seat, $card) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | 16 | my @rest = grep { $_ != $card } @{ $self->game->deal->hand_of($seat)->cards }; | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 16 | return best(\@rest); | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 18 | ▶ | sub choice_cards { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
choice_cards: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 18 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 18 | my (%playable, %knock); | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 18 | for my $move (@{ $self->game->deal->legal($seat) }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | 196 | ▶ | next unless $move->{kind} eq 'discard'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 196 | $playable{ $move->{card} } = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | 196 | ▶ | $knock{ $move->{card} } = 1 if $move->{knock}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 18 | my $groups = $self->hand_groups(best($self->game->deal->hand_of($seat)->cards)); | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 18 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | 18 | for my $group (@$groups) { | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | 35 | for my $card (@{ $group->{cards} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | 198 | ▶ | next unless $playable{$card}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | push @out, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | card => $card, | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | knock => $knock{$card} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | loose => $group->{loose}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 192 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 18 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 16 | ▶ | sub first_loose { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_loose: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 16 | my ($self, $choices) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 16 | my ($at) = grep { $choices->[$_]{loose} } 0 .. $#$choices; | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | 16 | ▶ | return defined $at ? $at : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 17 | ▶ | sub legend { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 17 | my ($self, $choice) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | 17 | my @key = ('left and right to choose', 'enter to discard'); | |||||||||||||||||||||||||||||||||||||||||||||
| 436 | 17 | ▶ | push @key, 'k to discard and knock' if $choice && $choice->{knock}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$choice and $choice->{"knock"}
MC/DC50%1/2
$choice and $choice->{"knock"}
$choice
$choice->{"knock"}
Truth table66%2/3
A and B
A= $choiceB= $choice->{"knock"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 17 | push @key, '? for the rest', 'q to stop'; | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 17 | return join ', ', @key; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 12 | ▶ | sub pick_discard { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_discard: called CC=23 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 12 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 12 | my $choices = $self->choice_cards($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 12 | ▶ | return undef unless @$choices; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 12 | my $legal = $self->game->deal->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | 12 | my ($big) = grep { $_->{kind} eq 'big_gin' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 12 | my $at = $self->first_loose($choices); | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | 12 | my $remelded = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | 12 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 12 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 455 | 17 | $self->show_choice($seat, $choices, $at, \@notice, $big, $remelded); | |||||||||||||||||||||||||||||||||||||||||||||
| 456 | 17 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 17 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | 17 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC33%1/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table50%2/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 16 | ▶ | if ($key eq 'q') { $self->quit(1); return undef } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 9 | ▶ | if ($key eq 'left' || $key eq 'down') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "left" or $key eq "down"
MC/DC0%0/2
$key eq "left" or $key eq "down"
$key eq "left"
$key eq "down"
Truth table33%1/3
A or B
A= $key eq "left"B= $key eq "down"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $at = ($at - 1) % @$choices; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 9 | ▶ | if ($key eq 'right' || $key eq 'up' || $key eq 'tab') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$key eq "right" or $key eq "up" or $key eq "tab"
$key eq "right" or $key eq "up"
MC/DC33%1/3
$key eq "right" or $key eq "up" or $key eq "tab"
$key eq "right"
$key eq "up"
$key eq "tab"
Truth table50%2/4
A or B or C
A= $key eq "right"B= $key eq "up"C= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | $at = ($at + 1) % @$choices; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 6 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 6 | ▶ | if ($key eq 'end' || $key eq 'page_down') { $at = $#$choices; next } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "end" or $key eq "page_down"
MC/DC0%0/2
$key eq "end" or $key eq "page_down"
$key eq "end"
$key eq "page_down"
Truth table33%1/3
A or B
A= $key eq "end"B= $key eq "page_down"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | ▶ | 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 " "
| |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | return { kind => 'discard', card => $choices->[$at]{card} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 3 | ▶ | if ($key eq 'k') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | return { kind => 'discard', card => $choices->[$at]{card}, knock => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 2 | ▶ | if $choices->[$at]{knock}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | @notice = ('you cannot knock on that one'); | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | ▶ | if ($key eq 'g' && $big) { return $big } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "g" and $big
MC/DC0%0/2
$key eq "g" and $big
$key eq "g"
$big
Truth table33%1/3
A and B
A= $key eq "g"B= $big
| |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | ▶ | if ($key eq 'v') { $remelded = !$remelded; next } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ($key eq '?') { @notice = $self->help_lines; next } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | @notice = ('that key does nothing here. ? for the ones that do'); | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 17 | ▶ | sub show_choice { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_choice: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 17 | my ($self, $seat, $choices, $at, $notice, $big, $remelded) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 17 | my $card = $choices->[$at]{card}; | |||||||||||||||||||||||||||||||||||||||||||||
| 498 | 17 | my $deal = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 17 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | 17 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 17 | ▶ | if ($remelded) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | $self->say_to($_) for @{ $self->render($seat, $card) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | $self->say_to(' that is the hand WITHOUT ' . $self->pretty($card) | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | . '. v puts it back.'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 16 | my %mark = (%{ $self->marks }, $card => 'cursor'); | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | 16 | $self->say_to($_) for @{ $self->render($seat, undef, \%mark) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 16 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | 16 | $self->say_to(' ' . $self->without_line($seat, $choices->[$at])); | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 17 | ▶ | $self->say_to(' big gin is there for the taking: press g') if $big; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 17 | ▶ | if (@$notice) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | $self->say_to(' ', $_) for @$notice; | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 17 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 17 | $self->say_to(' ', $self->legend($choices->[$at])); | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 16 | ▶ | sub without_line { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
without_line: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 16 | my ($self, $seat, $choice) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 530 | 16 | my $melding = $self->preview($seat, $choice->{card}); | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | my $line = 'throw ' . $self->pretty($choice->{card}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 16 | . ' and your count is ' . $melding->{deadwood}; | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | 16 | ▶ | $line .= ', which lets you knock' if $choice->{knock}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 16 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | sub help_lines { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | 'left and right walk your hand. the card under the cursor is the one', | |||||||||||||||||||||||||||||||||||||||||||||
| 540 | 'you would throw, and the line under the fan says what it leaves you.', | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 'enter discards it. k discards it and knocks, when that is allowed.', | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 'v shows the hand remelded without it. g declares big gin when it is', | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 'offered. q stops. ? is this.', | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 34 | ▶ | sub table_lines { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_lines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 34 | my ($self, $deal, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | 34 | my $upcard = $deal->upcard; | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | 34 | ▶ | my @label = ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | sprintf('stock %d', $deal->stock_left), | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | defined $upcard ? 'upcard ' . $self->pretty($upcard) : 'no upcard', | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||
| 555 | my @blocks = ({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | width => CARD_WIDTH, | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | lines => $deal->stock_left ? $self->card_back : $self->card_space, | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | }, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | width => CARD_WIDTH, | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | lines => defined $upcard | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 34 | ▶ | ? $self->card_art($upcard, $self->marks->{$upcard}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | : $self->card_space, | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 34 | my $head = sprintf('%-*s', CARD_WIDTH + 5, $label[0]) . $label[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 566 | 34 | return ($head, $self->_beside(5, @blocks)); | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 54 | ▶ | sub hand_groups { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_groups: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 54 | my ($self, $melding) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | 54 | my @group; | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | 54 | for my $meld (@{ $melding->{melds} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 573 | 36 | my @cards = sort { $a <=> $b } @$meld; | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | 36 | my $same = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 575 | 36 | ▶ | $same &&= rank_of($_) == rank_of($cards[0]) for @cards; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$same &&= rank_of($_) == rank_of($cards[0])
MC/DC100%2/2
$same &&= rank_of($_) == rank_of($cards[0])
$same
rank_of($_) == rank_of($cards[0])
Truth table100%3/3
A &&= B
A= $sameB= rank_of($_) == rank_of($cards[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 36 | ▶ | push @group, { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | cards => \@cards, | ||||||||||||||||||||||||||||||||||||||||||||||
| 578 | label => $same ? 'set' : 'run', | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | loose => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 580 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 582 | push @group, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 1048 | cards => [ sort { $a <=> $b } @{ $melding->{unmatched} } ], | |||||||||||||||||||||||||||||||||||||||||||||
| 584 | label => 'loose ' . $melding->{deadwood}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | loose => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 54 | ▶ | } if @{ $melding->{unmatched} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 54 | return \@group; | |||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 35 | ▶ | sub hand_lines { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_lines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 35 | my ($self, $melding, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | 35 | my @group = @{ $self->hand_groups($melding) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 35 | my @ids = map { @{ $_->{cards} } } @group; | |||||||||||||||||||||||||||||||||||||||||||||
| 595 | 35 | ▶ | return ('you are holding nothing') unless @ids; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 35 | ▶ | my @lines = @{ $self->fan(\@ids, $marks || $self->marks) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$marks || $self->marks
MC/DC0%0/2
$marks || $self->marks
$marks
$self->marks
Truth table66%2/3
A || B
A= $marksB= $self->marks
| |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 35 | push @lines, $self->_brackets(\@group, scalar @ids); | |||||||||||||||||||||||||||||||||||||||||||||
| 599 | 35 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 35 | ▶ | sub _brackets { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_brackets: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 35 | my ($self, $groups, $total) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | 35 | ▶ | my ($h, $bl, $br) = $self->_ascii | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | ? ('-', '+', '+') : ("\x{2500}", "\x{2514}", "\x{2518}"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 35 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 607 | 35 | my $seen = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 608 | 35 | for my $group (@$groups) { | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | 52 | my $n = scalar @{ $group->{cards} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 610 | 52 | $seen += $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | 52 | ▶ | my $width = $seen == $total ? $self->fan_width($n) : $n * FAN_WIDTH; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 52 | my $label = $group->{label}; | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | 52 | ▶ | $label = '' if length($label) + 4 > $width; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 52 | my $rule = $width - 2 - length $label; | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 52 | my $left = int($rule / 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | 52 | $line .= $self->paint( | |||||||||||||||||||||||||||||||||||||||||||||
| 617 | $bl . ($h x $left) . $label . ($h x ($rule - $left)) . $br, '90' | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 35 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 5 | ▶ | sub show { my ($self, $seat) = @_; $self->say_to($_) for @{ $self->render($seat) }; return } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 44 | ▶ | sub card_named { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_named: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 44 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 627 | 44 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 44 | $text =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | 44 | for my $suit (keys %SUIT) { | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | 176 | my $pip = $SUIT{$suit}{wide}; | |||||||||||||||||||||||||||||||||||||||||||||
| 631 | 176 | $text =~ s/\Q$pip\E/$suit/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 44 | $text =~ s/\A10/T/; | |||||||||||||||||||||||||||||||||||||||||||||
| 634 | 44 | return id_of($text); | |||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1118 | ▶ | sub bot_move { my ($self, $seat) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot_move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 1118 | return Game::Gin::Bot->new(level => $self->_level)->choose($self->game, $seat) } | |||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 3409 | ▶ | sub is_human { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_human: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 3409 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 3409 | my $mode = $self->_mode; | |||||||||||||||||||||||||||||||||||||||||||||
| 643 | 3409 | ▶ | return 0 if $mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 124 | ▶ | return 1 if $mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 110 | ▶ | return $seat eq $self->_seat ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 28 | ▶ | sub human_move { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
human_move: called CC=25 SCAR=43.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 28 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 650 | 28 | my $deal = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||
| 651 | 28 | my $legal = $deal->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | 28 | my $phase = $deal->phase; | |||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 28 | ▶ | if ($phase eq 'forced_draw') { return { kind => 'draw' } } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 28 | ▶ | return $self->pick_move($seat, $phase, $legal) if $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 7 | ▶ | if ($phase eq 'upcard') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 2 | my $a = $self->ask('take the ' . $self->pretty($deal->upcard) . '? (y/n) '); | |||||||||||||||||||||||||||||||||||||||||||||
| 660 | 2 | ▶ | return undef unless defined $a; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 2 | ▶ | return undef if $self->_stopping($a); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 2 | ▶ | return { kind => $a =~ /^y/i ? 'take' : 'pass' }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 5 | ▶ | if ($phase eq 'draw') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 3 | my $a = $self->ask('(d)raw or (t)ake ' . $self->pretty($deal->upcard) . '? '); | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | 3 | ▶ | return undef unless defined $a; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 3 | ▶ | return undef if $self->_stopping($a); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | ▶ | return { kind => $a =~ /^t/i ? 'take' : 'draw' }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 2 | my ($big) = grep { $_->{kind} eq 'big_gin' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | 2 | ▶ | if ($big) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | my $a = $self->ask('big gin! declare it? (y/n) '); | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | return $big if defined $a && $a =~ /^y/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $a and $a =~ /^y/i
MC/DC0%0/2
defined $a and $a =~ /^y/i
defined $a
$a =~ /^y/i
Truth table0%0/3
A and B
A= defined $aB= $a =~ /^y/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 2 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 678 | 41 | my $a = $self->ask('discard which card? (e.g. KH, or KH! to knock) '); | |||||||||||||||||||||||||||||||||||||||||||||
| 679 | 41 | ▶ | return undef unless defined $a; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 39 | ▶ | return undef if $self->_stopping($a); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 39 | ▶ | if ($a =~ /\A\s*(?:\?|h|help)\s*\z/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | $self->say_to($_) for $self->typed_help; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 39 | my $knock = $a =~ s/!\s*$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 688 | 39 | my $card = $self->card_named($a); | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | 39 | ▶ | unless (defined $card) { $self->say_to('not a card'); next } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | my ($move) = grep { $_->{kind} eq 'discard' && $_->{card} == $card | |||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | && (($_->{knock} ? 1 : 0) == ($knock ? 1 : 0)) } @$legal; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$_->{'kind'} eq 'discard' && $_->{'card'} == $card && ($_->{'knock'} ? 1 : 0) == ($knock ? 1 : 0)
$_->{"kind"} eq "discard" and $_->{"card"} == $card
MC/DC0%0/3
$_->{'kind'} eq 'discard' && $_->{'card'} == $card && ($_->{'knock'} ? 1 : 0) == ($knock ? 1 : 0)
$_->{"kind"} eq "discard"
$_->{"card"} == $card
($_->{'knock'} ? 1 : 0) == ($knock ? 1 : 0)
Truth table0%0/4
A and B && C
A= $_->{"kind"} eq "discard"B= $_->{"card"} == $cardC= ($_->{'knock'} ? 1 : 0) == ($knock ? 1 : 0)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | return $move if $move; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | $self->say_to($knock ? 'you cannot knock on that' : 'you are not holding that'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 44 | ▶ | sub _stopping { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stopping: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 44 | my ($self, $answer) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 699 | 44 | ▶ | return 0 unless defined $answer && $answer =~ /\A\s*(?:q|quit|exit)\s*\z/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $answer and $answer =~ /\A\s*(?:q|quit|exit)\s*\z/i
MC/DC50%1/2
defined $answer and $answer =~ /\A\s*(?:q|quit|exit)\s*\z/i
defined $answer
$answer =~ /\A\s*(?:q|quit|exit)\s*\z/i
Truth table66%2/3
A and B
A= defined $answerB= $answer =~ /\A\s*(?:q|quit|exit)\s*\z/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | $self->quit(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 701 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | sub typed_help { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
typed_help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | 'name a card to discard it: KH, or 10H, or K with the pip itself.', | |||||||||||||||||||||||||||||||||||||||||||||
| 707 | 'add a ! to knock with it: KH!', | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 'quit stops. ? is this.', | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 21 | ▶ | sub pick_move { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_move: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 21 | my ($self, $seat, $phase, $legal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 21 | ▶ | unless ($self->enter_raw) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 1 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 1 | return $self->human_move($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 20 | ▶ | return $self->pick_draw($seat, $phase) if $phase eq 'upcard' || $phase eq 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$phase eq "upcard" or $phase eq "draw"
MC/DC100%2/2
$phase eq "upcard" or $phase eq "draw"
$phase eq "upcard"
$phase eq "draw"
Truth table100%3/3
A or B
A= $phase eq "upcard"B= $phase eq "draw"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 9 | return $self->pick_discard($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 11 | ▶ | sub pick_draw { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_draw: called CC=18 SCAR=39.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 11 | my ($self, $seat, $phase) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 11 | my $deal = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||
| 728 | 11 | my $upcard = $deal->upcard; | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | 11 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 11 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 732 | 11 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||
| 733 | 11 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 734 | 11 | $self->say_to($_) for @{ $self->render($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 735 | 11 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 736 | 11 | ▶ | $self->say_to(' u takes the ' . $self->pretty($upcard) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | . ', d draws from the stock' | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | . ($phase eq 'upcard' ? ', n passes it up' : '')); | ||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 11 | ▶ | if (@notice) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | $self->say_to(' ', $_) for @notice; | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 11 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | 11 | $self->say_to(' ? for the rest, q to stop'); | |||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 11 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | 11 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC0%0/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table25%1/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 11 | ▶ | if ($key eq 'q') { $self->quit(1); return undef } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 9 | ▶ | return { kind => 'take' } if $key eq 'u' || $key eq 't'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "u" or $key eq "t"
MC/DC50%1/2
$key eq "u" or $key eq "t"
$key eq "u"
$key eq "t"
Truth table66%2/3
A or B
A= $key eq "u"B= $key eq "t"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 8 | ▶ | if ($key eq 'd') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 8 | ▶ | return { kind => 'draw' } if $phase eq 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | @notice = ('on the first turn it is take it or pass it up: u or n'); | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | if ($key eq 'n' || $key eq 'p') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "n" or $key eq "p"
MC/DC0%0/2
$key eq "n" or $key eq "p"
$key eq "n"
$key eq "p"
Truth table0%0/3
A or B
A= $key eq "n"B= $key eq "p"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | return { kind => 'pass' } if $phase eq 'upcard'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | @notice = ('you cannot pass now: u to take it, d to draw'); | |||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | if ($key eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | @notice = ($phase eq 'upcard' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | ? 'u takes the upcard, n passes it up. that is the whole choice.' | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | : 'u takes the upcard, d draws the card nobody has seen.'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | @notice = ('that key does nothing here. ? for the ones that do'); | |||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 16 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=20 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 16 | my ($self, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 780 | 16 | ▶ | my $seed = $o{seed} || Digest::SHA::sha256(join ':', 'gin', $$, time, rand); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$o{'seed'} || &Digest::SHA::sha256(join(':', 'gin', $$, time, rand))
MC/DC0%0/2
$o{'seed'} || &Digest::SHA::sha256(join(':', 'gin', $$, time, rand))
$o{'seed'}
&Digest::SHA::sha256(join(':', 'gin', $$, time, rand))
Truth table33%1/3
A || B
A= $o{'seed'}B= &Digest::SHA::sha256(join(':', 'gin', $$, time, rand))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 16 | ▶ | $self->game(Game::Gin->build(seed => $seed, dealer => $o{dealer} || 'p1')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o{'dealer'} || 'p1'
MC/DC0%0/1
$o{'dealer'} || 'p1'
$o{'dealer'}
Truth table50%1/2
A
A= $o{'dealer'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 16 | ▶ | $self->say_to(sprintf('deal %d, dealt by %s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 784 | $self->game->number, $self->game->dealer)) | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | if $self->_mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 16 | ▶ | my $limit = $o{limit} || 20_000; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{'limit'} || 20000
MC/DC100%1/1
$o{'limit'} || 20000
$o{'limit'}
Truth table100%2/2
A
A= $o{'limit'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 16 | my $moves = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 789 | 16 | my $last_seat; | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | 16 | ▶ | while (!$self->game->over && !$self->quit && $moves++ < $limit) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $self->game->over || $self->quit and $moves++ < $limit
$self->game->over || $self->quit
MC/DC33%1/3
not $self->game->over || $self->quit and $moves++ < $limit
$self->game->over
$self->quit
$moves++ < $limit
Truth table50%2/4
not(A || B) and C
A= $self->game->overB= $self->quitC= $moves++ < $limit
| |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 1145 | ▶ | my $seat = $self->game->turn or last; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 1145 | my $number = $self->game->number; | |||||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 1145 | my $move; | |||||||||||||||||||||||||||||||||||||||||||||
| 795 | 1145 | ▶ | if ($self->is_human($seat)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 27 | ▶ | if (!defined $last_seat || $last_seat ne $seat) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $last_seat or $last_seat ne $seat
MC/DC100%2/2
not defined $last_seat or $last_seat ne $seat
not defined $last_seat
$last_seat ne $seat
Truth table100%3/3
not(A) or B
A= not defined $last_seatB= $last_seat ne $seat
| |||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 15 | ▶ | last unless $self->handover($seat); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 14 | $last_seat = $seat; | |||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 26 | ▶ | $self->show($seat) unless $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 26 | $move = $self->human_move($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 802 | 26 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 1118 | $move = $self->bot_move($seat); | |||||||||||||||||||||||||||||||||||||||||||||
| 806 | 1118 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||
| 809 | my %held = $self->is_human($seat) | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1132 | ▶ | ? (map { $_ => 1 } @{ $self->game->deal->hand_of($seat)->cards }) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 811 | : (); | ||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 1132 | my @out = $self->game->apply($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||
| 814 | 1132 | ▶ | if (ref $out[0] eq 'Game::Gin::Error') { $self->say_to($out[0]->message); next } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 1132 | $self->remember($seat, \%held, \@out); | |||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1132 | $self->announce($_) for @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 817 | 1132 | ▶ | $self->say_to('') if $self->game->number != $number; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 16 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 16 | $self->announce_result; | |||||||||||||||||||||||||||||||||||||||||||||
| 823 | 16 | return $self->game; | |||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 1132 | ▶ | sub remember { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remember: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 1132 | my ($self, $seat, $held, $out) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 1132 | my $discard = grep { $_->{kind} eq 'discard' } @$out; | |||||||||||||||||||||||||||||||||||||||||||||
| 830 | 1132 | my $deal = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 1132 | ▶ | if ($discard) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 551 | my $upcard = $deal->upcard; | |||||||||||||||||||||||||||||||||||||||||||||
| 834 | 551 | ▶ | $self->marks(defined $upcard && !$self->is_human($seat) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $upcard and not $self->is_human($seat)
MC/DC50%1/2
defined $upcard and not $self->is_human($seat)
defined $upcard
not $self->is_human($seat)
Truth table66%2/3
A and not(B)
A= defined $upcardB= not $self->is_human($seat)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 835 | ? { $upcard => 'took' } : {}); | ||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 551 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 581 | ▶ | return $self->marks({}) unless $self->is_human($seat); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 12 | ▶ | my $hand = $deal->hand_of($seat) or return $self->marks({}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 12 | my $took = grep { $_->{kind} eq 'take' } @$out; | |||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 12 | my %mark; | |||||||||||||||||||||||||||||||||||||||||||||
| 845 | 12 | for my $card (@{ $hand->cards }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 846 | 130 | ▶ | next if $held->{$card}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 10 | ▶ | $mark{$card} = $took ? 'took' : 'drew'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 12 | $self->marks(\%mark); | |||||||||||||||||||||||||||||||||||||||||||||
| 851 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 1204 | ▶ | sub announce { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
announce: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 1204 | my ($self, $out) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 856 | 1204 | my $k = $out->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||
| 857 | 1204 | ▶ | return $self->say_to("$out->{seat} takes " . $self->pretty($out->{card})) if $k eq 'take'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 1039 | ▶ | return $self->say_to("$out->{seat} draws") if $k eq 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 644 | ▶ | return $self->say_to("$out->{seat} passes") if $k eq 'pass'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 860 | return $self->say_to("$out->{seat} discards " . $self->pretty($out->{card}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 624 | ▶ | . ($out->{knock} ? ' and knocks' : '')) if $k eq 'discard'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 73 | ▶ | return $self->say_to("$out->{seat} declares big gin") if $k eq 'big_gin'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 72 | ▶ | return $self->say_to('the stock ran out: the hand is cancelled') if $k eq 'cancelled'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 72 | ▶ | if ($k eq 'hand_end') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 865 | return $self->say_to(sprintf('%s wins the hand by %s, %d points', | ||||||||||||||||||||||||||||||||||||||||||||||
| 866 | $out->{winner}, $out->{how} // '?', $out->{points})) | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 36 | ▶ | if $out->{winner}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out->{"how"} // "?"
MC/DC0%0/1
$out->{"how"} // "?"
$out->{"how"}
Truth table50%1/2
A
A= $out->{"how"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | return $self->say_to('the hand is over'); | |||||||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 36 | ▶ | return $self->say_to(sprintf('deal %d, dealt by %s', $out->{number}, $out->{dealer})) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 871 | if $k eq 'deal'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 16 | ▶ | sub announce_result { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
announce_result: called CC=6 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 877 | 16 | ▶ | my $r = $self->game->result or return $self->say_to('unfinished'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 878 | $self->say_to(sprintf('%s wins: %d to %d%s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 879 | $r->{winner} // 'nobody', | ||||||||||||||||||||||||||||||||||||||||||||||
| 880 | $r->{totals}{ $r->{winner} // 'p1' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | $r->{totals}{ $r->{loser} // 'p2' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 3 | ▶ | $r->{shutout} ? ', a shutout' : '')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$r->{"winner"} // "nobody"
$r->{"winner"} // "p1"
$r->{"loser"} // "p2"
MC/DC0%0/1
$r->{"winner"} // "nobody"
$r->{"winner"}
MC/DC0%0/1
$r->{"winner"} // "p1"
$r->{"winner"}
MC/DC0%0/1
$r->{"loser"} // "p2"
$r->{"loser"}
Truth table50%1/2
A
A= $r->{"winner"}
Truth table50%1/2
A
A= $r->{"winner"}
Truth table50%1/2
A
A= $r->{"loser"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||
| 888 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||