| 1 | package Game::Oware::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Game::Oware; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Game::Oware::Board; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Game::Oware::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Game::Oware::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Game::Oware::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use Game::Oware::Rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Game::Oware::Scoring; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use Game::Oware::Variant (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # The glyph tables. NOTE: this file is NOT under `use utf8`, so the wide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # glyphs are byte strings and `length` on anything built from them is a byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # count rather than a column count. Every cell below is therefore padded from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # a COUNT the caller already has, never from length(), and nothing here is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # ever passed to sprintf's %Ns. Get that wrong and the board shears by two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # columns per seed on a UTF-8 terminal and by none on a C-locale one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | my %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | h => '─', v => '│', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | tl => '╭', tr => '╮', bl => '╰', br => '╯', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | td => '┬', tu => '┴', lt => '├', rt => '┤', tx => '┼', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | seed => '•', more => '…', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | h => '-', v => '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | tl => '+', tr => '+', bl => '+', br => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | td => '+', tu => '+', lt => '+', rt => '+', tx => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | seed => '.', more => '>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | my $STORE_W = 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | my $HOUSE_W = 6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | my $SEED_CAP = 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | my %SGR = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | frame => '2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | letter => '36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | mine => '1;36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | store => '36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | storemine => '1;36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | empty => '2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | seed => '33', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | risk => '31', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | loaded => '1;33', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | emptied => '2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | gained => '32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | landed => '1;32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | captured => '7;31', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | forfeited => '1;33', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | prompt => '1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | cursor => '1;7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | my @TIMES = ('', 'once', 'twice', 'for the third time', 'for the fourth time'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # Term::ReadKey hands over one character at a time and leaves an escape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # sequence as the characters it is made of, so the arrow keys are named here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Same tables as Game::Checkers::Terminal, on purpose: two of this author's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # terminals reading the same keyboard should not disagree about what Home is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 10 | my %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 'A' => 'up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 'B' => 'down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 'C' => 'right', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 'H' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | '1~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | '4~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | '5~' => 'page_up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | '7~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | my %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | "\r" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | "\n" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | "\x7f" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | "\x03" => 'interrupt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | has in => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 53 | ▶ | default => sub { \*STDIN } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | has out => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | ▶ | default => sub { \*STDOUT } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | has level => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | default => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | has variant => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | default => 'abapa' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | has seat => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | default => 'p1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | has seed => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | default => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | has quiet => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | has ascii => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | has game => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | has bot => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | has raw => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 10 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | has recent => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | default => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | has pending => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | default => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | has _wants_ansi => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | init_arg => 'ansi', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | has _wants_progress => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | init_arg => 'progress', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | has _wants_interactive => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | init_arg => 'interactive', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | has _wants_picking => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | init_arg => 'picking', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 53 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 53 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 53 | Game::Oware::Variant::check_variant($self->variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 51 | ▶ | die 'Game::Oware::Terminal: seat must be p1 or p2, not ' . $self->seat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->seat eq "p1" or $self->seat eq "p2"
MC/DC100%2/2
$self->seat eq "p1" or $self->seat eq "p2"
$self->seat eq "p1"
$self->seat eq "p2"
Truth table100%3/3
A or B
A= $self->seat eq "p1"B= $self->seat eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | unless $self->seat eq 'p1' || $self->seat eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 49 | Game::Oware::Bot->setting_for($self->level); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 47 | ▶ | $self->game(Game::Oware->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | variant => $self->variant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | seed => $self->seed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | )) unless $self->game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 47 | ▶ | $self->bot(Game::Oware::Bot->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | level => $self->level, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | seed => $self->seed . ':bot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | )) unless $self->bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 47 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 23793 | ▶ | sub ansi { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ansi: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 23793 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 23793 | ▶ | return 0 if defined $ENV{NO_COLOR} && length $ENV{NO_COLOR}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ENV{"NO_COLOR"} and length $ENV{"NO_COLOR"}
MC/DC100%2/2
defined $ENV{"NO_COLOR"} and length $ENV{"NO_COLOR"}
defined $ENV{"NO_COLOR"}
length $ENV{"NO_COLOR"}
Truth table100%3/3
A and B
A= defined $ENV{"NO_COLOR"}B= length $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 23792 | ▶ | return $self->_wants_ansi ? 1 : 0 if defined $self->_wants_ansi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | return -t $self->out ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 611 | ▶ | sub interactive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 611 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 611 | ▶ | return $self->_wants_interactive ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | if defined $self->_wants_interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 326 | ▶ | return -t $self->out ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 570 | ▶ | sub progress { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
progress: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 570 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 570 | ▶ | return 0 if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 494 | ▶ | return $self->_wants_progress ? 1 : 0 if defined $self->_wants_progress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 494 | return $self->interactive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Read AND write: the `type` key turns picking off for the rest of the game, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # and `pick` turns it back on. Not a plain property because the default has to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # be computed from `in`, which the suite sets after construction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 817 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 817 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 817 | ▶ | $self->_wants_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 817 | ▶ | return 0 if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 774 | ▶ | return $self->_wants_picking ? 1 : 0 if defined $self->_wants_picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 508 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 511 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=5 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 511 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 511 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 510 | ▶ | return 0 unless defined $self->in && -t $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->in and -t $self->in
MC/DC0%0/2
defined $self->in and -t $self->in
defined $self->in
-t $self->in
Truth table33%1/3
A and B
A= defined $self->inB= -t $self->in
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 117 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 117 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 117 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 101 | ▶ | if ($self->keysource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 100 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 100 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # cbreak rather than raw, so an interrupt stays an interrupt instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # becoming a key this loop has to know about. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 101 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 101 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 101 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 100 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 100 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 100 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 176 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 176 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 176 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 176 | ▶ | return shift @$pending if @$pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 174 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Nothing there yet, and the rest of an escape sequence is worth one short | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # wait before the escape is taken for the key of that name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return Term::ReadKey::ReadKey(-1, $self->in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 136 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 136 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 136 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 136 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 134 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 41 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 21 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 20 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 20 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 20 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # A pressed escape key that happens to be followed by a real keystroke must | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # not eat it, so what is not the opening of a sequence goes back. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 20 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 18 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 18 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 20 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 20 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 20 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 20 | ▶ | last if $char =~ /[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 18 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$SEQUENCE{$tail} || 'escape'
$SEQUENCE{$tail}
Truth table50%1/2
A
A= $SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 462 | ▶ | sub rows_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows_for: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 462 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 462 | ▶ | return $seat eq 'p1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | ? ([ reverse 6 .. 11 ], [ 0 .. 5 ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | : ([ reverse 0 .. 5 ], [ 6 .. 11 ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 453 | ▶ | sub marks_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
marks_for: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 453 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 453 | ▶ | return {} unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 441 | my %mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 441 | my $house = $move->house; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 441 | $mark{$house} = '-'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # The sowing walk, so the mark on a house of twelve or more shows the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # origin staying empty while the hand goes past it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 441 | my $i = $house; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 441 | my $hand = $move->sown; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 441 | ▶ | while ($hand) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1144 | $i = ($i + 1) % Game::Oware::Board->HOUSES; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1144 | ▶ | next if $i == $house; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1129 | $mark{$i} = '+'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1129 | $hand--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 441 | $mark{ $move->last } = '*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 441 | $mark{$_} = '!' for @{ $move->forfeited }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 441 | $mark{$_} = 'x' for @{ $move->captured }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 441 | return \%mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 462 | ▶ | sub board_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_text: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 462 | my ($self, $from, $seat, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 462 | ▶ | $seat ||= $self->seat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$seat ||= $self->seat
MC/DC0%0/2
$seat ||= $self->seat
$seat
$self->seat
Truth table33%1/3
A ||= B
A= $seatB= $self->seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 462 | ▶ | $marks ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$marks ||= {}
MC/DC100%1/1
$marks ||= {}
$marks
Truth table100%2/2
A
A= $marks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # A game or a bare board, because the picker draws a position no game has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # been in: the one a candidate move would produce. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 462 | ▶ | my $board = ref $from eq 'ARRAY' ? $from : $from->board; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 462 | my $captured = Game::Oware::Scoring->captured($board); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 462 | my ($top, $bottom) = $self->rows_for($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 462 | my $them = Game::Oware::Board->other($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 462 | my $g = $self->_glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 462 | my $v = $self->_paint($g->{v}, 'frame'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 462 | my $house = $g->{h} x $HOUSE_W; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 462 | my $store = $g->{h} x $STORE_W; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 462 | my @left = $self->_store_cell($them, $captured->{$them}, 'store'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 462 | my @right = $self->_store_cell($seat, $captured->{$seat}, 'storemine'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 462 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 462 | push @out, $self->_letters($top, 'letter'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | push @out, $self->_paint($g->{tl} . $store . $g->{td} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 462 | . join($g->{td}, ($house) x 6) . $g->{td} . $store . $g->{tr}, 'frame'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 462 | push @out, $v . $left[0] . $v . $self->_seeds($board, $top, $marks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | . $v . $right[0] . $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 462 | push @out, $v . $left[1] . $v . $self->_counts($board, $top, $marks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | . $v . $right[1] . $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | push @out, $v . $left[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 462 | . $self->_paint($g->{lt} . join($g->{tx}, ($house) x 6) . $g->{rt}, 'frame') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | . $right[2] . $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 462 | push @out, $v . $left[3] . $v . $self->_counts($board, $bottom, $marks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | . $v . $right[3] . $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 462 | push @out, $v . $left[4] . $v . $self->_seeds($board, $bottom, $marks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | . $v . $right[4] . $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | push @out, $self->_paint($g->{bl} . $store . $g->{tu} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 462 | . join($g->{tu}, ($house) x 6) . $g->{tu} . $store . $g->{br}, 'frame'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 462 | push @out, $self->_letters($bottom, 'mine'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 462 | return @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 588 | ▶ | sub preview { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preview: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 588 | my ($self, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 588 | return Game::Oware::Rules->resolve( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | $self->game->board, $house, $self->seat, $self->variant); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 472 | ▶ | sub describe { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 472 | my ($self, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 472 | my (undef, $move) = $self->preview($house); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 472 | my $them = Game::Oware::Board->other($self->seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 472 | my @note = ('sows ' . $move->sown); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 472 | ▶ | push @note, 'right round, skipping ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | . Game::Oware::Notation->letter_of($house) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | if $move->sown >= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 472 | ▶ | if (@{ $move->forfeited }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | push @note, "would take every seed $them has, so takes none"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 472 | elsif (@{ $move->captured }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | push @note, 'captures ' . $move->taken . ' from ' . join ', ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 77 | map { Game::Oware::Notation->letter_of($_) } @{ $move->captured }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 77 | ▶ | push @note, "and the rest of the board goes to $them" if $move->slammed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 472 | return join ', ', @note; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 117 | ▶ | sub choice_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
choice_lines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 117 | my ($self, $legal, $at) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 117 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 117 | for my $index (0 .. $#$legal) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 472 | my $line = Game::Oware::Notation->letter_of($legal->[$index]) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | . ' ' . $self->describe($legal->[$index]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 472 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 472 | ▶ | push @lines, $index == $at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ? ' ' . $self->_paint("> $line", 'cursor') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | : " $line"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 117 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 117 | ▶ | sub legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 117 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 117 | 'arrows to choose, enter to sow, a letter to jump to that house', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 'v for the board as it stands, ? for the rules, t to type, q to quit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 101 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=27 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 101 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 101 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 101 | my $seat = $self->seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 101 | my @legal = @{ $game->legal($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 101 | ▶ | return 0 unless @legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # Asked for and not available: fall back to typing for good rather than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # failing the same way on every turn of the game. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 101 | ▶ | unless ($self->enter_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | return $self->_typed_turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 100 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 100 | my $live = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 100 | my @notice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 100 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 117 | $self->_show_choice(\@legal, $at, \@notice, $live); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 117 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 117 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 117 | ▶ | if (!defined $key || $key eq 'eof' || $key eq 'interrupt' || $key eq 'q') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/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/DC75%3/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 table80%4/5
not(A) or B or C or D
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"D= $key eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 9 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 9 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 108 | ▶ | if ($key eq 'up' || $key eq 'left') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "up" or $key eq "left"
MC/DC50%1/2
$key eq "up" or $key eq "left"
$key eq "up"
$key eq "left"
Truth table66%2/3
A or B
A= $key eq "up"B= $key eq "left"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | $at = ($at - 1) % @legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 107 | ▶ | if ($key eq 'down' || $key eq 'right' || $key eq 'tab') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$key eq "down" or $key eq "right" or $key eq "tab"
$key eq "down" or $key eq "right"
MC/DC33%1/3
$key eq "down" or $key eq "right" or $key eq "tab"
$key eq "down"
$key eq "right"
$key eq "tab"
Truth table50%2/4
A or B or C
A= $key eq "down"B= $key eq "right"C= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 9 | $at = ($at + 1) % @legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 98 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 98 | ▶ | if ($key eq 'end' || $key eq 'page_down') { $at = $#legal; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "end" or $key eq "page_down"
MC/DC50%1/2
$key eq "end" or $key eq "page_down"
$key eq "end"
$key eq "page_down"
Truth table66%2/3
A or B
A= $key eq "end"B= $key eq "page_down"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 97 | ▶ | if ($key eq 'enter' || $key eq ' ') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "enter" or $key eq " "
MC/DC50%1/2
$key eq "enter" or $key eq " "
$key eq "enter"
$key eq " "
Truth table66%2/3
A or B
A= $key eq "enter"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 87 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 87 | my $move = $game->play($seat, $legal[$at]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 87 | $self->_after_ply($move, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 87 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 10 | ▶ | if ($key =~ /\A[1-9]\z/ && $key <= @legal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key =~ /\A[1-9]\z/ and $key <= @legal
MC/DC50%1/2
$key =~ /\A[1-9]\z/ and $key <= @legal
$key =~ /\A[1-9]\z/
$key <= @legal
Truth table66%2/3
A and B
A= $key =~ /\A[1-9]\z/B= $key <= @legal
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | $at = $key - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # Not `b`, which is a house. See `command`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 9 | ▶ | if ($key eq 'v') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | $live = !$live; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # A HOUSE LETTER IS STILL THE INTERFACE. The letters are printed on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # board and against every option, so typing one has to land on it, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # typing one that is not on the list has to say why it is not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 8 | my $house = eval { Game::Oware::Notation->index_of($key) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 8 | ▶ | if (defined $house) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 3 | my ($found) = grep { $legal[$_] == $house } 0 .. $#legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 3 | ▶ | if (defined $found) { $at = $found; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 2 | @notice = (ucfirst($self->_why_not($house, $seat)) . '.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 5 | ▶ | if ($key eq '?') { @notice = $self->_help_lines; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 5 | ▶ | if ($key eq 't' || $key eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "t" or $key eq ":"
MC/DC100%2/2
$key eq "t" or $key eq ":"
$key eq "t"
$key eq ":"
Truth table100%3/3
A or B
A= $key eq "t"B= $key eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 4 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 4 | ▶ | $self->picking(0) if $key eq 't'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 4 | return $self->_typed_turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | @notice = ('That key does nothing here. Press ? for the ones that do.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 458 | ▶ | sub status_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_text: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 458 | my ($self, $from) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 458 | ▶ | $from ||= $self->game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$from ||= $self->game
MC/DC0%0/2
$from ||= $self->game
$from
$self->game
Truth table33%1/3
A ||= B
A= $fromB= $self->game
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 458 | ▶ | my $board = ref $from eq 'ARRAY' ? $from : $from->board; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 458 | my $play = Game::Oware::Board->seeds_on_side($board, 'p1') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | + Game::Oware::Board->seeds_on_side($board, 'p2'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 458 | return ' ' x ($STORE_W + 4) . $self->_paint($play . ' in play, ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | . Game::Oware::Variant::target($self->variant) . ' wins', 'frame'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 18 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 18 | ▶ | $self->_intro unless $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 18 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 18 | ▶ | $self->_show unless $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 18 | ▶ | while ($game->status eq 'active') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 576 | my ($turn) = $game->waiting_on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 576 | ▶ | last unless defined $turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 576 | ▶ | if ($turn eq $self->seat) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 291 | ▶ | last unless $self->_human_turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 285 | ▶ | last unless $self->_bot_turn($turn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 18 | $self->_finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 18 | return $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 224 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 224 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 224 | ▶ | return 'quit' unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 223 | $line =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 223 | ▶ | return 'again' unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 221 | ▶ | return 'quit' if $line =~ /\A(?:q|quit|exit)\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 211 | ▶ | return 'help' if $line =~ /\A(?:\?|h|help)\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 209 | ▶ | return 'board' if $line =~ /\Aboard\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 208 | ▶ | return 'pick' if $line =~ /\Apick\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 208 | ▶ | return 'type' if $line =~ /\Atype\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 208 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 5285 | ▶ | sub _glyphs { return $GLYPH{ $_[0]->ascii ? 'ascii' : 'wide' } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glyphs: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1323 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 1323 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 1323 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 1323 | print {$out} "$_\n" for @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 1323 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # A partial line, so the handle has to be flushed or a prompt sits in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # buffer while the bot thinks and the player stares at nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 217 | ▶ | sub _print { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 217 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 217 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 217 | print {$out} $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 217 | my $was = select $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 217 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 217 | select $was; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 217 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # An undef key is "leave it alone", which is what an ordinary house count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | # wants: paint every cell and the marked ones stop standing out. Only a call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # with no key at all takes the default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 23789 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 23789 | my ($self, $text, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 23789 | ▶ | return $text unless $self->ansi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 55 | ▶ | $key = 'prompt' if @_ < 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 55 | ▶ | return $text unless defined $key && defined $SGR{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $key and defined $SGR{$key}
MC/DC50%1/2
defined $key and defined $SGR{$key}
defined $key
defined $SGR{$key}
Truth table66%2/3
A and B
A= defined $keyB= defined $SGR{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 43 | return "\e[" . $SGR{$key} . 'm' . $text . "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 924 | ▶ | sub _letters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_letters: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 924 | my ($self, $houses, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 924 | my $row = ' ' x ($STORE_W + 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | $row .= $self->_paint(Game::Oware::Notation->letter_of($_), $key) . ' ' x 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 924 | for @$houses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 924 | $row =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 924 | return $row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 924 | ▶ | sub _store_cell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store_cell: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 924 | my ($self, $who, $count, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 924 | my $blank = ' ' x $STORE_W; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 924 | $blank, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | $self->_paint(sprintf(' %-2s ', $who), $key), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | $self->_paint(sprintf(' %2d ', $count), $key), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | $blank, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | $blank, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 924 | ▶ | sub _seeds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seeds: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 924 | my ($self, $board, $houses, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 924 | my $g = $self->_glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | return join $self->_paint($g->{v}, 'frame'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 924 | map { $self->_paint($self->_seed_text($board->[$_]), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 5544 | $self->_seed_key($board->[$_], $marks->{$_})) } @$houses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 924 | ▶ | sub _counts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_counts: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 924 | my ($self, $board, $houses, $marks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 924 | my $g = $self->_glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | return join $self->_paint($g->{v}, 'frame'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 924 | map { $self->_paint( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | sprintf(' %s %2d ', defined $marks->{$_} ? $marks->{$_} : ' ', $board->[$_]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 5544 | ▶ | $self->_count_key($board->[$_], $marks->{$_})) } @$houses; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 5544 | ▶ | sub _seed_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seed_text: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 5544 | my ($self, $count) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 5544 | ▶ | return ' ' x $HOUSE_W unless $count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # The overflow glyph is NOT a `+`: that is the mark for a house that gained | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # a seed, and the two sat one row apart meaning different things. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 2975 | my $g = $self->_glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 2975 | ▶ | return ' ' . ($g->{seed} x $SEED_CAP) . $g->{more} if $count > $SEED_CAP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 2028 | my $pad = int(($HOUSE_W - $count) / 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 2028 | return (' ' x $pad) . ($g->{seed} x $count) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | . (' ' x ($HOUSE_W - $pad - $count)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 5544 | ▶ | sub _seed_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seed_key: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 5544 | my ($self, $count, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 5544 | ▶ | return 'captured' if defined $mark && $mark eq 'x'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $mark and $mark eq "x"
MC/DC100%2/2
defined $mark and $mark eq "x"
defined $mark
$mark eq "x"
Truth table100%3/3
A and B
A= defined $markB= $mark eq "x"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 5484 | ▶ | return 'forfeited' if defined $mark && $mark eq '!'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $mark and $mark eq "!"
MC/DC0%0/2
defined $mark and $mark eq "!"
defined $mark
$mark eq "!"
Truth table66%2/3
A and B
A= defined $markB= $mark eq "!"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 5484 | ▶ | return 'empty' unless $count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 2975 | ▶ | return 'risk' if $count <= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 1538 | ▶ | return 'loaded' if $count >= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 1399 | return 'seed'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 5544 | ▶ | sub _count_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_count_key: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 5544 | my ($self, $count, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 5544 | ▶ | if (defined $mark) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 1525 | ▶ | return 'captured' if $mark eq 'x'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 1465 | ▶ | return 'forfeited' if $mark eq '!'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 1465 | ▶ | return 'landed' if $mark eq '*'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 1062 | ▶ | return 'gained' if $mark eq '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 441 | ▶ | return 'emptied' if $mark eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 4019 | ▶ | return 'empty' unless $count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 1951 | ▶ | return 'risk' if $count <= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 1086 | ▶ | return 'loaded' if $count >= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 985 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 344 | ▶ | sub _show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 344 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 344 | ▶ | return if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 341 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 341 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # A sweep rewrote the board after the move, so the move's marks would be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # pointing at counts that are no longer the ones it produced. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 341 | ▶ | my $swept = $result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$result && ($result->reason eq 'cycle' || $result->reason eq 'no_feed')
$result->reason eq "cycle" or $result->reason eq "no_feed"
MC/DC100%3/3
$result && ($result->reason eq 'cycle' || $result->reason eq 'no_feed')
$result
$result->reason eq "cycle"
$result->reason eq "no_feed"
Truth table100%4/4
A && B or C
A= $resultB= $result->reason eq "cycle"C= $result->reason eq "no_feed"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | && ($result->reason eq 'cycle' || $result->reason eq 'no_feed'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 341 | ▶ | $self->_say('', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | $self->board_text($game, $self->seat, $swept ? {} : $self->marks_for($move)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | $self->status_text($game)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 341 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 16 | ▶ | sub _legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legend: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 16 | ' ' . $self->_paint('-', 'emptied') . ' emptied ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | . $self->_paint('+', 'gained') . ' gained a seed ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | . $self->_paint('*', 'landed') . ' the last seed landed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | ' ' . $self->_paint('x', 'captured') . ' captured ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | . $self->_paint('!', 'forfeited') . ' capture forfeited', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 15 | ▶ | sub _intro { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_intro: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 15 | $self->_say( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 'Oware, ' . $self->variant . ' rules. You are ' . $self->seat . '.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 'Your six houses are the bottom row and your store is on the right.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 'Sow from one of them by typing its letter.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 'The marks say what the last move did:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | $self->_legend, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 'Type help for the rules that surprise people, or quit to stop.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 1 | ▶ | sub _help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_help: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 1 | $self->_say($self->_help_lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 1 | ▶ | sub _help_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_help_lines: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 1 | 'Take every seed from one of your houses and drop one in each house', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 'counter-clockwise, skipping the house you took them from.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 'If your last seed brings one of your opponent houses to exactly two or', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 'three, you capture it, and the walk continues backwards while that', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 'holds. Twenty-five seeds wins. Twenty-four each is a draw.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 'Three rules surprise people:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | ' - a move that would take EVERY seed your opponent has takes none;', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | ' - if your opponent has no seeds you must play a house that reaches', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | ' them, and if you cannot, you take your own seeds and the game ends;', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | ' - a game that will not end is stopped by a house rule, not a rule of', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | ' Oware. See the note when it happens.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 'The marks on the board:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | $self->_legend, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 'A house of one or two seeds is drawn in red, because that is what an', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 'opponent captures by bringing it to two or three. A house of twelve or', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 'more is drawn bright, because it laps the board.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 212 | ▶ | sub _prompt_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prompt_for: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 212 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 212 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 212 | my @legal = @{ $game->legal($seat) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 212 | my @sowable = Game::Oware::Rules->sowable($game->board, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 212 | ▶ | if (@sowable > @legal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 3 | my $them = Game::Oware::Board->other($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | $self->_say('', $them . ' has no seeds, so you must play a house that' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | . ' reaches them: ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 3 | . join(' ', map { Game::Oware::Notation->letter_of($_) } @legal)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 212 | return join ' ', map { Game::Oware::Notation->letter_of($_) } @legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 291 | ▶ | sub _human_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_human_turn: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 291 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 291 | ▶ | return $self->picking ? $self->pick : $self->_typed_turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | # The picker redraws the whole screen on every keystroke, so it clears first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | # scrolling six options past a nine line board is unreadable. Nothing here is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | # an escape the renderer owns, so it is gated on being interactive rather than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | # on `ansi`: a player with NO_COLOR set still wants a usable picker. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 117 | ▶ | sub _clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 117 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 117 | ▶ | return unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | $self->_print("\e[2J\e[H"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 117 | ▶ | sub _show_choice { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_choice: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 117 | my ($self, $legal, $at, $notice, $live) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 117 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 117 | my $seat = $self->seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 117 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | # THE ROUND SO FAR, every frame. The picker clears the screen on every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | # keystroke, so the narration printed when a move was played has already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | # gone by the time there is anything to choose. Both plies, not just the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # opponent's: a player who cannot see their own capture, or what it was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # answered with, is choosing in the dark. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 117 | my $recent = $self->recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | $self->_say($self->_narrate_lines($_->{move}, $_->{seat}, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 117 | for @$recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 117 | ▶ | $self->_say('') if @$recent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # THE BOARD DRAWN HERE IS THE ONE THE MOVE WOULD PRODUCE, not the one on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # the table with a path drawn over it. The first version did the latter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | # the way Game::Checkers highlights a jump, and it was wrong for this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | # game: the marks said where the seeds went while every count was still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | # the count from before they moved, so the cursor house read `- 1` for a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | # house it had just emptied. Here a capture shows the store going up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | # `v` swaps it for the position as it stands, carrying the opponent's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | # marks, because a preview is not a substitute for the board you are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # actually playing from. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 117 | my ($board, $marks, $title); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 117 | ▶ | if ($live) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 1 | $board = $game->board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 1 | ▶ | $marks = @$recent ? $self->marks_for($recent->[-1]{move}) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 1 | $title = ' as it stands:'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 116 | my $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 116 | ($board, $move) = $self->preview($legal->[$at]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 116 | $marks = $self->marks_for($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 116 | $title = ' if you sow ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | . Game::Oware::Notation->letter_of($legal->[$at]) . ':'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 117 | $self->_say( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | $title, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | $self->board_text($board, $seat, $marks), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | $self->status_text($board), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # The list holds only legal moves, so a player looking for a house the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | # feeding rule took away has nothing to read. Say it where the list is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 117 | my @sowable = Game::Oware::Rules->sowable($game->board, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 117 | ▶ | $self->_say(Game::Oware::Board->other($seat) . ' has no seeds, so only a' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | . ' house that reaches them can be played:', '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | if @sowable > @$legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 117 | $self->_say($self->choice_lines($legal, $at)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 117 | ▶ | $self->_say('', @$notice) if @$notice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 117 | $self->_say('', map { $self->_paint($_, 'frame') } $self->legend); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 117 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 2 | ▶ | sub _why_not { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_why_not: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 2 | my ($self, $house, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 2 | ▶ | my $flag = Game::Oware::Board->owner_of($house) ne $seat ? 'not_your_house' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | : !$self->game->board->[$house] ? 'empty_house' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | : 'must_feed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 2 | return Game::Oware::Error->throw($flag)->message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 212 | ▶ | sub _typed_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_typed_turn: called CC=11 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 212 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 212 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 212 | my $seat = $self->seat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 212 | my $in = $self->in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 212 | my $legal = $self->_prompt_for($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 212 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | # The newline belongs to the PROMPT, not to whatever answers it. On a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | # terminal the echoed Return supplies one; on a pipe it does not, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | # the first version of this loop printed every refusal, every help | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | # screen and every redrawn board onto the prompt's own line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 217 | $self->_print("\n" . $self->_paint('your move', 'prompt') . " [$legal] > "); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 217 | my $line = <$in>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 217 | my $command = $self->command($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 217 | ▶ | return 0 if $command eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 208 | ▶ | if ($command eq 'help') { $self->_say(''); $self->_help; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 207 | ▶ | if ($command eq 'again') { next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 206 | ▶ | if ($command eq 'board') { $self->_show; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 206 | ▶ | if ($command eq 'type') { $self->picking(0); next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 206 | ▶ | if ($command eq 'pick') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | $self->picking(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | ▶ | return $self->pick if $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | $self->_say('', 'The keys are not available here, so this game is' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | . ' typed. Term::ReadKey and a terminal are what it takes.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 206 | my $house = eval { Game::Oware::Notation->index_of($command) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 206 | ▶ | if (!defined $house) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 2 | $self->_say('', 'That is not a house. Type one of: ' . $legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 204 | my $out_of = $game->play($seat, $house); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 204 | ▶ | if (ref $out_of && $out_of->isa('Game::Oware::Error')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $out_of and $out_of->isa("Game::Oware::Error")
MC/DC50%1/2
ref $out_of and $out_of->isa("Game::Oware::Error")
ref $out_of
$out_of->isa("Game::Oware::Error")
Truth table66%2/3
A and B
A= ref $out_ofB= $out_of->isa("Game::Oware::Error")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 1 | $self->_say('', ucfirst($out_of->message) . '.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 203 | $self->_after_ply($out_of, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 203 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 285 | ▶ | sub _bot_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_turn: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 285 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 285 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 285 | $self->_thinking($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 285 | my $house = $self->bot->choose($game, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 285 | $self->_thought; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | # Unreachable while the engine ends a game the moment a seat has no legal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | # move. A `return` here instead would hand control back to a loop whose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | # condition has not changed, so the program would spin in silence. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 285 | ▶ | unless (defined $house) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | ▶ | $self->_say('', "$seat has no move, so the game cannot go on.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | unless $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 285 | my $move = $game->play($seat, $house); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 285 | $self->_after_ply($move, $seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 285 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 285 | ▶ | sub _thinking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_thinking: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 285 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 285 | ▶ | return unless $self->progress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | $self->_print($self->_paint("$seat is thinking", 'frame')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 285 | ▶ | sub _thought { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_thought: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 285 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 285 | ▶ | return unless $self->progress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | $self->_print("\r" . (' ' x 20) . "\r"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | # Everything one ply owes the screen, in one place, because the two front ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | # want opposite things from it. The typed game scrolls, so it narrates and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # redraws; the picker owns the screen and reprints both plies in its own header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | # on every keystroke, so anything drawn here would be a flash and nothing more. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 575 | ▶ | sub _after_ply { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_after_ply: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 575 | my ($self, $move, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # Recorded whether or not it is printed. The picker clears the screen on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | # every keystroke, so this is the only surviving copy of the round, and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | # player who cannot see their own capture or the reply to it is choosing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | # in the dark. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 575 | my $recent = $self->recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 575 | push @$recent, { move => $move, seat => $seat }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 575 | ▶ | shift @$recent while @$recent > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 575 | ▶ | return if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 499 | ▶ | return if $self->picking && $self->game->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->picking and $self->game->status eq "active"
MC/DC100%2/2
$self->picking and $self->game->status eq "active"
$self->picking
$self->game->status eq "active"
Truth table100%3/3
A and B
A= $self->pickingB= $self->game->status eq "active"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 329 | $self->_say('', $self->_narrate_lines($move, $seat)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 329 | $self->_show($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 329 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 495 | ▶ | sub _narrate_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_narrate_lines: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 495 | my ($self, $move, $seat, $past) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 495 | my $name = Game::Oware::Notation->letter_of($move->house); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 495 | my $them = Game::Oware::Board->other($seat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 495 | ▶ | my $sows = $past ? 'sowed' : 'sows'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 495 | my @lines = ($self->_paint("$seat $sows $name.", 'prompt')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 495 | ▶ | push @lines, ' The sow went right round, so it skipped ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | . "$name on the way past." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | if $move->sown >= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 495 | ▶ | if (@{ $move->forfeited }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | my $houses = join ', ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 1 | map { Game::Oware::Notation->letter_of($_) } @{ $move->forfeited }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 1 | push @lines, " That would have taken every seed $them has, from " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | . "$houses, so it takes none and they stay on the board."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 494 | elsif (@{ $move->captured }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | my $houses = join ', ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 47 | map { Game::Oware::Notation->letter_of($_) } @{ $move->captured }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 47 | push @lines, ' It captures ' . $move->taken . " seeds, from $houses."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 47 | ▶ | push @lines, ' Every seed left on the board goes to ' . $them . '.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | if $move->slammed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 495 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 18 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 18 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 18 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 18 | ▶ | unless ($result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 6 | ▶ | $self->_say('', 'Stopped. Nobody won.') unless $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 12 | my $reason = $result->reason; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 12 | ▶ | if ($reason eq 'no_feed' && !$self->quiet) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$reason eq "no_feed" and not $self->quiet
MC/DC50%1/2
$reason eq "no_feed" and not $self->quiet
$reason eq "no_feed"
not $self->quiet
Truth table66%2/3
A and not(B)
A= $reason eq "no_feed"B= not $self->quiet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 4 | my ($swept) = map { $_->{payload}{p} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 4 | grep { $_->{kind} eq 'sweep' } @{ $game->events }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 4 | $self->_say('', "$swept had no move that could give the other side seeds," | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | . ' so it took every seed in its own territory and the game ended.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | elsif ($reason eq 'cycle') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | # NOT narration, so quiet does not silence it. A game ended by a rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | # that no book contains has to say so however terse the output is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 2 | my ($cycle) = grep { $_->{kind} eq 'cycle' } @{ $game->events }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | my $times = $cycle->{payload}{times} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 2 | ▶ | || Game::Oware::Variant::repetition_limit($self->variant); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$cycle->{'payload'}{'times'} || Game::Oware::Variant::repetition_limit($self->variant)
MC/DC0%0/2
$cycle->{'payload'}{'times'} || Game::Oware::Variant::repetition_limit($self->variant)
$cycle->{'payload'}{'times'}
Game::Oware::Variant::repetition_limit($self->variant)
Truth table33%1/3
A || B
A= $cycle->{'payload'}{'times'}B= Game::Oware::Variant::repetition_limit($self->variant)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | my $why = $cycle->{payload}{why} eq 'repetition' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | ? 'the same position came round ' . _times($times) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 2 | ▶ | : $cycle->{payload}{plies} . ' moves passed with nothing captured'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 2 | $self->_say('', "This game was going nowhere: $why.", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 'So each side took the seeds on its own half.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 'THAT IS A HOUSE RULE AND NOT A RULE OF OWARE. The published rule', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 'ends a cycle when both players agree, which is not something this', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 'program can ask you.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 12 | $self->_say('', $self->_paint($result->stringify . '.', 'prompt')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 2 | ▶ | sub _times { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_times: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 2 | my ($count) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 2 | ▶ | return $TIMES[$count] if $count && $count <= $#TIMES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count and $count <= $#TIMES
MC/DC0%0/2
$count and $count <= $#TIMES
$count
$count <= $#TIMES
Truth table33%1/3
A and B
A= $countB= $count <= $#TIMES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | return "for the ${count}th time"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 9 | ▶ | sub _defaults { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 9 | level => 3, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | variant => 'abapa', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | seat => 'p1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | seed => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | quiet => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | ascii => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 2 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 2 | my %opt = _defaults(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 2 | my @levels = Game::Oware::Bot->levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 2 | my @variants = Game::Oware::Variant::variants(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 2 | my $levels = $levels[0] . ' to ' . $levels[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 2 | my $variants = join ' or ', @variants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 2 | return <<"USAGE"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | oware - play Oware against a bot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | Usage: oware [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | -l, --level N bot level, $levels (default $opt{level}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | -s, --seat SEAT the seat you play, p1 or p2 (default $opt{seat}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | -V, --variant V $variants (default $opt{variant}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | --seed STRING the seed, so a game can be replayed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | -q, --quiet only the result: no banner, narration or board | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | -a, --ascii plain box drawing, for a terminal without the glyphs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | --ansi force colour on, --no-ansi forces it off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | --no-pick type the moves out instead of choosing them with the keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | -v, --version print the version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | -h, --help this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | On a terminal the legal moves are listed under the board and chosen with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | arrow keys: the board above the list is the one the move under the cursor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | would produce, so a capture is seen before it is played. Enter sows it, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | house letter jumps to that house, t goes back to typing and ? prints the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | rules. Needs Term::ReadKey; without it, or off a terminal, the moves are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | typed out as a letter at a time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | The board marks what the last move did: - emptied, + gained a seed, * where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | the last seed landed, x captured, ! capture forfeited. Those are characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | rather than colours, so they survive --no-ansi and a redirected handle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | Levels $levels[-2] and $levels[-1] search a great deal deeper and take noticeably | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | longer a move. The budget is in nodes rather than seconds, so a loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | machine plays the same game as an idle one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | Exit status is 0 if you won or drew, 1 if you lost, 2 for a bad option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 7 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 7 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 7 | my $saved = Getopt::Long::Configure(qw(bundling no_ignore_case)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 7 | my $status = $class->_run(\@argv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 7 | Getopt::Long::Configure($saved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 7 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 7 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=18 SCAR=33.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 7 | my ($class, $argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 7 | my %opt = _defaults(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | Getopt::Long::GetOptionsFromArray($argv, \%opt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 'level|l=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 'variant|V=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 'seat|s=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 'seed=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 'quiet|q', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 'ascii|a', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 'ansi!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 'pick!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 'version|v', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 'help|h', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 7 | ▶ | ) or do { print STDERR _usage(); return 2 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 6 | ▶ | if ($opt{help}) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 5 | ▶ | if ($opt{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 1 | print "oware $Game::Oware::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 4 | ▶ | if (@{$argv}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | print STDERR "oware: there is nothing to do with '$argv->[0]': options begin with --\n", _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 4 | my $terminal = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | level => $opt{level}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | variant => $opt{variant}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | seat => $opt{seat}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | seed => $opt{seed}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | quiet => $opt{quiet} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | ascii => $opt{ascii} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | (exists $opt{ansi} ? (ansi => $opt{ansi} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 4 | ▶ | (exists $opt{pick} ? (picking => $opt{pick} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 4 | ▶ | unless ($terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 3 | ▶ | my $why = $@ || 'could not start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'could not start'
MC/DC0%0/1
$@ || 'could not start'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 3 | $why =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 3 | $why =~ s/\A[\w:]+: //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 3 | chomp $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 3 | print STDERR "oware: $why\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 3 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 1 | local @SIG{qw(INT TERM HUP)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 1 | for my $sig (qw(INT TERM HUP)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 3 | ▶ | $SIG{$sig} = sub { $terminal->leave_raw; $SIG{$sig} = 'DEFAULT'; kill $sig, $$ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 1 | my $result = eval { $terminal->start }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 1 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 1 | $terminal->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 1 | ▶ | die $died if $died; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 1 | ▶ | return 0 unless $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 0 | ▶ | return 0 if !defined $result->winner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | ▶ | return 0 if $result->winner eq $opt{seat}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||