| 1 | package Game::Schnapsen::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Game::Schnapsen (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Game::Schnapsen::Bot (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Game::Schnapsen::Card qw(rank_of suit_of points_of name_of id_of long_name_of); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Game::Schnapsen::Declare qw(marriages_in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Game::Schnapsen::Variant (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | our %FRAME = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | plain => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | wide => [ "\x{250C}", "\x{2510}", "\x{2514}", "\x{2518}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | "\x{2500}", "\x{2502}" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ascii => [ '+', '+', '+', '+', '-', '|' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | fresh => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | wide => [ "\x{2554}", "\x{2557}", "\x{255A}", "\x{255D}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | "\x{2550}", "\x{2551}" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ascii => [ '#', '#', '#', '#', '=', '#' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | cursor => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | wide => [ "\x{250F}", "\x{2513}", "\x{2517}", "\x{251B}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | "\x{2501}", "\x{2503}" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ascii => [ '+', '+', '+', '+', '=', '!' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | our %MARK_INK = (fresh => '1;32', cursor => '1;7'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | our %RANK_TEXT = (T => '10'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | my %SUIT = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | S => { wide => "\x{2660}", ascii => 'S', colour => '37' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | H => { wide => "\x{2665}", ascii => 'H', colour => '31' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | D => { wide => "\x{2666}", ascii => 'D', colour => '31' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | C => { wide => "\x{2663}", ascii => 'C', colour => '37' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | has game => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | has out => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | has in => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | has mode => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | has level => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | has seat => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | has variant => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | has ascii => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | has colour => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | has _painting => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 42 | ▶ | has marks => (is => 'rw', isa => HashRef, default => sub { {} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | has raw => (is => 'rw', isa => Any, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | has keysource => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 42 | ▶ | has pending => (is => 'rw', isa => ArrayRef, default => sub { [] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | has quit => (is => 'rw', isa => Any, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 5 | has _picking => (is => 'rw', isa => Any, init_arg => 'picking'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | has _staring => (is => 'rw', isa => Any, init_arg => 'interactive'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | our %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 'A' => 'up', 'B' => 'down', 'C' => 'right', 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 'H' => 'home', 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | '1~' => 'home', '4~' => 'end', '5~' => 'page_up', '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | '7~' => 'home', '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | our %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | "\r" => 'enter', "\n" => 'enter', "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | "\x7f" => 'backspace', "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | "\x03" => 'interrupt', "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1123 | ▶ | sub _out { return $_[0]->out || \*STDOUT } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_out: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->out || \*STDOUT
MC/DC100%1/1
$_[0]->out || \*STDOUT
$_[0]->out
Truth table100%2/2
A
A= $_[0]->out
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 22 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 984 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 576 | ▶ | sub _level { return $_[0]->level || 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_level: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->level || 2
MC/DC100%1/1
$_[0]->level || 2
$_[0]->level
Truth table100%2/2
A
A= $_[0]->level
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1298 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 944 | ▶ | sub _ascii { return $_[0]->ascii ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ascii: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 60 | ▶ | sub other { return $_[0] eq 'p1' ? 'p2' : 'p1' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
other: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 42 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 42 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 42 | ▶ | binmode $self->_out, ':encoding(UTF-8)' unless $self->_ascii; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 42 | my $previous = select $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 42 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 42 | select $previous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 42 | ▶ | die 'Game::Schnapsen::Terminal: the level is 1 to ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_level >= 1 and $self->_level <= "Game::Schnapsen::Bot"->levels
MC/DC50%1/2
$self->_level >= 1 and $self->_level <= "Game::Schnapsen::Bot"->levels
$self->_level >= 1
$self->_level <= "Game::Schnapsen::Bot"->levels
Truth table66%2/3
A and B
A= $self->_level >= 1B= $self->_level <= "Game::Schnapsen::Bot"->levels
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | . Game::Schnapsen::Bot->levels . ', not ' . $self->_level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | unless $self->_level >= 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | && $self->_level <= Game::Schnapsen::Bot->levels; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 41 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1343 | ▶ | sub _colour { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colour: called CC=6 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1343 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1343 | my $on = $self->_painting; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1343 | ▶ | return $on if defined $on; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | $on = defined $self->colour ? ($self->colour ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 25 | ▶ | : ((eval { -t $self->_out } && !$ENV{NO_COLOR}) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/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 table0%0/3
A and not(B)
A= eval {
do {
-t $self->_out
}
}B= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 25 | $self->_painting($on); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 25 | return $on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1342 | ▶ | sub paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paint: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1342 | my ($self, $text, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1342 | ▶ | return $text unless $self->_colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return "\e[${code}m" . $text . "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1068 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | ▶ | sub ask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ask: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 13 | my ($self, $prompt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 13 | my $fh = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 13 | print {$fh} $prompt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | my $in = $self->_in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 13 | my $line = <$in>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 13 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | print {$fh} "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 10 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 764 | ▶ | sub rank_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rank_text: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 764 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 764 | my $rank = rank_of($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 764 | ▶ | return $RANK_TEXT{$rank} // $rank; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Game::Schnapsen::Terminal::RANK_TEXT{$rank} // $rank
MC/DC0%0/2
$Game::Schnapsen::Terminal::RANK_TEXT{$rank} // $rank
$Game::Schnapsen::Terminal::RANK_TEXT{$rank}
$rank
Truth table66%2/3
A // B
A= $Game::Schnapsen::Terminal::RANK_TEXT{$rank}B= $rank
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 650 | ▶ | sub plain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plain: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 650 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 650 | ▶ | return '-' unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 650 | my $suit = $SUIT{ suit_of($id) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 650 | ▶ | return $self->rank_text($id) . $suit->{ $self->_ascii ? 'ascii' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 539 | ▶ | sub pretty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pretty: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 539 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 539 | ▶ | return '-' unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 538 | return $self->paint($self->plain($id), $SUIT{ suit_of($id) }{colour}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 113 | ▶ | sub _card_rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_card_rows: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 113 | my ($self, $id, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 113 | my $rank = $self->rank_text($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 113 | my $suit = $SUIT{ suit_of($id) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 113 | ▶ | my $pip = $suit->{ $self->_ascii ? 'ascii' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 113 | ▶ | my $style = $mark && $FRAME{$mark} ? $mark : 'plain'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mark and $Game::Schnapsen::Terminal::FRAME{$mark}
MC/DC50%1/2
$mark and $Game::Schnapsen::Terminal::FRAME{$mark}
$mark
$Game::Schnapsen::Terminal::FRAME{$mark}
Truth table66%2/3
A and B
A= $markB= $Game::Schnapsen::Terminal::FRAME{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | my ($tl, $tr, $bl, $br, $h, $v) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 113 | ▶ | = @{ $FRAME{$style}{ $self->_ascii ? 'ascii' : 'wide' } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | return ([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | $tl . ($h x 7) . $tr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $v . sprintf('%-7s', $rank) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $v . (' ' x 7) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | $v . ' ' . $pip . ' ' . $v, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | $v . (' ' x 7) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | $v . sprintf('%7s', $rank) . $v, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | $bl . ($h x 7) . $br, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 113 | ], $suit->{colour}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 113 | ▶ | sub card_art { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_art: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 113 | my ($self, $id, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 113 | my ($rows, $colour) = $self->_card_rows($id, $mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 113 | ▶ | my $ink = $mark && $MARK_INK{$mark} ? $MARK_INK{$mark} : $colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mark and $Game::Schnapsen::Terminal::MARK_INK{$mark}
MC/DC50%1/2
$mark and $Game::Schnapsen::Terminal::MARK_INK{$mark}
$mark
$Game::Schnapsen::Terminal::MARK_INK{$mark}
Truth table66%2/3
A and B
A= $markB= $Game::Schnapsen::Terminal::MARK_INK{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 113 | return [ map { $self->paint($_, $ink) } @$rows ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | sub card_back { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_back: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | my ($tl, $tr, $bl, $br, $h, $v, $fill) = $self->_ascii | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ? ('+', '+', '+', '+', '-', '|', '#') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | : ("\x{250C}", "\x{2510}", "\x{2514}", "\x{2518}", "\x{2500}", "\x{2502}", "\x{2592}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 7 | return [ map { $self->paint($_, '90') } ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | $tl . ($h x 7) . $tr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | (map { $v . ($fill x 7) . $v } 1 .. 5), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | $bl . ($h x 7) . $br, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 23 | ▶ | sub fan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fan: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 23 | my ($self, $cards, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 23 | ▶ | return [ ('') x 7 ] unless @$cards; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 23 | ▶ | $marks ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$marks ||= {}
MC/DC100%1/1
$marks ||= {}
$marks
Truth table100%2/2
A
A= $marks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 23 | my @rows = ('') x 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 23 | for my $i (0 .. $#$cards) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 112 | my $art = $self->card_art($cards->[$i], $marks->{ $cards->[$i] }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 112 | $rows[$_] .= $art->[$_] . ' ' for 0 .. 6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 23 | s/\s+\z// for @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 23 | return \@rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 27 | ▶ | sub score_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
score_line: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 27 | my $g = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 27 | my $v = $g->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 27 | my $up = Game::Schnapsen::Variant::match_direction($v) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 27 | my $s = $g->scores; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | return sprintf('%s you %d them %d (%s, %s)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | $up ? 'Game points' : 'Game points left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 27 | ▶ | $s->{ $self->_seat }, $s->{ other($self->_seat) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | $up ? 'first to 7' : 'down to zero', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | $v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 25 | ▶ | sub table_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_lines: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 25 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 25 | my $g = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 25 | my $d = $g->deal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 25 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | push @out, sprintf('Deal %d trump %s talon %d%s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | $g->number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 25 | ▶ | $SUIT{ $d->trump }{ $self->_ascii ? 'ascii' : 'wide' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | $d->talon_left, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $d->closed ? ' (closed)' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 25 | push @out, sprintf('Card points you %d them %d', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $d->points_of($seat), $d->points_of(other($seat))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 25 | ▶ | if (defined $d->turn_up && !$d->closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $d->turn_up and not $d->closed
MC/DC50%1/2
defined $d->turn_up and not $d->closed
defined $d->turn_up
not $d->closed
Truth table66%2/3
A and not(B)
A= defined $d->turn_upB= not $d->closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 23 | push @out, 'Turn-up: ' . $self->pretty($d->turn_up); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 25 | ▶ | if (defined $d->lead) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 5 | push @out, 'Led: ' . $self->pretty($d->lead); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | elsif (my $t = $d->last_trick) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | push @out, sprintf('Last trick: %s and %s to %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | $self->pretty($t->{lead}), $self->pretty($t->{follow}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | ▶ | $t->{winner} eq $seat ? 'you' : 'them'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 25 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 22 | ▶ | sub hand_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_lines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 22 | my ($self, $seat, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 22 | my $d = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 22 | my $cards = $d->hand_of($seat)->sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 22 | ▶ | my @out = @{ $self->fan($cards, $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | my $labels = join ' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 22 | my $pad = 7 - length $self->plain($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 111 | ▶ | $self->pretty($_) . ' ' x ($pad > 0 ? $pad : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } @$cards; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 22 | $labels =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 22 | push @out, $labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 22 | my $m = marriages_in($cards, $d->trump); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 22 | ▶ | push @out, 'Marriages: ' . join(', ', map { $_->{suit} . ' for ' . $_->{value} } @$m) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | if @$m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 22 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 21 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 21 | my ($self, $seat, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 21 | ▶ | $seat //= $self->_seat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$seat //= $self->_seat
MC/DC0%0/2
$seat //= $self->_seat
$seat
$self->_seat
Truth table33%1/3
A //= B
A= $seatB= $self->_seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 21 | my @out = ('', $self->score_line, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 21 | push @out, @{ $self->table_lines($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 21 | push @out, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 21 | push @out, @{ $self->hand_lines($seat, $marks) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 21 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 13 | ▶ | sub show { my ($self, $seat) = @_; $self->say_to($_) for @{ $self->render($seat) }; return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 497 | ▶ | sub describe { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 497 | my ($self, $move, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 497 | ▶ | my $who = $seat eq $self->_seat ? 'You' : 'They'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 497 | my $k = $move->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 497 | ▶ | return "$who led " . $self->pretty($move->{card}) if $k eq 'lead'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 303 | ▶ | return "$who played " . $self->pretty($move->{card}) if $k eq 'follow'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 113 | ▶ | return "$who declared a marriage in $move->{suit}" if $k eq 'marriage'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 87 | ▶ | return "$who exchanged for the trump card" if $k eq 'exchange'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 70 | ▶ | return "$who closed the talon" if $k eq 'close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 62 | ▶ | return "$who claimed 66" if $k eq 'claim'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 37 | ▶ | return "$who drew" if $k eq 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return "$who did something"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 15 | ▶ | sub card_named { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_named: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 15 | my ($self, $text, $cards) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 15 | ▶ | return undef unless defined $text && length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and length $text
MC/DC50%1/2
defined $text and length $text
defined $text
length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 14 | (my $want = uc $text) =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 14 | $want =~ s/\A10/T/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 14 | for my $card (@$cards) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 29 | ▶ | return $card if uc(name_of($card)) eq $want; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $legal = $self->game->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my @kinds = grep { !$seen{$_}++ } map { $_->{kind} } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return \@kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 984 | ▶ | sub is_human { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_human: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 984 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 984 | my $mode = $self->_mode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 984 | ▶ | return 0 if $mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 10 | ▶ | return 1 if $mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 10 | ▶ | return $seat eq $self->_seat ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 491 | ▶ | sub bot_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot_move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 491 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 491 | my $bot = Game::Schnapsen::Bot->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | level => $self->_level, seed => $self->game->seed . $seat); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 491 | return $bot->choose($self->game, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 6 | ▶ | sub interactive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=4 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 6 | my $want = $self->_staring; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 6 | ▶ | return $want ? 1 : 0 if defined $want; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | return (eval { -t $self->_out }) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 11 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 11 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 11 | ▶ | $self->_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 11 | ▶ | return $self->_picking ? 1 : 0 if defined $self->_picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 9 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=4 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 9 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 9 | ▶ | return 0 unless eval { -t $self->_in }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 5 | ▶ | if ($self->keysource) { $self->raw(1); return $self } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 2 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->_in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 8 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=3 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->_in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 45 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 45 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 45 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 45 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 43 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->_in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return Term::ReadKey::ReadKey(-1, $self->_in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 25 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 25 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 25 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 24 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 18 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 8 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 10 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 10 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 10 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 10 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 8 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 8 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 10 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 10 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 10 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 10 | ▶ | last if $char =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 8 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Schnapsen::Terminal::SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$Game::Schnapsen::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Schnapsen::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Schnapsen::Terminal::SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 6 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=10.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | ▶ | return $self unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $fh = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | print {$fh} "\e[2J\e[3J\e[H"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 492 | ▶ | sub remember { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remember: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 492 | my ($self, $seat, $held) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 492 | ▶ | my $hand = eval { $self->game->deal->hand_of($seat) } or return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 492 | my %mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 492 | for my $card (@{ $hand->sorted }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 2245 | ▶ | $mark{$card} = 'fresh' unless $held->{$card}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 492 | $self->marks(\%mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 492 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 7 | ▶ | sub card_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_line: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 7 | my ($self, $seat, $card) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 7 | my $d = $self->game->deal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 7 | my $name = $self->pretty($card); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 7 | my $lead = $d->lead; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 7 | ▶ | return "$name: you lead it" unless defined $lead; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | my $winner = Game::Schnapsen::Trick::winner_of($lead, $card, $d->trump); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my $worth = Game::Schnapsen::Trick::value_of($lead, $card); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | my $mine = $d->points_of($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | ▶ | return sprintf '%s: %s the trick, %d %s%s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ($winner == $card ? 'takes' : 'loses'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | $worth, ($worth == 1 ? 'point' : 'points'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ($winner == $card | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | ? sprintf(', which puts you on %d', $mine + $worth) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | sub pick_help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | 'left and right walk your hand, enter plays the card under the cursor.', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 'the line under it says what that card would do to the trick.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 'x exchanges, c closes, m declares a marriage, o claims 66, d draws.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 't goes back to typing, q stops.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 5 | my %SPECIAL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | x => 'exchange', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | c => 'close', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | o => 'claim', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | d => 'draw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 3 | ▶ | sub pick_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_move: called CC=33 SCAR=45.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 3 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | my $g = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 3 | my $legal = $g->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 3 | ▶ | return undef unless @$legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 3 | my %by; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | push @{ $by{ $_->{kind} } }, $_ for @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 15 | my @cards = map { $_->{card} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 3 | grep { defined $_->{card} } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 3 | my %playable = map { $_ => 1 } @cards; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 3 | my @order = grep { $playable{$_} } @{ $g->deal->hand_of($seat)->sorted }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 3 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 3 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 6 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 6 | ▶ | my %mark = (%{ $self->marks }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | @order ? ($order[$at] => 'cursor') : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 6 | $self->say_to($_) for @{ $self->render($seat, \%mark) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 6 | ▶ | $self->say_to(' ' . $self->card_line($seat, $order[$at])) if @order; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 6 | my $offers = $self->_offers(\%by); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 6 | ▶ | $self->say_to(' ' . $offers) if length $offers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 6 | $self->say_to(' ' . $_) for @notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 6 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 6 | $self->say_to(' ' . $self->paint( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 'arrows to choose, enter to play, ? for the keys', '90')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 6 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 6 | ▶ | if (!defined $key || $key eq 'eof' || $key eq 'interrupt' || $key eq 'q') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q"
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC25%1/4
not defined $key or $key eq "eof" or $key eq "interrupt" or $key eq "q"
not defined $key
$key eq "eof"
$key eq "interrupt"
$key eq "q"
Truth table40%2/5
not(A) or B or C or D
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"D= $key eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | $self->quit(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 4 | ▶ | if (@order && ($key eq 'left' || $key eq 'up')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@order and $key eq "left" || $key eq "up"
$key eq "left" or $key eq "up"
MC/DC0%0/3
@order and $key eq "left" || $key eq "up"
@order
$key eq "left"
$key eq "up"
Truth table25%1/4
A and B or C
A= @orderB= $key eq "left"C= $key eq "up"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $at = ($at - 1) % @order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 4 | ▶ | if (@order && ($key eq 'right' || $key eq 'down' || $key eq 'tab')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
@order and $key eq "right" || $key eq "down" || $key eq "tab"
$key eq "right" or $key eq "down" or $key eq "tab"
$key eq "right" or $key eq "down"
MC/DC25%1/4
@order and $key eq "right" || $key eq "down" || $key eq "tab"
@order
$key eq "right"
$key eq "down"
$key eq "tab"
Truth table40%2/5
A and B or C or D
A= @orderB= $key eq "right"C= $key eq "down"D= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | $at = ($at + 1) % @order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 3 | ▶ | if (@order && ($key eq 'enter' || $key eq ' ')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@order and $key eq "enter" || $key eq " "
$key eq "enter" or $key eq " "
MC/DC33%1/3
@order and $key eq "enter" || $key eq " "
@order
$key eq "enter"
$key eq " "
Truth table50%2/4
A and B or C
A= @orderB= $key eq "enter"C= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | ▶ | my ($pick) = grep { defined $_->{card} && $_->{card} == $order[$at] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $_->{'card'} && $_->{'card'} == $order[$at]
MC/DC100%2/2
defined $_->{'card'} && $_->{'card'} == $order[$at]
defined $_->{'card'}
$_->{'card'} == $order[$at]
Truth table100%3/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $order[$at]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | @$legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | ▶ | return $pick if $pick; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | @notice = ('you cannot play that one'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 2 | ▶ | if (my $kind = $SPECIAL{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | ▶ | return $by{$kind}[0] if $by{$kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 1 | @notice = ("you cannot $kind here"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | ▶ | if ($key eq 'm') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | if (my $m = $by{marriage}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | return $m->[0] if @$m == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | @notice = ('which marriage? ' . join(' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | map { lc $_->{suit} } @$m) . ' as a letter'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $suit = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | my ($pick) = grep { lc $_->{suit} eq lc($suit // '') } @$m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$suit // ""
MC/DC0%0/1
$suit // ""
$suit
Truth table0%0/2
A
A= $suit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | return $pick if $pick; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | @notice = ('you do not hold that marriage'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | @notice = ('you have no marriage to declare'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | ▶ | if ($key eq 't') { $self->picking(0); return $self->typed_move($seat) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | ▶ | if ($key eq '?') { @notice = $self->pick_help; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | @notice = ('that key does nothing here. ? for the ones that do'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 6 | ▶ | sub _offers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_offers: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 6 | my ($self, $by) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 6 | my @say; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 6 | ▶ | push @say, 'x exchange' if $by->{exchange}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 6 | ▶ | push @say, 'c close' if $by->{close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 6 | ▶ | push @say, 'm marriage' if $by->{marriage}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 6 | ▶ | push @say, 'o claim 66' if $by->{claim}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 6 | ▶ | push @say, 'd draw' if $by->{draw}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 6 | ▶ | return @say ? 'also: ' . join(' ', @say) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 8 | ▶ | sub human_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
human_move: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 8 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 8 | ▶ | if ($self->picking) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | ▶ | return $self->pick_move($seat) if $self->enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 8 | return $self->typed_move($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 8 | ▶ | sub typed_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
typed_move: called CC=18 SCAR=34.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 8 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 8 | my $g = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 8 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 13 | my $legal = $g->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 13 | ▶ | return undef unless @$legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 13 | my %by; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 13 | push @{ $by{ $_->{kind} } }, $_ for @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 13 | my @words = sort keys %by; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 13 | $self->show($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 13 | my $line = $self->ask('> '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 13 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 10 | $line =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 10 | ▶ | if ($line =~ /\A(?:\?|h|help)\z/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 2 | $self->say_to('You may: ' . join(', ', @words)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 2 | $self->say_to('Name a card to play it (KH, 10H, TH). Or: ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | . 'm SUIT to declare a marriage, x to exchange, ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | . 'c to close, out to claim 66, d to draw.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 8 | ▶ | if ($line =~ /\Am\s*([SHDC])\z/i && $by{marriage}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /\Am\s*([SHDC])\z/i and $by{"marriage"}
MC/DC0%0/2
$line =~ /\Am\s*([SHDC])\z/i and $by{"marriage"}
$line =~ /\Am\s*([SHDC])\z/i
$by{"marriage"}
Truth table33%1/3
A and B
A= $line =~ /\Am\s*([SHDC])\z/iB= $by{"marriage"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my $suit = uc $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | my ($pick) = grep { $_->{suit} eq $suit } @{ $by{marriage} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | return $pick if $pick; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | $self->say_to('You do not hold that marriage.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 8 | ▶ | if ($line =~ /\A(?:x|exchange)\z/i && $by{exchange}) { return $by{exchange}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /\A(?:x|exchange)\z/i and $by{"exchange"}
MC/DC0%0/2
$line =~ /\A(?:x|exchange)\z/i and $by{"exchange"}
$line =~ /\A(?:x|exchange)\z/i
$by{"exchange"}
Truth table33%1/3
A and B
A= $line =~ /\A(?:x|exchange)\z/iB= $by{"exchange"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 8 | ▶ | if ($line =~ /\A(?:c|close)\z/i && $by{close}) { return $by{close}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /\A(?:c|close)\z/i and $by{"close"}
MC/DC0%0/2
$line =~ /\A(?:c|close)\z/i and $by{"close"}
$line =~ /\A(?:c|close)\z/i
$by{"close"}
Truth table33%1/3
A and B
A= $line =~ /\A(?:c|close)\z/iB= $by{"close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 8 | ▶ | if ($line =~ /\A(?:out|claim|66)\z/i && $by{claim}) { return $by{claim}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line =~ /\A(?:out|claim|66)\z/i and $by{"claim"}
MC/DC50%1/2
$line =~ /\A(?:out|claim|66)\z/i and $by{"claim"}
$line =~ /\A(?:out|claim|66)\z/i
$by{"claim"}
Truth table66%2/3
A and B
A= $line =~ /\A(?:out|claim|66)\z/iB= $by{"claim"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 5 | ▶ | if ($line =~ /\A(?:d|draw)\z/i && $by{draw}) { return $by{draw}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /\A(?:d|draw)\z/i and $by{"draw"}
MC/DC0%0/2
$line =~ /\A(?:d|draw)\z/i and $by{"draw"}
$line =~ /\A(?:d|draw)\z/i
$by{"draw"}
Truth table33%1/3
A and B
A= $line =~ /\A(?:d|draw)\z/iB= $by{"draw"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 5 | my @playable = grep { defined $_->{card} } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 5 | my $card = $self->card_named($line, [ map { $_->{card} } @playable ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 5 | ▶ | if (defined $card) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | my ($pick) = grep { $_->{card} == $card } @playable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | ▶ | return $pick if $pick; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 3 | $self->say_to("I did not follow that. You may: " . join(', ', @words) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | . '. Type ? for help.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 733 | ▶ | sub announce { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
announce: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 733 | my ($self, $event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 733 | my $k = $event->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 733 | ▶ | if ($k eq 'trick') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 190 | ▶ | return $self->say_to(' ' . ($event->{winner} eq $self->_seat ? 'You take it.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | : 'They take it.')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 543 | ▶ | if ($k eq 'deal_end') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 26 | return $self->say_to($self->deal_result_line($event)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 517 | ▶ | if ($k eq 'deal') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 22 | return $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 495 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 33 | ▶ | sub deal_result_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deal_result_line: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 33 | my ($self, $r) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 33 | ▶ | return 'The deal is drawn. Nobody scores, and it is dealt again.' if $r->{drawn}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 32 | ▶ | my $who = ($r->{winner} // '') eq $self->_seat ? 'You win' : 'They win'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$r->{"winner"} // ""
MC/DC0%0/1
$r->{"winner"} // ""
$r->{"winner"}
Truth table50%1/2
A
A= $r->{"winner"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 32 | my %how = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | claim => 'the deal, claiming 66', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | closed_out => 'the deal, having closed the talon', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | false_claim => 'the deal: the claim was false', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | beat_closer => 'the deal, beating the closer to it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | failed_close => 'the deal: the close failed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | last_trick => 'the deal on the last trick', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | return sprintf('%s %s, for %d game point%s.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | $who, $how{ $r->{how} } // 'the deal', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 32 | ▶ | $r->{game_points}, $r->{game_points} == 1 ? '' : 's'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$how{$r->{"how"}} // "the deal"
MC/DC0%0/1
$how{$r->{"how"}} // "the deal"
$how{$r->{"how"}}
Truth table50%1/2
A
A= $how{$r->{"how"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 8 | ▶ | sub result_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_line: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 8 | my $g = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 8 | ▶ | my $r = $g->result or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 8 | my $s = $g->scores; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 8 | my $mine = $s->{ $self->_seat }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 8 | my $theirs = $s->{ other($self->_seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 8 | my $won = $r->{winner} eq $self->_seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | return sprintf('%s the match, %d to %d, over %d deals.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | $won ? 'You win' : 'They win', $mine, $theirs, $r->{deals}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 8 | ▶ | if Game::Schnapsen::Variant::match_direction($g->variant) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | return sprintf('%s the match over %d deals, with %d still to find %s.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | $won ? 'You win' : 'They win', $r->{deals}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 5 | ▶ | $won ? $theirs : $mine, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | $won ? 'against you' : 'from you'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 8 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=17 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 8 | my ($self, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 8 | ▶ | my $seed = $o{seed} // Digest::SHA::sha256(join ':', $$, time, rand); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$o{"seed"} // &Digest::SHA::sha256(join(":", $$, time, rand))
MC/DC0%0/2
$o{"seed"} // &Digest::SHA::sha256(join(":", $$, time, rand))
$o{"seed"}
&Digest::SHA::sha256(join(":", $$, time, rand))
Truth table33%1/3
A // B
A= $o{"seed"}B= &Digest::SHA::sha256(join(":", $$, time, rand))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 8 | ▶ | my $variant = $o{variant} // $self->variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$o{"variant"} // $self->variant
MC/DC50%1/2
$o{"variant"} // $self->variant
$o{"variant"}
$self->variant
Truth table66%2/3
A // B
A= $o{"variant"}B= $self->variant
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 8 | my $bad = Game::Schnapsen::Variant::check_variant($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 8 | ▶ | if ($bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 2 | $self->say_to('Cannot start: ' . $bad->message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | . ' (schnapsen or sixtysix, and there is no default)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 2 | return $bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | my $g = Game::Schnapsen->build( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | variant => $variant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | seed => $seed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 6 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 6 | ▶ | if (ref $g eq 'Game::Schnapsen::Error') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | $self->say_to('Cannot start: ' . $g->message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | return $g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 6 | $self->game($g); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 6 | my $guard = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 6 | ▶ | while (!$g->over && !$self->quit && $guard++ < 10_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $g->over || $self->quit and $guard++ < 10000
$g->over || $self->quit
MC/DC33%1/3
not $g->over || $self->quit and $guard++ < 10000
$g->over
$self->quit
$guard++ < 10000
Truth table50%2/4
not(A || B) and C
A= $g->overB= $self->quitC= $guard++ < 10000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 493 | ▶ | my $seat = $g->turn or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 493 | ▶ | my $move = $self->is_human($seat) ? $self->human_move($seat) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | : $self->bot_move($seat); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 493 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 491 | ▶ | $self->say_to($self->describe($move, $seat)) unless $self->is_human($seat); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 491 | my $mine = $self->_seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 491 | my %held = eval { map { $_ => 1 } @{ $g->deal->hand_of($mine)->sorted } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 491 | my @out = $g->apply($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 491 | ▶ | if (@out == 1 && ref $out[0] eq 'Game::Schnapsen::Error') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@out == 1 and ref $out[0] eq "Game::Schnapsen::Error"
MC/DC0%0/2
@out == 1 and ref $out[0] eq "Game::Schnapsen::Error"
@out == 1
ref $out[0] eq "Game::Schnapsen::Error"
Truth table66%2/3
A and B
A= @out == 1B= ref $out[0] eq "Game::Schnapsen::Error"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | $self->say_to($out[0]->message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 491 | $self->remember($mine, \%held); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 491 | $self->announce($_) for @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 6 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 6 | $self->say_to(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 6 | ▶ | $self->say_to($self->result_line) if $g->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 6 | return $g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 2 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 2 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | schnapsen - Schnapsen and Sixty-Six at a prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | schnapsen --variant schnapsen the Austrian game, 20 cards, 7 down to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | schnapsen --variant sixtysix the German parent, 24 cards, 0 up to 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | --seat p2 play the bot as p2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | --mode hotseat two people at one keyboard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | --mode watch two bots, and you read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | --level 1 a weaker opponent (1 or 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | --seed tuesday deal the same match every time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | --ascii letters instead of the suit pips | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | --nocolour no colour (NO_COLOR does the same) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | --nopick type the cards out instead of pointing at them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | --variant has no default, because the two are different games and picking one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | silently would make the other an afterthought. They differ in thirteen places: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | the pack, the card that exchanges for the trump, whether a marriage may be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | declared late, what the last trick is worth, which way the score runs, and more. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | At the prompt, name a card to play it: KH, TH, or 10H for the same card. Then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | m H declare a marriage in hearts, and lead one of the two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | x exchange your lowest trump for the turn-up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | c close the talon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | out claim 66 and end the deal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | d draw (sixtysix, where you may close before drawing instead) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | ? what is legal right now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | Claiming is typed in full. A claim that turns out to be false loses the deal, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | the screen already shows you your own count, so it is not put a keystroke away | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | from anything else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | On a terminal the left and right keys walk your own hand instead, and the line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | under it says what the card under the cursor would do to the trick: whether it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | takes it, what the trick is worth, and what that puts you on. Enter plays it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | The moves that are not cards keep their own keys, x c m o d, because a card is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | a thing in your hand and those are not. t goes back to typing, ? lists the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | keys. Needs Term::ReadKey; without it the cards are typed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | The card you drew at the end of the last trick is drawn in a heavier frame, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | you can see what is new without counting the hand. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | Exit status is 0 if you won, or if nobody was playing a seat, 1 if you lost or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | stopped early, and 2 for an option the game will not take. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 4 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=25 SCAR=42.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 4 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 4 | my %o = (mode => 'bot', level => 2, seat => 'p1'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 4 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 4 | ▶ | local $SIG{__WARN__} = sub { print STDERR "schnapsen: $_[0]" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | Getopt::Long::GetOptionsFromArray(\@argv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 'variant=s' => \$o{variant}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 'mode=s' => \$o{mode}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 'level=i' => \$o{level}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 'seat=s' => \$o{seat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 'seed=s' => \$o{seed}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 'ascii' => \$o{ascii}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 'pick!' => \$o{pick}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 'colour!' => \$o{colour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 'color!' => \$o{colour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 'help' => \$o{help}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 4 | ▶ | if (!$ok) { print STDERR _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 4 | ▶ | if ($o{help}) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 3 | ▶ | if (@argv) { print STDERR "schnapsen: not an option: $argv[0]\n", _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | my $levels = Game::Schnapsen::Bot->levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | my $refused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | = !(defined $o{variant} && $o{variant} =~ /\A(?:schnapsen|sixtysix)\z/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | ? '--variant must be schnapsen or sixtysix' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | : $o{mode} !~ /\A(?:bot|hotseat|watch)\z/ ? 'mode must be bot, hotseat or watch' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | : $o{seat} !~ /\A p[12] \z/x ? 'seat must be p1 or p2' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 3 | ▶ | : !($o{level} =~ /\A\d+\z/ && $o{level} >= 1 && $o{level} <= $levels) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition44%4/9
defined $o{'variant'} && $o{'variant'} =~ /\A(?:schnapsen|sixtysix)\z/
$o{'level'} =~ /\A\d+\z/ && $o{'level'} >= 1 && $o{'level'} <= $levels
$o{"level"} =~ /\A\d+\z/ and $o{"level"} >= 1
MC/DC50%1/2
defined $o{'variant'} && $o{'variant'} =~ /\A(?:schnapsen|sixtysix)\z/
defined $o{'variant'}
$o{'variant'} =~ /\A(?:schnapsen|sixtysix)\z/
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 table66%2/3
A && B
A= defined $o{'variant'}B= $o{'variant'} =~ /\A(?:schnapsen|sixtysix)\z/
Truth table25%1/4
A and B && C
A= $o{"level"} =~ /\A\d+\z/B= $o{"level"} >= 1C= $o{'level'} <= $levels
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | ? "level must be 1 to $levels" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 3 | ▶ | if (defined $refused) { print STDERR "schnapsen: $refused\n", _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 2 | ▶ | my $seed = defined $o{seed} ? Digest::SHA::sha256($o{seed}) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | my $ui = $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | variant => $o{variant}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | mode => $o{mode}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | level => $o{level}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | seat => $o{seat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | ($o{ascii} ? (ascii => 1) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | (defined $o{colour} ? (colour => $o{colour}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 2 | ▶ | (defined $o{pick} ? (picking => $o{pick} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 2 | local @SIG{qw(INT TERM HUP)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 2 | for my $sig (qw(INT TERM HUP)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 6 | ▶ | $SIG{$sig} = sub { $ui->leave_raw; $SIG{$sig} = 'DEFAULT'; kill $sig, $$ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 2 | ▶ | my $game = eval { $ui->play(defined $seed ? (seed => $seed) : ()) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 2 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 2 | $ui->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 2 | ▶ | die $died if $died; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 2 | ▶ | return 1 unless ref $game && $game->over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $game and $game->over
MC/DC0%0/2
ref $game and $game->over
ref $game
$game->over
Truth table33%1/3
A and B
A= ref $gameB= $game->over
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 2 | ▶ | return 0 if $o{mode} ne 'bot'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | ▶ | return 0 if ($game->winner // '') eq $o{seat}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$game->winner // ""
MC/DC0%0/1
$game->winner // ""
$game->winner
Truth table0%0/2
A
A= $game->winner
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||