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