| 1 | package Game::Durak::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 Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Game::Durak (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Game::Durak::Bot (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Game::Durak::Card qw(name_of long_name_of suit_of rank_of face_of); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Game::Durak::Table (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | my %SUIT = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | S => { wide => "\x{2660}", ascii => 'S', colour => '37' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | H => { wide => "\x{2665}", ascii => 'H', colour => '31' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | D => { wide => "\x{2666}", ascii => 'D', colour => '31' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | C => { wide => "\x{2663}", ascii => 'C', colour => '37' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | my %SAID = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | attack => 'attack with', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | beat => 'beat it with', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | take => 'take the bout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | done => 'are done', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | swap => 'exchange the trump six', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | resign => 'give up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | has game => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | has out => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | has in => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | has seed => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | has level => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | has seat => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | has ascii => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | has colour => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | has paint => (is => 'ro', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | has width => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | has height => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | has _painting => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | has raw => (is => 'rw', isa => Any, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | has keysource => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | ▶ | has pending => (is => 'rw', isa => ArrayRef, default => sub { [] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | has _picking => (is => 'rw', isa => Any, init_arg => 'picking'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | our %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'A' => 'up', 'B' => 'down', 'C' => 'right', 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 'H' => 'home', 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | '1~' => 'home', '4~' => 'end', '5~' => 'page_up', '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | '7~' => 'home', '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | our %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | "\r" => 'enter', "\n" => 'enter', "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | "\x7f" => 'backspace', "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | "\x03" => 'interrupt', "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | has _table => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | has _said => (is => 'rw', isa => Any); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 373 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 84 | ▶ | sub _in { return $_[0]->in || \*STDIN } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->in || \*STDIN
MC/DC100%1/1
$_[0]->in || \*STDIN
$_[0]->in
Truth table100%2/2
A
A= $_[0]->in
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | sub _level { return defined $_[0]->level ? $_[0]->level : 3 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_level: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | sub _seat { return defined $_[0]->seat ? $_[0]->seat : 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seat: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1239 | ▶ | sub _ascii { return $_[0]->ascii ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ascii: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _them { return 3 - $_[0]->_seat } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_them: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 16 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | ▶ | binmode $self->_out, ':encoding(UTF-8)' unless $self->_ascii; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | my $previous = select $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 16 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | select $previous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1417 | ▶ | sub _colour { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colour: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1417 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1417 | my $on = $self->_painting; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1417 | ▶ | return $on if defined $on; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | $on = defined $self->colour ? ($self->colour ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 11 | ▶ | : ((eval { -t $self->_out } && !$ENV{NO_COLOR}) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
eval {
do {
-t $self->_out
}
} and not $ENV{"NO_COLOR"}
MC/DC0%0/2
eval {
do {
-t $self->_out
}
} and not $ENV{"NO_COLOR"}
eval {
do {
-t $self->_out
}
}
not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= eval {
do {
-t $self->_out
}
}B= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 11 | $self->_painting($on); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | return $on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 214 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 214 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 214 | ▶ | return $self->paint ? 1 : 0 if defined $self->paint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 193 | return $self->_colour; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub table_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_of: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $table = $self->_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return $table if $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $table = Game::Durak::Table->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$self->width || 80
$self->height || 24
MC/DC0%0/1
$self->width || 80
$self->width
MC/DC0%0/1
$self->height || 24
$self->height
Truth table0%0/2
A
A= $self->width
Truth table0%0/2
A
A= $self->height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | width => $self->width || 80, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | height => $self->height || 24, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ascii => $self->ascii, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->_table($table); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return $table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub frame { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frame: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $view, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $table = $self->table_of; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $grid = $table->screen($view, %o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return $self->_colour ? $table->paint($grid) : $table->lines($grid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub headline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headline: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my ($self, $room) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my @said = @{ $self->_said || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_said || []
MC/DC0%0/1
$self->_said || []
$self->_said
Truth table0%0/2
A
A= $self->_said
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return '' unless @said; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | while (@said) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $next = pop @said; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $grown = length $line ? "$next, $line" : $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | last if length $grown > $room; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $line = $grown; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $line = substr((pop @{ $self->_said }), 0, $room) unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my ($self, $view, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $handle = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $table = $self->table_of; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | my $footer = defined $o{footer} ? $o{footer} : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | my $lines = $self->frame($view, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | header => (defined $o{header} ? $o{header} : $self->headline($table->width - 2)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | footer => $footer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | (defined $o{cursor} ? (cursor => $o{cursor}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | print {$handle} "\e[H", join("\n", @$lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | print {$handle} sprintf "\e[%d;%dH", $table->height, length($footer) + 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $self->_said([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 119 | ▶ | sub told { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
told: called CC=5 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 119 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 119 | ▶ | return unless @lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 119 | ▶ | if ($self->_paint) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $said = $self->_said || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_said || []
MC/DC0%0/1
$self->_said || []
$self->_said
Truth table0%0/2
A
A= $self->_said
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | push @$said, @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $self->_said($said); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 119 | $self->say(" $_") for @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 119 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 353 | ▶ | sub say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 353 | my ($self, @what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 353 | my $handle = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 353 | print {$handle} @what, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 353 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1199 | ▶ | sub card { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1199 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1199 | ▶ | return '--' unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1129 | my $suit = suit_of($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | my $face = face_of($id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1129 | ▶ | . ($self->_ascii ? $SUIT{$suit}{ascii} : $SUIT{$suit}{wide}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1129 | ▶ | return $face unless $self->_colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return "\e[$SUIT{$suit}{colour}m$face\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 92 | ▶ | sub hand_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_line: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 92 | my ($self, $hand, $cursor) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 92 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 92 | ▶ | return join ' ', map { ++$n . ') ' . $self->card($_) } @$hand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | unless defined $cursor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | return join ' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 9 | $n++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 40 | ▶ | ($cursor == $n ? '>' : ' ') . $n . ') ' . $self->card($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } @$hand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 90 | ▶ | sub bout_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bout_line: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 90 | my ($self, $bout) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 90 | ▶ | return 'nothing on the table' unless $bout && @{ $bout->{pairs} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$bout and @{$bout->{"pairs"};}
MC/DC50%1/2
$bout and @{$bout->{"pairs"};}
$bout
@{$bout->{"pairs"};}
Truth table66%2/3
A and B
A= $boutB= @{$bout->{"pairs"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | return join ' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | $self->card($_->{attack}) . ' / ' . $self->card($_->{beat}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 82 | } @{ $bout->{pairs} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 89 | ▶ | sub table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 89 | my ($self, $view, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 89 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 89 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | push @lines, sprintf 'trump %s%s talon %d heap %d they hold %d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | $self->card_suit($view->{trump}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | (defined $view->{trump_card} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ? ' (' . $self->card($view->{trump_card}) . ' face up)' : ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $view->{talon}, $view->{discard}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 89 | ▶ | $view->{counts}{ 3 - $view->{seat} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 89 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 89 | push @lines, ' ' . $self->bout_line($view->{bout}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 89 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 89 | push @lines, ' ' . $self->hand_line($view->{hand}, $o{cursor}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 89 | return join "\n", @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 94 | ▶ | sub card_suit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_suit: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 94 | my ($self, $suit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 94 | ▶ | my $face = $self->_ascii ? $SUIT{$suit}{ascii} : $SUIT{$suit}{wide}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 94 | ▶ | return $self->_colour ? "\e[$SUIT{$suit}{colour}m$face\e[0m" : $face; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 89 | ▶ | sub playable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
playable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 89 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 250 | my %card = map { $_->{card} => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 89 | grep { defined $_->{card} } @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 89 | my @at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 89 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 89 | for my $held (@{ $view->{hand} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 920 | $n++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 920 | ▶ | push @at, $n if $card{$held}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 89 | return \@at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 82 | ▶ | sub prompt_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prompt_for: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 82 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 82 | my %kinds = map { $_->{kind} => 1 } @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 82 | my @what; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 82 | my $playable = $self->playable($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 82 | ▶ | push @what, '[' . join(' ', @$playable) . '] a card' if @$playable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 82 | ▶ | push @what, 't take' if $kinds{take}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 82 | ▶ | push @what, 'd done' if $kinds{done}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 82 | ▶ | push @what, 'x exchange' if $kinds{swap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 82 | push @what, 'r resign'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 82 | push @what, 'q quit'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 82 | return join ' ', @what; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=4 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 5 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | ▶ | return 0 unless eval { -t $self->_in }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 159 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 159 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 159 | ▶ | $self->_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 159 | ▶ | return $self->_picking ? 1 : 0 if defined $self->_picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 5 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 5 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | ▶ | if ($self->keysource) { $self->raw(1); return $self } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->_in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=3 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->_in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 51 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 51 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 51 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 51 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 49 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->_in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return Term::ReadKey::ReadKey(-1, $self->_in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 27 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 27 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 27 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 26 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 21 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 12 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 12 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 12 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 12 | ▶ | unless ($opener eq '[' || $opener eq 'O') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opener eq "[" or $opener eq "O"
MC/DC100%2/2
$opener eq "[" or $opener eq "O"
$opener eq "["
$opener eq "O"
Truth table100%3/3
A or B
A= $opener eq "["B= $opener eq "O"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 10 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 10 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 12 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 12 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 12 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 12 | ▶ | last if $char =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 10 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Durak::Terminal::SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$Game::Durak::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Durak::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Durak::Terminal::SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 11 | ▶ | sub card_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
card_line: called CC=10 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 11 | my ($self, $view, $card) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 44 | ▶ | my ($move) = grep { defined $_->{card} && $_->{card} == $card } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $_->{'card'} && $_->{'card'} == $card
MC/DC100%2/2
defined $_->{'card'} && $_->{'card'} == $card
defined $_->{'card'}
$_->{'card'} == $card
Truth table100%3/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $card
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 11 | @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 11 | ▶ | return $self->card($card) . ': not one you can play' unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 11 | ▶ | my $trump = suit_of($card) eq $view->{trump} ? ', a trump' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 11 | my $bout = $view->{bout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 11 | ▶ | if ($move->{kind} eq 'defend') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | my $beats = defined $bout && defined $bout->{unbeaten} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | ? ' the ' . $self->card($bout->{unbeaten}) : ' the attack'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $bout and defined $bout->{"unbeaten"}
MC/DC0%0/2
defined $bout and defined $bout->{"unbeaten"}
defined $bout
defined $bout->{"unbeaten"}
Truth table0%0/3
A and B
A= defined $boutB= defined $bout->{"unbeaten"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return $self->card($card) . ": beats$beats$trump"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 11 | ▶ | my $room = defined $bout ? ($bout->{cap} - $bout->{size}) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 11 | ▶ | my $with = $room > 1 ? sprintf ', %d more could follow', $room - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | : $room == 1 ? ', the last this bout can hold' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 11 | return $self->card($card) . ": they must beat it$trump$with"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 8 | ▶ | sub pick_keys { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 8 | return 'arrows to choose, enter to play, ? for the keys'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub pick_help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | 'arrows walk the cards you may play, enter plays the one under the cursor', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 'the line above says what it would do', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 't take, d done, x exchange, r resign, q quit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 4 | ▶ | sub pick_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_move: called CC=36 SCAR=52.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 4 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 4 | my $at_list = $self->playable($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | my @slot = @$at_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 4 | my %by; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | push @{ $by{ $_->{kind} } }, $_ for @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 4 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 4 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | ▶ | my $card = @slot ? $view->{hand}[ $slot[$at] - 1 ] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 8 | ▶ | $self->told(@notice) if @notice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 8 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 8 | ▶ | $self->told($self->card_line($view, $card)) if defined $card; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 8 | ▶ | $self->position($view, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | cursor => (defined $card ? $slot[$at] : undef), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | footer => $self->pick_keys); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 8 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 8 | ▶ | return { kind => 'quit' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | if !defined $key || $key eq 'eof' || $key eq 'interrupt' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | || $key eq 'q'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 5 | ▶ | if (@slot && ($key eq 'left' || $key eq 'up')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@slot and $key eq "left" || $key eq "up"
$key eq "left" or $key eq "up"
MC/DC0%0/3
@slot and $key eq "left" || $key eq "up"
@slot
$key eq "left"
$key eq "up"
Truth table25%1/4
A and B or C
A= @slotB= $key eq "left"C= $key eq "up"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $at = ($at - 1) % @slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 5 | ▶ | if (@slot && ($key eq 'right' || $key eq 'down' || $key eq 'tab')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
@slot 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
@slot and $key eq "right" || $key eq "down" || $key eq "tab"
@slot
$key eq "right"
$key eq "down"
$key eq "tab"
Truth table40%2/5
A and B or C or D
A= @slotB= $key eq "right"C= $key eq "down"D= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | $at = ($at + 1) % @slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | ▶ | if (@slot && ($key eq 'home')) { $at = 0; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@slot and $key eq "home"
MC/DC0%0/2
@slot and $key eq "home"
@slot
$key eq "home"
Truth table33%1/3
A and B
A= @slotB= $key eq "home"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | ▶ | if (@slot && ($key eq 'end')) { $at = $#slot; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@slot and $key eq "end"
MC/DC0%0/2
@slot and $key eq "end"
@slot
$key eq "end"
Truth table33%1/3
A and B
A= @slotB= $key eq "end"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | ▶ | if (@slot && ($key eq 'enter' || $key eq ' ')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@slot and $key eq "enter" || $key eq " "
$key eq "enter" or $key eq " "
MC/DC0%0/3
@slot and $key eq "enter" || $key eq " "
@slot
$key eq "enter"
$key eq " "
Truth table25%1/4
A and B or C
A= @slotB= $key eq "enter"C= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | my ($move) = grep { defined $_->{card} && $_->{card} == $card } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'card'} && $_->{'card'} == $card
MC/DC0%0/2
defined $_->{'card'} && $_->{'card'} == $card
defined $_->{'card'}
$_->{'card'} == $card
Truth table0%0/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $card
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | return $move if $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | @notice = ('you cannot play that one'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | ▶ | if ($key eq 't' && $by{take}) { return $by{take}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "t" and $by{"take"}
MC/DC50%1/2
$key eq "t" and $by{"take"}
$key eq "t"
$by{"take"}
Truth table66%2/3
A and B
A= $key eq "t"B= $by{"take"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | if ($key eq 'd' && $by{done}) { return $by{done}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "d" and $by{"done"}
MC/DC0%0/2
$key eq "d" and $by{"done"}
$key eq "d"
$by{"done"}
Truth table33%1/3
A and B
A= $key eq "d"B= $by{"done"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | if ($key eq 'x' && $by{swap}) { return $by{swap}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "x" and $by{"swap"}
MC/DC0%0/2
$key eq "x" and $by{"swap"}
$key eq "x"
$by{"swap"}
Truth table33%1/3
A and B
A= $key eq "x"B= $by{"swap"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | ▶ | if ($key eq 'r') { return { kind => 'resign' } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | if ($key =~ /\A[1-9]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | my ($found) = grep { $slot[$_] == $key } 0 .. $#slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if (defined $found) { $at = $found; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | @notice = ("you cannot play card $key"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | if ($key eq '?') { @notice = $self->pick_help; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | @notice = ('that key does nothing here'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 95 | ▶ | sub move_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move_for: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 95 | my ($self, $view, $said) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 95 | ▶ | return undef unless defined $said; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 94 | $said =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 94 | ▶ | return { kind => 'quit' } if lc $said eq 'q' || lc $said eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $said eq "q" or lc $said eq "quit"
MC/DC100%2/2
lc $said eq "q" or lc $said eq "quit"
lc $said eq "q"
lc $said eq "quit"
Truth table100%3/3
A or B
A= lc $said eq "q"B= lc $said eq "quit"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 88 | my %by; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 88 | push @{ $by{ $_->{kind} } }, $_ for @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 88 | ▶ | return $by{take}[0] if lc $said eq 't' && $by{take}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $said eq "t" and $by{"take"}
MC/DC100%2/2
lc $said eq "t" and $by{"take"}
lc $said eq "t"
$by{"take"}
Truth table100%3/3
A and B
A= lc $said eq "t"B= $by{"take"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 83 | ▶ | return $by{done}[0] if lc $said eq 'd' && $by{done}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $said eq "d" and $by{"done"}
MC/DC100%2/2
lc $said eq "d" and $by{"done"}
lc $said eq "d"
$by{"done"}
Truth table100%3/3
A and B
A= lc $said eq "d"B= $by{"done"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 79 | ▶ | return $by{swap}[0] if lc $said eq 'x' && $by{swap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $said eq "x" and $by{"swap"}
MC/DC100%2/2
lc $said eq "x" and $by{"swap"}
lc $said eq "x"
$by{"swap"}
Truth table100%3/3
A and B
A= lc $said eq "x"B= $by{"swap"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 78 | ▶ | return { kind => 'resign' } if lc $said eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 77 | ▶ | return undef unless $said =~ /\A[0-9]+\z/ && $said >= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$said =~ /\A[0-9]+\z/ and $said >= 1
MC/DC100%2/2
$said =~ /\A[0-9]+\z/ and $said >= 1
$said =~ /\A[0-9]+\z/
$said >= 1
Truth table100%3/3
A and B
A= $said =~ /\A[0-9]+\z/B= $said >= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 57 | my $card = $view->{hand}[ $said - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 57 | ▶ | return undef unless defined $card; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | my ($move) = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 209 | ▶ | defined $_->{card} && $_->{card} == $card | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $_->{'card'} && $_->{'card'} == $card
MC/DC100%2/2
defined $_->{'card'} && $_->{'card'} == $card
defined $_->{'card'}
$_->{'card'} == $card
Truth table100%3/3
A && B
A= defined $_->{'card'}B= $_->{'card'} == $card
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 55 | } @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 55 | return $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 25 | ▶ | sub cards { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cards: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 25 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 25 | ▶ | return $n == 1 ? '1 card' : "$n cards"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 61 | ▶ | sub narration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
narration: called CC=17 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 61 | my ($self, $view, @events) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 61 | my $me = $view->{seat}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 61 | my @said; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 61 | for my $event (@events) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 114 | my $kind = $event->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 114 | ▶ | if ($SAID{$kind}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | my $who = !defined $event->{seat} ? 'somebody' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 64 | ▶ | : $event->{seat} == $me ? 'you' : 'they'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | my $what = defined $event->{card} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 64 | ▶ | ? ' ' . long_name_of($event->{card}) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 64 | push @said, "$who $SAID{$kind}$what"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 64 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 50 | ▶ | if ($kind eq 'bout_end') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 23 | ▶ | if ($event->{taken}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 11 | my $took = 3 - $event->{next_attacker}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | push @said, sprintf '%s pick up %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 11 | ▶ | $took == $me ? 'you' : 'they', $self->cards($event->{cards}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | push @said, sprintf 'the bout is beaten off, %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 12 | $self->cards($event->{cards}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 23 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 27 | ▶ | if ($kind eq 'refill') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 22 | ▶ | next unless $event->{drawn}{1} || $event->{drawn}{2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$event->{"drawn"}{1} or $event->{"drawn"}{2}
MC/DC100%2/2
$event->{"drawn"}{1} or $event->{"drawn"}{2}
$event->{"drawn"}{1}
$event->{"drawn"}{2}
Truth table100%3/3
A or B
A= $event->{"drawn"}{1}B= $event->{"drawn"}{2}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | push @said, sprintf 'you draw %d, they draw %d, %d left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | $event->{drawn}{$me}, $event->{drawn}{ 3 - $me }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 17 | $event->{talon}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 17 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | ▶ | if ($kind eq 'out') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 2 | ▶ | push @said, $event->{seat} == $me ? 'you are out' : 'they are out'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 3 | ▶ | if ($kind eq 'game_end') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | push @said, !defined $event->{fool} ? 'a draw, and no fool' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 3 | ▶ | : $event->{fool} == $me ? 'you are the durak' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | : 'they are the durak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 61 | return @said; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2 | ▶ | sub narrate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
narrate: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | my ($self, $view, @events) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2 | my @said = $self->narration($view, @events); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 2 | ▶ | return unless @said; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | ▶ | $self->say('') if grep { $_ =~ /durak|a draw/ } @said; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 2 | $self->say(" $_") for @said; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 4 | my $game = Game::Durak->build(seed => $self->seed); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 4 | ▶ | die $game->message . "\n" if ref $game eq 'Game::Durak::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 4 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 4 | return $game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=14 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 4 | ▶ | my $game = $self->game || $self->start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->game || $self->start
MC/DC0%0/2
$self->game || $self->start
$self->game
$self->start
Truth table33%1/3
A || B
A= $self->gameB= $self->start
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 4 | my $me = $self->_seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 4 | ▶ | my $bot = Game::Durak::Bot->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->seed || ''
MC/DC0%0/1
$self->seed || ''
$self->seed
Truth table50%1/2
A
A= $self->seed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | level => Game::Durak::Bot->level_for($self->_level), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | seed => ($self->seed || '') . ':bot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 4 | $self->open_screen($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 4 | ▶ | while (!$game->over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 113 | my $seat = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 113 | my $view = $game->view($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 113 | ▶ | if ($seat != $me) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 34 | my $move = $bot->choose($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 34 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 34 | my @events = $game->apply($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 34 | ▶ | last if ref $events[0] eq 'Game::Durak::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 34 | $self->told($self->narration($game->view($me), @events)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 34 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 79 | my $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 79 | ▶ | if ($self->picking && $self->enter_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->picking and $self->enter_raw
MC/DC0%0/2
$self->picking and $self->enter_raw
$self->picking
$self->enter_raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->enter_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $move = $self->pick_move($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 79 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 79 | $self->position($view); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 79 | my $handle = $self->_in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 79 | my $said = <$handle>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 79 | ▶ | last unless defined $said; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 77 | $move = $self->move_for($view, $said); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 77 | ▶ | unless ($move) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 51 | $self->told('that is not one of the answers'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 51 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 26 | ▶ | last if $move->{kind} eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 25 | my @events = $game->apply($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 25 | ▶ | if (ref $events[0] eq 'Game::Durak::Error') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $self->told($events[0]->message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 25 | $self->told($self->narration($game->view($me), @events)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 4 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 4 | $self->close_screen($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 4 | return $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 4 | ▶ | sub open_screen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_screen: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 4 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 4 | ▶ | if ($self->_paint) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | my $handle = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | print {$handle} "\e[2J\e[H"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->told(sprintf 'durak: the loser is the fool, and seat %d opens', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | $game->turn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | $self->say('durak: the loser is the fool'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 4 | $self->say('trump is ' . $self->card_suit($game->trump) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | . ', and seat ' . $game->turn . ' opens'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 87 | ▶ | sub position { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 87 | my ($self, $view, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 87 | ▶ | my $footer = defined $o{footer} ? $o{footer} : $self->prompt_for($view); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | return $self->show($view, footer => $footer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 87 | ▶ | (defined $o{cursor} ? (cursor => $o{cursor}) : ())) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | if $self->_paint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 87 | $self->say($self->table($view, %o)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 87 | $self->say(' ' . $footer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 87 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 4 | ▶ | sub close_screen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close_screen: called CC=6 SCAR=33.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 4 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 4 | ▶ | return unless $self->_paint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | my $view = $game->view($self->_seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | my $fool = $result ? $result->{fool} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | my $over = !$result ? 'you left the table' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | : !defined $fool ? 'a draw, and no fool' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | : $fool == $self->_seat ? 'you are the durak' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | : 'they are the durak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | $self->show($view, header => $over, footer => 'the deal is over'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my $handle = $self->_out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | print {$handle} "\e[0m\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||