| 1 | package Game::Mahjong::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Game::Mahjong; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Game::Mahjong::Tiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Game::Mahjong::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Game::Mahjong::Rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Game::Mahjong::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Game::Mahjong::Fans; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Game::Mahjong::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | has seed => (is => 'ro', isa => Str, required => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | has level => (is => 'ro', isa => Int, default => 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | has seat => (is => 'ro', isa => Int, default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | has in => (is => 'ro', required => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | has out => (is => 'ro', required => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | has colour => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | has glyphs => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | has ascii => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | has clear => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | has auto => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 35 | ▶ | has names => (is => 'ro', isa => ArrayRef, default => sub { [ 'You', 'Ada', 'Bram', 'Cho' ] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | has rules => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | has bots => (is => 'rw', isa => ArrayRef, default => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | has hinter => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | has quit => (is => 'rw', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | has finished => (is => 'rw', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | has winner => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | has cursor => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | has raw => (is => 'rw', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 35 | ▶ | has pending => (is => 'rw', isa => ArrayRef, default => sub { [] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | has _picking => (is => 'rw', init_arg => 'picking'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | our %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 'A' => 'up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 'B' => 'down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 'C' => 'right', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'H' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | '1~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | '4~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | '5~' => 'page_up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | '7~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | our %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | "\r" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | "\n" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | "\x7f" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | "\x03" => 'interrupt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | our %WIND = (0 => 'East', 1 => 'South', 2 => 'West', 3 => 'North'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | our $DOT = '|'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1043 | ▶ | sub _clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=3 SCAR=15.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1043 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1043 | ▶ | return unless $self->colour && $self->clear; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->colour and $self->clear
MC/DC0%0/2
$self->colour and $self->clear
$self->colour
$self->clear
Truth table66%2/3
A and B
A= $self->colourB= $self->clear
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | print {$out} "\e[H\e[2J"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | my %GLYPH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my @m = map { chr(0x1F007 + $_) } 0 .. 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | my @p = map { chr(0x1F019 + $_) } 0 .. 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | my @s = map { chr(0x1F010 + $_) } 0 .. 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | my @w = (chr 0x1F000, chr 0x1F001, chr 0x1F002, chr 0x1F003); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | my @d = (chr 0x1F004, chr 0x1F005, chr 0x1F006); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | my @f = map { chr(0x1F022 + $_) } 0 .. 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my @t = map { chr(0x1F026 + $_) } 0 .. 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | $GLYPH{ $i++ } = $_ for @m, @p, @s, @w, @d, @f, @t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 35 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 35 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 35 | ▶ | die 'Game::Mahjong::Terminal: the seat is 0 to 3' unless $self->seat >= 0 && $self->seat <= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->seat >= 0 and $self->seat <= 3
MC/DC50%1/2
$self->seat >= 0 and $self->seat <= 3
$self->seat >= 0
$self->seat <= 3
Truth table66%2/3
A and B
A= $self->seat >= 0B= $self->seat <= 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 34 | ▶ | die 'Game::Mahjong::Terminal: the level is 1 to 3' unless $self->level >= 1 && $self->level <= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->level >= 1 and $self->level <= 3
MC/DC50%1/2
$self->level >= 1 and $self->level <= 3
$self->level >= 1
$self->level <= 3
Truth table66%2/3
A and B
A= $self->level >= 1B= $self->level <= 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 33 | $self->rules(Game::Mahjong::Rules->new(seed => $self->seed)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 33 | $self->bots([ map { Game::Mahjong::Bot->new(level => $self->level, seed => $self->seed) } 0 .. 3 ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 33 | $self->hinter(Game::Mahjong::Bot->new(level => 3, seed => $self->seed . ':hint')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8917 | ▶ | sub _c { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_c: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 8917 | my ($self, $code, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 8917 | ▶ | return $text unless $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 13 | my %code = (bold => 1, dim => 2, red => 31, green => 32, yellow => 33, blue => 34, magenta => 35, cyan => 36); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | return "\e[$code{$code}m$text\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | our %HONOUR_FACE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | we => 'E', ws => 'S', ww => 'W', wn => 'N', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | dr => 'R', dg => 'G', dw => 'B', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | our %INK = (m => 196, p => 25, s => 29, f => 170, t => 178); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | our %HONOUR_INK = (we => 240, ws => 240, ww => 240, wn => 240, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | dr => 196, dg => 29, dw => 245); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | our $FACE_BG = 230; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | our $EDGE_FG = 180; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | our $SIDE_FG = 137; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | our $BACK_BG = 66; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | our $FRESH_FG = 28; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | our %FRAME = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | plain => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | wide => [ "\x{250c}", "\x{2510}", "\x{2514}", "\x{2518}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | "\x{2502}", "\x{2500}" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | ascii => [ '+', '+', '+', '+', '|', '-' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | fresh => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | wide => [ "\x{2554}", "\x{2557}", "\x{255a}", "\x{255d}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | "\x{2551}", "\x{2550}" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | ascii => [ '#', '#', '#', '#', '#', '=' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | cursor => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | wide => [ "\x{250f}", "\x{2513}", "\x{2517}", "\x{251b}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | "\x{2503}", "\x{2501}" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ascii => [ '+', '+', '+', '+', '!', '=' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 54607 | ▶ | sub face { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
face: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 54607 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 54607 | ▶ | return ' ' unless defined $kind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 54607 | ▶ | return $GLYPH{$kind} if $self->glyphs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 54589 | my $code = Game::Mahjong::Tiles::code_of($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 54589 | ▶ | return $HONOUR_FACE{$code} . ' ' if $HONOUR_FACE{$code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 39162 | my $text = Game::Mahjong::Notation::print($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 39162 | ▶ | $text = substr($text, 0, 2) if length $text > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 39162 | ▶ | return length $text == 1 ? "$text " : $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 18 | ▶ | sub _ink { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ink: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 18 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 18 | my $code = Game::Mahjong::Tiles::code_of($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 18 | ▶ | return $HONOUR_INK{$code} if $HONOUR_INK{$code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 14 | ▶ | return $INK{ substr($code, 0, 1) } // 240; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Mahjong::Terminal::INK{substr($code, 0, 1)} // 240
MC/DC0%0/1
$Game::Mahjong::Terminal::INK{substr($code, 0, 1)} // 240
$Game::Mahjong::Terminal::INK{substr($code, 0, 1)}
Truth table50%1/2
A
A= $Game::Mahjong::Terminal::INK{substr($code, 0, 1)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 14660 | ▶ | sub tile_art { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tile_art: called CC=13 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 14660 | my ($self, $kind, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 14660 | my $ascii = $self->ascii; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 14660 | ▶ | my $style = $o{cursor} ? 'cursor' : $o{mark} ? 'fresh' : 'plain'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | my ($tl, $tr, $bl, $br, $v, $h) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 14660 | ▶ | = @{ $FRAME{$style}{ $ascii ? 'ascii' : 'wide' } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 14660 | ▶ | my $face = $o{back} ? ($ascii ? '##' : "\x{2592}\x{2592}") : $self->face($kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 14660 | ▶ | unless ($self->colour) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 14646 | return ($tl . $h x 2 . $tr, $v . $face . $v, $bl . $h x 2 . $br); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | my $bg = $o{back} ? $BACK_BG : $FACE_BG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 14 | ▶ | my $ink = $o{back} ? 250 : $self->_ink($kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 14 | ▶ | my $edge = $o{mark} ? $FRESH_FG : $EDGE_FG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 14 | ▶ | my $side = $o{mark} ? $FRESH_FG : $SIDE_FG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 14 | ▶ | my $on = $o{cursor} ? "\e[1m\e[7m" : $o{mark} ? "\e[1m" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 14 | "$on\e[38;5;${edge}m\e[48;5;${bg}m" . $tl . $h x 2 . $tr . "\e[0m", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | "$on\e[38;5;${ink}m\e[48;5;${bg}m" . $v . $face . $v . "\e[0m", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | "$on\e[38;5;${side}m\e[48;5;${bg}m" . $bl . $h x 2 . $br . "\e[0m", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1189 | ▶ | sub tile_row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tile_row: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1189 | my ($self, $kinds, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1189 | my @line = ('', '', ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1189 | ▶ | my $backs = $o{backs} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{'backs'} || {}
MC/DC100%1/1
$o{'backs'} || {}
$o{'backs'}
Truth table100%2/2
A
A= $o{'backs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1189 | ▶ | my $gaps = $o{gaps} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{'gaps'} || {}
MC/DC100%1/1
$o{'gaps'} || {}
$o{'gaps'}
Truth table100%2/2
A
A= $o{'gaps'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1189 | for my $i (0 .. $#$kinds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 14660 | ▶ | my $pad = $gaps->{$i} ? ' ' : ($i ? ' ' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | my @art = $self->tile_art($kinds->[$i], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | back => $backs->{$i}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | mark => (defined $o{mark} && $o{mark} == $i), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 14660 | ▶ | cursor => (defined $o{cursor} && $o{cursor} == $i)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
defined $o{'mark'} && $o{'mark'} == $i
defined $o{'cursor'} && $o{'cursor'} == $i
MC/DC100%2/2
defined $o{'mark'} && $o{'mark'} == $i
defined $o{'mark'}
$o{'mark'} == $i
MC/DC100%2/2
defined $o{'cursor'} && $o{'cursor'} == $i
defined $o{'cursor'}
$o{'cursor'} == $i
Truth table100%3/3
A && B
A= defined $o{'mark'}B= $o{'mark'} == $i
Truth table100%3/3
A && B
A= defined $o{'cursor'}B= $o{'cursor'} == $i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 14660 | $line[$_] .= $pad . $art[$_] for 0 .. 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1189 | return @line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 39947 | ▶ | sub tile_chip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tile_chip: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 39947 | my ($self, $kind, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 39947 | my $face = $self->face($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 39947 | ▶ | return ($o{last} ? "<$face>" : "[$face]") unless $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | my $ink = $self->_ink($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | my $bg = $o{last} ? 223 : $FACE_BG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | return "\e[38;5;${ink}m\e[48;5;${bg}m" . ($o{last} ? '<' : '[') . $face . ($o{last} ? '>' : ']') . "\e[0m"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3243 | ▶ | sub tile_chips { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tile_chips: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3243 | my ($self, @kinds) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3243 | return join '', map { $self->tile_chip($_) } @kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4593 | ▶ | sub tile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tile: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4593 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4593 | ▶ | return $self->glyphs ? $GLYPH{$kind} : Game::Mahjong::Notation::print($kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | sub tiles { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tiles: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my ($self, @kinds) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | ▶ | return '' unless @kinds; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | return $self->glyphs ? join('', map { $GLYPH{$_} } @kinds) : Game::Mahjong::Notation::print(@kinds); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 12558 | ▶ | sub name_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 12558 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 12558 | return $self->names->[$seat]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 603 | ▶ | sub _does { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_does: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 603 | my ($self, $seat, $third, $second) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 603 | ▶ | return $self->name_of($seat) . ' ' . ($seat == $self->seat ? $second : $third); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 27126 | ▶ | sub say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 27126 | my ($self, @text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 27126 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 27126 | print {$out} @text, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 27126 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 6412 | ▶ | sub _on_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_turn: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 6412 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 6412 | my $turn = $self->rules->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 6412 | ▶ | return defined $turn && $self->rules->phase eq 'discard' && $turn == $seat ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $turn and $self->rules->phase eq "discard" and $turn == $seat
defined $turn and $self->rules->phase eq "discard"
MC/DC66%2/3
defined $turn and $self->rules->phase eq "discard" and $turn == $seat
defined $turn
$self->rules->phase eq "discard"
$turn == $seat
Truth table75%3/4
A and B and C
A= defined $turnB= $self->rules->phase eq "discard"C= $turn == $seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 5215 | ▶ | sub _wind_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wind_of: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 5215 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 5215 | return $WIND{ $self->rules->seat_wind($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1043 | ▶ | sub show_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_table: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1043 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1043 | my $g = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1043 | my $me = $self->seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1043 | my $w = $g->window; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1043 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1043 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | $self->say($self->_c('bold', sprintf 'Hand %d of %d %s %s round %s you are %s %s wall %d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1043 | $g->hand_no, Game::Mahjong::Result::HANDS, $DOT, $WIND{ $g->prevailing }, $DOT, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | $self->_wind_of($me), $DOT, $g->wall->remaining)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | $self->say('Totals ' . join(' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1043 | ▶ | sprintf '%s %s', $self->name_of($_), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | $self->_c($g->totals->[$_] < 0 ? 'red' : 'green', sprintf '%+d', $g->totals->[$_]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } 0 .. 3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1043 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1043 | for my $i (1 .. 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 3129 | my $seat = ($me + $i) % 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 3129 | my $hand = $g->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3129 | ▶ | my $mark = $self->_on_turn($seat) ? $self->_c('yellow', '>') : ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 3129 | ▶ | my $dealer = $seat == $g->dealer ? ' (deals)' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | $self->say(sprintf '%s %-5s %-6s %2d tiles%s%s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | $mark, $self->name_of($seat), $self->_wind_of($seat), $hand->size, $dealer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3129 | ▶ | (@{ $hand->flowers } ? ' flowers ' . $self->tile_chips(@{ $hand->flowers }) : '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3129 | ▶ | $self->say(' sets ' . $self->_melds_line($hand)) if @{ $hand->melds }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3129 | $self->say(' pool ' . $self->_pool($seat)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1043 | ▶ | if ($w && $g->is_active) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$w and $g->is_active
MC/DC50%1/2
$w and $g->is_active
$w
$g->is_active
Truth table66%2/3
A and B
A= $wB= $g->is_active
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | my @art = $self->tile_row([ $w->{tile} ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | my $from = $self->name_of($w->{from}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | ▶ | my $verb = $g->phase eq 'rob' ? 'adds to a pung' : 'discards'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | $self->say(' ' . $art[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | $self->say(' ' . $art[1] . ' ' . $self->_c('yellow', "$from $verb this")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | $self->say(' ' . $art[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1043 | my $mine = $g->hand_of($me); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1043 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | $self->say($self->_c('bold', sprintf '%s %-5s %-6s%s%s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ($self->_on_turn($me) ? $self->_c('yellow', '>') : ' '), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | $self->name_of($me), $self->_wind_of($me), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | ($me == $g->dealer ? ' (you deal)' : ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1043 | ▶ | (@{ $mine->flowers } ? ' flowers ' . $self->tile_chips(@{ $mine->flowers }) : ''))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1043 | $self->say(' pool ' . $self->_pool($me)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1043 | ▶ | if (@{ $mine->melds }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 98 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 98 | $self->say(' Your sets:'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 98 | $self->say(' ' . $_) for $self->_melds_art($mine); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1043 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1043 | $self->say(' Your hand:'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1043 | $self->say(' ' . $_) for $self->_rack_art; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1043 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 98 | ▶ | sub _melds_art { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_melds_art: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 98 | my ($self, $hand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 98 | my (@kinds, %backs, %gaps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 98 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 98 | for my $meld (@{ $hand->melds }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 109 | ▶ | $gaps{$n} = 1 if $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 109 | for my $t (@{ $meld->tiles }) { push @kinds, $t; $n++ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 98 | ▶ | return ('-') unless @kinds; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 98 | my @line = $self->tile_row(\@kinds, backs => \%backs, gaps => \%gaps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 98 | my $label = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 98 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 98 | for my $meld (@{ $hand->melds }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 109 | my $width = 5 * scalar(@{ $meld->tiles }) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 109 | ▶ | $label .= ' ' if $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 109 | ▶ | $label .= sprintf '%-*s', $width, $meld->kind . ($meld->concealed ? ' (concealed)' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 109 | $at++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 98 | return (@line, $label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 246 | ▶ | sub _melds_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_melds_line: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 246 | my ($self, $hand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 246 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 246 | for my $meld (@{ $hand->melds }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | push @out, $meld->concealed && $hand != $self->rules->hand_of($self->seat) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ? ($self->colour ? "\e[48;5;${BACK_BG}m\e[38;5;250m[##][##][##][##]\e[0m" : '[##][##][##][##]') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 270 | ▶ | : $self->tile_chips(@{ $meld->tiles }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$meld->concealed and $hand != $self->rules->hand_of($self->seat)
MC/DC50%1/2
$meld->concealed and $hand != $self->rules->hand_of($self->seat)
$meld->concealed
$hand != $self->rules->hand_of($self->seat)
Truth table66%2/3
A and B
A= $meld->concealedB= $hand != $self->rules->hand_of($self->seat)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 246 | return join ' ', @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1158 | ▶ | sub rack_order { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rack_order: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1158 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1158 | my $g = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1158 | my @kinds = $g->hand_of($self->seat)->tiles; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1158 | ▶ | my $drawn = $self->_on_turn($self->seat) ? $g->drawn : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1158 | ▶ | return (\@kinds, undef) unless defined $drawn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1116 | my ($at) = grep { $kinds[$_] == $drawn } 0 .. $#kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1116 | ▶ | return (\@kinds, undef) unless defined $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1116 | splice @kinds, $at, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1116 | push @kinds, $drawn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1116 | return (\@kinds, $#kinds); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1043 | ▶ | sub _rack_art { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rack_art: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1043 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1043 | my ($kinds, $last) = $self->rack_order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1043 | my @kinds = @$kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1043 | my %gaps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1043 | ▶ | $gaps{$last} = 1 if defined $last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 1043 | my @line = $self->tile_row(\@kinds, gaps => \%gaps, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | mark => $last, cursor => $self->cursor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1043 | my $numbers = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1043 | for my $i (0 .. $#kinds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 14274 | ▶ | $numbers .= $gaps{$i} ? ' ' : ($i ? ' ' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 14274 | $numbers .= sprintf ' %-3s', $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1043 | ▶ | $numbers = substr($numbers, 0, length($numbers) - 1) if length $numbers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1043 | push @line, $numbers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1043 | ▶ | push @line, $self->_c('dim', sprintf ' %s the tile you just drew', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $self->_caret_under($last, \%gaps)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | if defined $last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1043 | return @line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1002 | ▶ | sub _caret_under { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_caret_under: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1002 | my ($self, $i, $gaps) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1002 | my $col = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1002 | ▶ | for my $n (0 .. $i) { $col += ($gaps->{$n} ? 3 : ($n ? 1 : 0)) + 4 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1002 | return (' ' x ($col - 3)) . '^'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 4172 | ▶ | sub _pool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pool: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 4172 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 4172 | my @p = @{ $self->rules->pool_of($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 4172 | ▶ | return $self->_c('dim', 'nothing thrown yet') unless @p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 3972 | my $w = $self->rules->window; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 3972 | ▶ | my $lit = ($w && $w->{from} == $seat) ? $#p : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$w and $w->{"from"} == $seat
MC/DC100%2/2
$w and $w->{"from"} == $seat
$w
$w->{"from"} == $seat
Truth table100%3/3
A and B
A= $wB= $w->{"from"} == $seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 3972 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3972 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 3972 | my @chips = map { $self->tile_chip($_, last => ($i++ == $lit)) } @p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3972 | ▶ | while (@chips) { push @rows, join '', splice @chips, 0, 12 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 3972 | return join "\n ", @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 64 | ▶ | sub show_hand_end { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_hand_end: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 64 | my ($self, $e) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 64 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 64 | ▶ | if (!defined $e->{winner}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 17 | $self->say($self->_c('bold', 'The wall is exhausted: nobody wins this hand.')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 47 | my $who = $self->name_of($e->{winner}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 47 | ▶ | my $how = $e->{by} eq 'self' ? 'self-drawn' : $e->{by} eq 'rob' ? 'robbing the kong of ' . $self->name_of($e->{from}) : 'off ' . $self->name_of($e->{from}) . "'s discard"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 47 | ▶ | if (defined $e->{tile}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 47 | my @art = $self->tile_row([ $e->{tile} ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 47 | $self->say(' ' . $art[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 47 | $self->say(' ' . $art[1] . ' ' . $self->_c('bold', sprintf '%s, %s.', $who, $how)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 47 | $self->say(' ' . $art[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $self->say($self->_c('bold', sprintf '%s with the dealt tiles, a heavenly hand.', $who)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 47 | for my $f (@{ $e->{fans} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 242 | my $fan = Game::Mahjong::Fans::by_key($f->{key}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 242 | ▶ | $self->say(sprintf ' %-32s %3d%s', $fan->name, $f->{points} * $f->{times}, $f->{times} > 1 ? " ($f->{times} x $f->{points})" : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 47 | $self->say(sprintf ' %-32s %3d', $self->_c('bold', 'Total'), $e->{points}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 47 | ▶ | $self->say('Settlement: ' . join(', ', map { sprintf '%s %s', $self->name_of($_), $self->_c($e->{deltas}[$_] < 0 ? 'red' : 'green', ($e->{deltas}[$_] >= 0 ? '+' : '') . $e->{deltas}[$_]) } 0 .. 3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 64 | for my $seat (0 .. 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 256 | ▶ | my @k = @{ $e->{concealed_kongs}[$seat] || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$e->{'concealed_kongs'}[$seat] || []
MC/DC0%0/1
$e->{'concealed_kongs'}[$seat] || []
$e->{'concealed_kongs'}[$seat]
Truth table50%1/2
A
A= $e->{'concealed_kongs'}[$seat]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 256 | $self->say(sprintf '%s a concealed kong of %s.', $self->_does($seat, 'shows', 'show'), $self->tiles(($_) x 4)) for @k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 64 | $self->say('Totals now: ' . join(' ', map { sprintf '%s %d', $self->name_of($_), $e->{totals}[$_] } 0 .. 3)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 64 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 4 | ▶ | sub show_game_end { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_game_end: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 4 | my ($self, $e) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | $self->finished(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | $self->winner($e->{winner}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | $self->say($self->_c('bold', 'The game is over after sixteen hands.')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | my @order = sort { $e->{places}[$a] <=> $e->{places}[$b] } 0 .. 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | $self->say(sprintf ' %d. %-5s %5d', $e->{places}[$_], $self->name_of($_), $e->{totals}[$_]) for @order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | ▶ | $self->say(defined $e->{winner} ? $self->_does($e->{winner}, 'wins', 'win') . ' the game.' : 'A shared first place: the game is drawn.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 5432 | ▶ | sub narrate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
narrate: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 5432 | my ($self, @events) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 5432 | for my $e (@events) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 10508 | my $k = $e->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 10508 | my $actor = $e->{actor}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 10508 | ▶ | if ($k eq 'deal') { $self->say($self->_c('dim', sprintf 'Hand %d. %s.', $e->{hand}, $self->_does($e->{dealer}, 'deals', 'deal'))) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 473 | ▶ | elsif ($k eq 'flower') { $self->say(sprintf '%s a flower, %s, and %s again.', $self->_does($e->{seat}, 'exposes', 'expose'), $self->tile($e->{tile}), $e->{seat} == $self->seat ? 'draw' : 'draws') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | ▶ | elsif ($k eq 'drew' && $e->{seat} == $self->seat && $self->_on_turn($self->seat) && defined $self->rules->drawn) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$k eq "drew" and $e->{"seat"} == $self->seat and $self->_on_turn($self->seat) and defined $self->rules->drawn
$k eq "drew" and $e->{"seat"} == $self->seat and $self->_on_turn($self->seat)
$k eq "drew" and $e->{"seat"} == $self->seat
MC/DC100%4/4
$k eq "drew" and $e->{"seat"} == $self->seat and $self->_on_turn($self->seat) and defined $self->rules->drawn
$k eq "drew"
$e->{"seat"} == $self->seat
$self->_on_turn($self->seat)
defined $self->rules->drawn
Truth table100%5/5
A and B and C and D
A= $k eq "drew"B= $e->{"seat"} == $self->seatC= $self->_on_turn($self->seat)D= defined $self->rules->drawn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 1028 | ▶ | $self->say(sprintf 'You draw %s from the %s.', $self->tile($self->rules->drawn), $e->{from} eq 'back' ? 'back of the wall' : 'wall'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 3011 | ▶ | elsif ($k eq 'discard' && $actor ne $self->seat) { $self->say(sprintf '%s discards %s.', $self->name_of($actor), $self->tile($e->{tile})) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$k eq "discard" and $actor ne $self->seat
MC/DC100%2/2
$k eq "discard" and $actor ne $self->seat
$k eq "discard"
$actor ne $self->seat
Truth table100%3/3
A and B
A= $k eq "discard"B= $actor ne $self->seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | elsif ($k eq 'claimed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 88 | ▶ | next if $e->{meld} eq 'win'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 51 | $self->say(sprintf '%s %s from %s for a %s.', $self->_does($e->{seat}, 'claims', 'claim'), $self->tile($e->{tile}), $self->name_of($e->{from}), $e->{meld}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 3 | ▶ | elsif ($k eq 'kong' && $actor ne $self->seat) { $self->say(sprintf '%s declares a %s kong of %s.', $self->name_of($actor), $e->{how}, $self->tile($e->{tile})) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$k eq "kong" and $actor ne $self->seat
MC/DC100%2/2
$k eq "kong" and $actor ne $self->seat
$k eq "kong"
$actor ne $self->seat
Truth table100%3/3
A and B
A= $k eq "kong"B= $actor ne $self->seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 64 | elsif ($k eq 'hand_end') { $self->show_hand_end($e) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | elsif ($k eq 'game_end') { $self->show_game_end($e) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 5432 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | $self->say('Commands:'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | $self->say(' <n> discard the tile numbered n in your hand'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | $self->say(' d <tile> discard a tile by name, e.g. d 5m, d E, d B (white dragon)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | $self->say(' kong <tile> declare a kong (four in hand, or the fourth for your exposed pung)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | $self->say(' win declare your hand complete'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $self->say(' pass | pung | kong | chow <n> answer a discard (chow <n> picks the shape offered)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | $self->say(' hint what the strongest bot would do'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | $self->say(' table show the table again'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | $self->say(' fans list the eighty-one scoring elements and their points'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | $self->say(' help this list'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | $self->say(' quit leave the game'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | sub show_fans { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_fans: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | for my $fan (Game::Mahjong::Fans::all()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 81 | $self->say(sprintf '%2d %-36s %2d', $fan->n, $fan->name, $fan->points); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 36 | ▶ | sub _describe_legal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_describe_legal: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 36 | my ($self, @legal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 36 | my $g = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 36 | ▶ | if ($g->phase ne 'discard') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | my $w = $g->window; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | for my $m (@legal) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | ▶ | my $text = $m->{kind} eq 'chow' ? sprintf('chow %d (%s)', ++$n, $self->tiles(@{ $m->{tiles} })) : $m->{kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | push @lines, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | ▶ | $self->say(sprintf '%s %s %s. You may: %s', $self->name_of($w->{from}), ($g->phase eq 'rob' ? 'adds to a pung' : 'discards'), $self->tile($w->{tile}), join(', ', @lines)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 35 | my @extra = grep { $_->{kind} ne 'discard' } @legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 35 | ▶ | $self->say('You may also: ' . join(', ', map { $_->{kind} eq 'kong' ? 'kong ' . $self->tile($_->{tile}) : $_->{kind} } @extra)) if @extra; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 9 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=6 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 9 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 9 | ▶ | $self->_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 9 | ▶ | return 0 if $self->auto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 9 | ▶ | return $self->_picking ? 1 : 0 if defined $self->_picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 9 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 9 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=4 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 9 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 9 | ▶ | return 0 unless eval { -t $self->in }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 13 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 13 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 13 | ▶ | if ($self->keysource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 13 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 86 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 86 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 86 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 86 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 84 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | return Term::ReadKey::ReadKey(-1, $self->in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 44 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 44 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 44 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 44 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 43 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 26 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 5 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 21 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 21 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 21 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 21 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 2 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 2 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 19 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 19 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 21 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 21 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 21 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 21 | ▶ | last if $char =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 19 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Mahjong::Terminal::SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$Game::Mahjong::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Mahjong::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Mahjong::Terminal::SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 25 | ▶ | sub throw_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_line: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 25 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 25 | my $hand = $self->rules->hand_of($self->seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 25 | my $left = Game::Mahjong::Shanten::after_discard($hand, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 25 | ▶ | my $line = sprintf 'throw %s and you are %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | $self->tile($kind), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | $left < 0 ? 'out' : $left == 0 ? 'waiting' : "$left away"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 25 | my $rest = $hand->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 25 | $rest->remove($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 25 | my @help = Game::Mahjong::Shanten::ukeire($rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 25 | ▶ | $line .= sprintf ', %d %s help', scalar @help, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | @help == 1 ? 'kind would' : 'kinds would' if @help; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 25 | ▶ | $line .= ', a step backwards' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | if $left > Game::Mahjong::Shanten::shanten($hand); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 25 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 13 | ▶ | sub pick_discard { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_discard: called CC=28 SCAR=50.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 13 | my ($self, @legal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 13 | my ($kinds) = $self->rack_order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 153 | my %throwable = map { $_->{tile} => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 13 | grep { $_->{kind} eq 'discard' } @legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 13 | my @slot = grep { $throwable{ $kinds->[$_] } } 0 .. $#$kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 13 | ▶ | return undef unless @slot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 13 | my $at = $#slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 13 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 13 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 25 | $self->show_pick(\@slot, $at, \@notice, \@legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 25 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 25 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 25 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | $self->quit(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 24 | ▶ | if ($key eq 'left' || $key eq 'down') { $at = ($at - 1) % @slot; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "left" or $key eq "down"
MC/DC50%1/2
$key eq "left" or $key eq "down"
$key eq "left"
$key eq "down"
Truth table66%2/3
A or B
A= $key eq "left"B= $key eq "down"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 15 | ▶ | if ($key eq 'right' || $key eq 'up' || $key eq 'tab') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$key eq "right" or $key eq "up" or $key eq "tab"
$key eq "right" or $key eq "up"
MC/DC33%1/3
$key eq "right" or $key eq "up" or $key eq "tab"
$key eq "right"
$key eq "up"
$key eq "tab"
Truth table50%2/4
A or B or C
A= $key eq "right"B= $key eq "up"C= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 3 | $at = ($at + 1) % @slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 12 | ▶ | if ($key eq 'home' || $key eq 'page_up') { $at = 0; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "home" or $key eq "page_up"
MC/DC0%0/2
$key eq "home" or $key eq "page_up"
$key eq "home"
$key eq "page_up"
Truth table33%1/3
A or B
A= $key eq "home"B= $key eq "page_up"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 12 | ▶ | if ($key eq 'end' || $key eq 'page_down') { $at = $#slot; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "end" or $key eq "page_down"
MC/DC0%0/2
$key eq "end" or $key eq "page_down"
$key eq "end"
$key eq "page_down"
Truth table33%1/3
A or B
A= $key eq "end"B= $key eq "page_down"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 12 | ▶ | if ($key eq 'enter' || $key eq ' ') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "enter" or $key eq " "
MC/DC0%0/2
$key eq "enter" or $key eq " "
$key eq "enter"
$key eq " "
Truth table33%1/3
A or B
A= $key eq "enter"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 12 | my $t = $kinds->[ $slot[$at] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 12 | ▶ | my ($m) = grep { $_->{kind} eq 'discard' && $_->{tile} == $t } @legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'kind'} eq 'discard' && $_->{'tile'} == $t
MC/DC50%1/2
$_->{'kind'} eq 'discard' && $_->{'tile'} == $t
$_->{'kind'} eq 'discard'
$_->{'tile'} == $t
Truth table66%2/3
A && B
A= $_->{'kind'} eq 'discard'B= $_->{'tile'} == $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 12 | ▶ | return $m if $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | @notice = ('you cannot throw that one'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | if ($key =~ /\A[1-9]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | my ($found) = grep { $slot[$_] == $key - 1 } 0 .. $#slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | ▶ | if (defined $found) { $at = $found; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | @notice = ('no tile is numbered ' . $key . ' here'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | if ($key eq 'h') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | my $m = $self->hinter->hint($self->rules, $self->seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if ($m && $m->{kind} eq 'discard') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$m and $m->{"kind"} eq "discard"
MC/DC0%0/2
$m and $m->{"kind"} eq "discard"
$m
$m->{"kind"} eq "discard"
Truth table0%0/3
A and B
A= $mB= $m->{"kind"} eq "discard"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my ($found) = grep { $kinds->[ $slot[$_] ] == $m->{tile} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 .. $#slot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | $at = $found if defined $found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | @notice = ('Hint: ' . $self->_move_text($m)) if $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | if ($key eq 't') { $self->picking(0); return $self->read_move(@legal) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | if ($key eq '?') { @notice = $self->pick_help; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | @notice = ('that key does nothing here. ? for the ones that do'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | sub pick_help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | 'left and right walk your rack. the tile under the cursor is the one', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 'you would throw, and the line under it says what that leaves you.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 'enter throws it, a number jumps to that tile, h is the hint,', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 't goes back to typing, q stops.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 25 | ▶ | sub show_pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_pick: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 25 | my ($self, $slot, $at, $notice, $legal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 25 | my ($kinds) = $self->rack_order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 25 | $self->cursor($slot->[$at]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 25 | $self->show_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 25 | $self->cursor(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 25 | $self->say(' ' . $self->throw_line($kinds->[ $slot->[$at] ])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 25 | $self->_describe_legal(@$legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 25 | $self->say(' ' . $self->_c('dim', $_)) for @$notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 25 | $self->say(' ' . $self->_c('dim', 'arrows to choose, enter to throw, ? for the keys')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 25 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 10 | ▶ | sub read_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_move: called CC=17 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 10 | my ($self, @legal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 10 | my $g = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 10 | my $in = $self->in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 10 | my $hand = $g->hand_of($self->seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 10 | ▶ | if ($g->phase eq 'discard' && $self->picking) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$g->phase eq "discard" and $self->picking
MC/DC0%0/2
$g->phase eq "discard" and $self->picking
$g->phase eq "discard"
$self->picking
Truth table66%2/3
A and B
A= $g->phase eq "discard"B= $self->picking
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | if ($self->enter_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | my $move = $self->pick_discard(@legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | return $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 10 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 17 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 17 | print {$out} '> '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 17 | my $line = <$in>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 17 | ▶ | unless (defined $line) { $self->quit(1); return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 16 | $line =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 16 | ▶ | next unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 16 | my ($cmd, @args) = split ' ', lc $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 16 | ▶ | if ($cmd eq 'quit' || $cmd eq 'q') { $self->quit(1); return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "quit" or $cmd eq "q"
MC/DC50%1/2
$cmd eq "quit" or $cmd eq "q"
$cmd eq "quit"
$cmd eq "q"
Truth table66%2/3
A or B
A= $cmd eq "quit"B= $cmd eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 8 | ▶ | if ($cmd eq 'help' || $cmd eq '?') { $self->help; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "help" or $cmd eq "?"
MC/DC50%1/2
$cmd eq "help" or $cmd eq "?"
$cmd eq "help"
$cmd eq "?"
Truth table66%2/3
A or B
A= $cmd eq "help"B= $cmd eq "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 7 | ▶ | if ($cmd eq 'table' || $cmd eq 't') { $self->show_table; $self->_describe_legal(@legal); next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "table" or $cmd eq "t"
MC/DC50%1/2
$cmd eq "table" or $cmd eq "t"
$cmd eq "table"
$cmd eq "t"
Truth table66%2/3
A or B
A= $cmd eq "table"B= $cmd eq "t"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 6 | ▶ | if ($cmd eq 'fans') { $self->show_fans; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 5 | ▶ | if ($cmd eq 'hint' || $cmd eq 'h') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "hint" or $cmd eq "h"
MC/DC50%1/2
$cmd eq "hint" or $cmd eq "h"
$cmd eq "hint"
$cmd eq "h"
Truth table66%2/3
A or B
A= $cmd eq "hint"B= $cmd eq "h"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | my $m = $self->hinter->hint($g, $self->seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 1 | ▶ | $self->say('Hint: ' . $self->_move_text($m)) if $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 4 | my $move = $self->_parse($cmd, \@args, \@legal, $hand); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 4 | ▶ | unless ($move) { $self->say('Not a move here. Type help for the commands.'); next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 1 | return $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 1 | ▶ | sub _move_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_move_text: called CC=5 SCAR=28.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 1 | my ($self, $m) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 1 | ▶ | return 'discard ' . $self->tile($m->{tile}) if $m->{kind} eq 'discard'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | return 'kong ' . $self->tile($m->{tile}) if $m->{kind} eq 'kong' && $m->{tile}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$m->{"kind"} eq "kong" and $m->{"tile"}
MC/DC0%0/2
$m->{"kind"} eq "kong" and $m->{"tile"}
$m->{"kind"} eq "kong"
$m->{"tile"}
Truth table0%0/3
A and B
A= $m->{"kind"} eq "kong"B= $m->{"tile"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | return 'chow with ' . $self->tiles(@{ $m->{tiles} }) if $m->{kind} eq 'chow'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | return $m->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 15 | ▶ | sub _parse_tile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_tile: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 15 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 15 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 15 | my $t = $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 15 | $t =~ s/\A([1-9])([mps])\z/$1$2/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 15 | ▶ | $t = uc $t if $t =~ /\A[eswnrgb]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 15 | my @ids = eval { Game::Mahjong::Notation::parse($t) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 15 | ▶ | return @ids == 1 ? $ids[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 74 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=21 SCAR=47.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 74 | my ($self, $cmd, $args, $legal, $hand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 74 | my $g = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 74 | ▶ | if ($g->phase eq 'discard') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 74 | ▶ | if ($cmd =~ /\A\d+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 71 | my ($kinds) = $self->rack_order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 71 | ▶ | my $t = $cmd >= 1 ? $kinds->[ $cmd - 1 ] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 71 | ▶ | return undef unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 71 | ▶ | my ($m) = grep { $_->{kind} eq 'discard' && $_->{tile} == $t } @$legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'kind'} eq 'discard' && $_->{'tile'} == $t
MC/DC50%1/2
$_->{'kind'} eq 'discard' && $_->{'tile'} == $t
$_->{'kind'} eq 'discard'
$_->{'tile'} == $t
Truth table66%2/3
A && B
A= $_->{'kind'} eq 'discard'B= $_->{'tile'} == $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 71 | return $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 3 | ▶ | if ($cmd eq 'd' || $cmd eq 'discard') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "d" or $cmd eq "discard"
MC/DC50%1/2
$cmd eq "d" or $cmd eq "discard"
$cmd eq "d"
$cmd eq "discard"
Truth table66%2/3
A or B
A= $cmd eq "d"B= $cmd eq "discard"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 2 | ▶ | my $t = $self->_parse_tile($args->[0]) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 1 | ▶ | my ($m) = grep { $_->{kind} eq 'discard' && $_->{tile} == $t } @$legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'kind'} eq 'discard' && $_->{'tile'} == $t
MC/DC0%0/2
$_->{'kind'} eq 'discard' && $_->{'tile'} == $t
$_->{'kind'} eq 'discard'
$_->{'tile'} == $t
Truth table33%1/3
A && B
A= $_->{'kind'} eq 'discard'B= $_->{'tile'} == $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 1 | return $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 1 | ▶ | if ($cmd eq 'kong') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | my @k = grep { $_->{kind} eq 'kong' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | return $k[0] if @k == 1 && !@$args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@k == 1 and not @$args
MC/DC0%0/2
@k == 1 and not @$args
@k == 1
not @$args
Truth table0%0/3
A and not(B)
A= @k == 1B= not @$args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | my $t = $self->_parse_tile($args->[0]) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my ($m) = grep { $_->{tile} == $t } @k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | return $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 1 | ▶ | if ($cmd eq 'win') { my ($m) = grep { $_->{kind} eq 'win' } @$legal; return $m } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | if ($cmd eq 'chow') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | my @c = grep { $_->{kind} eq 'chow' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | return $c[0] if @c == 1 && !@$args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@c == 1 and not @$args
MC/DC0%0/2
@c == 1 and not @$args
@c == 1
not @$args
Truth table0%0/3
A and not(B)
A= @c == 1B= not @$args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | my $n = $args->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | return undef unless defined $n && $n =~ /\A\d+\z/ && $c[ $n - 1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $n and $n =~ /\A\d+\z/ and $c[$n - 1]
defined $n and $n =~ /\A\d+\z/
MC/DC0%0/3
defined $n and $n =~ /\A\d+\z/ and $c[$n - 1]
defined $n
$n =~ /\A\d+\z/
$c[$n - 1]
Truth table0%0/4
A and B and C
A= defined $nB= $n =~ /\A\d+\z/C= $c[$n - 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | return $c[ $n - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my ($m) = grep { $_->{kind} eq $cmd } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | return $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 13 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=19 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 13 | my $g = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 13 | $self->say($self->_c('bold', 'Mahjong, the competition rules: sixteen hands, eight points to win.')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 13 | ▶ | $self->say('Seed ' . $self->seed . ', bots at level ' . $self->level . '. Type help for the commands.') unless $self->auto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 13 | $self->narrate($g->take_outcomes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 13 | my $shown = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 13 | ▶ | while ($g->is_active && !$self->quit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$g->is_active and not $self->quit
MC/DC50%1/2
$g->is_active and not $self->quit
$g->is_active
not $self->quit
Truth table66%2/3
A and not(B)
A= $g->is_activeB= not $self->quit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 5428 | my @waiting = $g->waiting_on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 5428 | ▶ | last unless @waiting; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 5428 | my ($seat) = grep { $_ == $self->seat } @waiting; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 5428 | ▶ | if (defined $seat && !$self->auto) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $seat and not $self->auto
MC/DC100%2/2
defined $seat and not $self->auto
defined $seat
not $self->auto
Truth table100%3/3
A and not(B)
A= defined $seatB= not $self->auto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 10 | my @legal = $g->legal($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 10 | ▶ | if ($shown != $g->moves) { $self->show_table; $shown = $g->moves } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 10 | $self->_describe_legal(@legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 10 | my $move = $self->read_move(@legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 10 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 1 | my $r = $g->apply($seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 1 | ▶ | if (ref $r && $r->can('error')) { $self->say('Refused: ' . $r->message); next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $r and $r->can("error")
MC/DC0%0/2
ref $r and $r->can("error")
ref $r
$r->can("error")
Truth table33%1/3
A and B
A= ref $rB= $r->can("error")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 1 | my @out = $g->take_outcomes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 1 | $self->narrate(@out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 5418 | my $bot_seat = $waiting[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 5418 | ▶ | if ($self->auto && $bot_seat == $self->seat && $g->phase eq 'discard' && $shown != $g->moves) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$self->auto and $bot_seat == $self->seat and $g->phase eq "discard" and $shown != $g->moves
$self->auto and $bot_seat == $self->seat and $g->phase eq "discard"
$self->auto and $bot_seat == $self->seat
MC/DC75%3/4
$self->auto and $bot_seat == $self->seat and $g->phase eq "discard" and $shown != $g->moves
$self->auto
$bot_seat == $self->seat
$g->phase eq "discard"
$shown != $g->moves
Truth table80%4/5
A and B and C and D
A= $self->autoB= $bot_seat == $self->seatC= $g->phase eq "discard"D= $shown != $g->moves
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 1007 | $self->show_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 1007 | $shown = $g->moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 5418 | ▶ | my $move = $self->bots->[$bot_seat]->choose($g, $bot_seat) or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 5418 | my $r = $g->apply($bot_seat, $move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 5418 | ▶ | die 'Game::Mahjong::Terminal: the bot was refused: ' . $r->code if ref $r && $r->can('error'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $r and $r->can("error")
MC/DC0%0/2
ref $r and $r->can("error")
ref $r
$r->can("error")
Truth table33%1/3
A and B
A= ref $rB= $r->can("error")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 5418 | $self->narrate($g->take_outcomes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 13 | ▶ | if ($self->quit) { $self->say('Goodbye.') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 13 | return $g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | mahjong: a game against three bots under the Chinese Official rules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | --seed STRING the game (the same seed deals the same tiles); a fresh one by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | --level 1..3 the bots' strength, 2 by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | --seat 0..3 your seat, 0 by default (seat 0 deals the first hand) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | --glyphs put the Unicode Mahjong Tiles block on the tile faces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | --ascii draw the tile frames with + - | for a terminal without box drawing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | --no-clear do not clear the screen before each table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | --no-colour plain text (colour is on when standard output is a terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | and NO_COLOR is unset) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | --no-pick type the moves out instead of pointing at them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | --auto four bots, no prompt: watch a game | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | --help this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | On a terminal the left and right keys walk your own rack and the tile under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | the cursor is the one you would throw. The line under it says what that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | leaves you: how far from a winning hand, and how many tiles would help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | Enter throws it, the number keys still work, ? lists the keys and q stops. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | Needs Term::ReadKey; without it, or off a terminal, every move is typed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | At a typed prompt: a number discards that tile, "help" lists the rest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | Exit status is 0 if you won or the game was drawn, 1 if you lost or stopped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | early, 2 for an option the game will not take. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | ▶ | my $tty = -t STDOUT ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | my %o = (level => 2, seat => 0, colour => ($tty && !$ENV{NO_COLOR} ? 1 : 0), glyphs => 0, auto => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tty and not $ENV{"NO_COLOR"}
MC/DC0%0/2
$tty and not $ENV{"NO_COLOR"}
$tty
not $ENV{"NO_COLOR"}
Truth table0%0/3
A and not(B)
A= $ttyB= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | ascii => 0, clear => $tty); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | ▶ | local $SIG{__WARN__} = sub { print STDERR "mahjong: $_[0]" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | Getopt::Long::GetOptionsFromArray(\@argv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 'seed=s' => \$o{seed}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 'level=i' => \$o{level}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 'seat=i' => \$o{seat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 'glyphs!' => \$o{glyphs}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 'colour!' => \$o{colour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 'color!' => \$o{colour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 'auto' => \$o{auto}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 'ascii!' => \$o{ascii}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 'clear!' => \$o{clear}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 'pick!' => \$o{pick}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 'help|h' => \$o{help}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | ▶ | if (!$ok) { print STDERR _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | ▶ | if ($o{help}) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | ▶ | if (@argv) { print STDERR "mahjong: not an option: $argv[0]\n", _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | $o{seed} //= sprintf('%s-%d', scalar(localtime), $$); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$o{"seed"} //= sprintf("%s-%d", scalar localtime, $$)
MC/DC0%0/2
$o{"seed"} //= sprintf("%s-%d", scalar localtime, $$)
$o{"seed"}
sprintf("%s-%d", scalar localtime, $$)
Truth table0%0/3
A //= B
A= $o{"seed"}B= sprintf("%s-%d", scalar localtime, $$)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | my $t = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | seed => $o{seed}, level => $o{level}, seat => $o{seat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | in => \*STDIN, out => \*STDOUT, colour => $o{colour}, glyphs => $o{glyphs}, auto => $o{auto}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | ascii => $o{ascii}, clear => $o{clear}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | (defined $o{pick} ? (picking => $o{pick} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | ▶ | unless ($t) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | ▶ | my $why = $@ || 'could not start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'could not start'
MC/DC0%0/1
$@ || 'could not start'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | $why =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | $why =~ s/\A[\w:]+: //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | chomp $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | print STDERR "mahjong: $why\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | ▶ | binmode $t->out, ':encoding(UTF-8)' unless $o{ascii}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | local @SIG{qw(INT TERM HUP)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | for my $sig (qw(INT TERM HUP)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | ▶ | $SIG{$sig} = sub { $t->leave_raw; $SIG{$sig} = 'DEFAULT'; kill $sig, $$ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | my $g = eval { $t->start }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | $t->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | ▶ | die $died if $died; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | ▶ | return 1 unless $t->finished; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | return 0 if $o{auto}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | ▶ | return 0 unless defined $t->winner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | ▶ | return 0 if $t->winner == $o{seat}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||