| 1 | package Game::Merrills::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 68 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 68 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 68 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 68 | ▶ | use Game::Merrills; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 68 | ▶ | use Game::Merrills::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 68 | ▶ | use Game::Merrills::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 68 | ▶ | use Game::Merrills::Points; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 68 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 68 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 68 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 68 | PITCH => 4, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | WIDTH => 27, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ROWS => 13, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | RECENT => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 68 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 68 | our (%COMMAND, %GLYPH, %INK, %GROUND, %BRACKET, %SEQUENCE, %CONTROL, %KEY); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 68 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 68 | %COMMAND = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | help => 'this list', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | '?' => 'this list', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | moves => 'the legal moves, numbered: play one by its number', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | pick => 'choose a move with the arrow keys instead of typing it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | type => 'go back to typing moves out', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | hint => 'what the bot would play here', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | board => 'draw the board again', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | position => 'the position as one line of text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | undo => 'take back your last move, and the reply to it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'save FILE' => 'write the game out', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'load FILE' => 'read a game back in', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'level N' => 'set the strength of the bot, 1 to 5', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ascii => 'letters and dashes instead of drawn men and lines', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | colour => 'turn the colours on or off', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | draw => 'offer a draw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | accept => 'accept a draw that was offered', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | decline => 'turn a draw down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | resign => 'give the game up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | quit => 'stop playing', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 68 | %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | across => '-', down => '|', empty => '.', taken => 'x', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | white => 'W', black => 'B', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | across => "\x{2500}", down => "\x{2502}", empty => "\x{00B7}", taken => "\x{00D7}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | white => "\x{25CB}", black => "\x{25CF}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | painted => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | across => "\x{2500}", down => "\x{2502}", empty => "\x{00B7}", taken => "\x{00D7}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | white => "\x{25CF}", black => "\x{25CF}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 68 | %INK = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | line => '38;5;179', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | empty => '1;38;5;222', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | white => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | black => '1;38;5;16', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | bracket => '1;38;5;230', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | taken => '1;38;5;217', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | label => '38;5;109', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | title => '1;38;5;222', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | you => '1;38;5;120', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | them => '1;38;5;215', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | said => '38;5;250', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | turn => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | mill => '1;38;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | warn => '1;38;5;209', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | good => '1;38;5;120', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | hint => '38;5;117', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | dim => '38;5;244', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | step => '1;38;5;159', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | cursor => '1;38;5;16;48;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | key => '1;38;5;222', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 68 | %GROUND = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | board => '48;5;94', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | mill => '48;5;130', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | last => '48;5;25', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | left => '48;5;24', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | taken => '48;5;124', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | candidate => '48;5;28', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | takeable => '48;5;127', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | option => '48;5;58', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | chosen => '48;5;31', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 68 | %BRACKET = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | last => [ '(', ')' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | left => [ '(', ')' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | taken => [ '(', ')' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | candidate => [ '[', ']' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | takeable => [ '{', '}' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | chosen => [ '<', '>' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 68 | %SEQUENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'A' => 'up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'B' => 'down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'C' => 'right', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 'D' => 'left', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 'H' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 'F' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 'Z' => 'back_tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | '1~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | '4~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | '5~' => 'page_up', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | '6~' => 'page_down', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | '7~' => 'home', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | '8~' => 'end', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 68 | %CONTROL = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | "\r" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | "\n" => 'enter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | "\t" => 'tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | "\x7f" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | "\x08" => 'backspace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | "\x03" => 'interrupt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | "\x04" => 'eof', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 68 | %KEY = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | u => 'undo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | t => 'type', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | q => 'quit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 68 | my %OTHER = (white => 'black', black => 'white'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | has game => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | has bot => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | has human => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | default => 'white' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | has [qw/in out/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | has [qw/interactive colour/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | has ascii => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | has redraw => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | default => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | has highlight => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1016 | ▶ | default => sub { {} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | has recent => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1016 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | has picking => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | isa => Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | has raw => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | has keysource => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | isa => CodeRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | has [qw/pending heard/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2032 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | has preview => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | has frames => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1016 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=13 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1016 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1016 | ▶ | $self->game(Game::Merrills->new) unless $self->game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1016 | ▶ | die "human must be white, black, both or none, got '" . $self->human . "'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | unless $self->human =~ m/^(?:white|black|both|none)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1015 | ▶ | $self->in(\*STDIN) unless $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1015 | ▶ | $self->out(\*STDOUT) unless $self->out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1015 | ▶ | $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1015 | ▶ | $self->colour($self->interactive && !$ENV{NO_COLOR} ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->interactive and not $ENV{"NO_COLOR"}
MC/DC0%0/2
$self->interactive and not $ENV{"NO_COLOR"}
$self->interactive
not $ENV{"NO_COLOR"}
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | unless defined $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1015 | ▶ | $self->picking($self->interactive ? 1 : 0) unless defined $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1015 | ▶ | $self->picking(0) unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1015 | $self->layer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1015 | my $previous = select $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1015 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1015 | select $previous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1015 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1019 | ▶ | sub layer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
layer: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1019 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1019 | binmode $self->out, ':raw'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1019 | ▶ | binmode $self->out, ':encoding(UTF-8)' unless $self->ascii; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1019 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 77 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 77 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 77 | $self->say($self->paint("Nine Men's Morris.", 'title') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | . $self->paint(' Type help for the commands.', 'dim')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 77 | ▶ | $self->picking(0) if $self->picking && !$self->enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->picking and not $self->enter_raw
MC/DC0%0/2
$self->picking and not $self->enter_raw
$self->picking
not $self->enter_raw
Truth table66%2/3
A and not(B)
A= $self->pickingB= not $self->enter_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 77 | my $interrupt = $SIG{INT}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | local $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $SIG{INT} = defined $interrupt ? $interrupt : 'DEFAULT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | kill 'INT', $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 77 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 77 | my $played = eval { $self->turns; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 77 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 77 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 77 | ▶ | die $error unless $played; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 77 | return $self->game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 77 | ▶ | sub turns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turns: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 77 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 77 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 499 | ▶ | my $picking = $self->picking && $self->raw && $self->human ne 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->picking && $self->raw && $self->human ne 'none'
$self->picking and $self->raw
MC/DC66%2/3
$self->picking && $self->raw && $self->human ne 'none'
$self->picking
$self->raw
$self->human ne 'none'
Truth table75%3/4
A and B && C
A= $self->pickingB= $self->rawC= $self->human ne 'none'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 499 | ▶ | $self->render if $self->redraw && !$picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->redraw and not $picking
MC/DC100%2/2
$self->redraw and not $picking
$self->redraw
not $picking
Truth table100%3/3
A and not(B)
A= $self->redrawB= not $picking
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 499 | ▶ | if (my $result = $self->game->result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 18 | ▶ | $self->render if $picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 18 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 481 | ▶ | if ($self->bot_plays($self->game->turn)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 298 | $self->bot_move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 298 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 183 | ▶ | my $line = $picking ? $self->pick : $self->read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 183 | ▶ | unless (defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 57 | $self->say('Bye.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 57 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 126 | $self->heard([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 126 | my $stop = $self->command($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 126 | ▶ | $self->heard([]) unless $self->picking && $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->picking and $self->raw
MC/DC50%1/2
$self->picking and $self->raw
$self->picking
$self->raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 126 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 77 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1017 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=5 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1017 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1017 | ▶ | return 1 if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 128 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | return eval { require Term::ReadKey; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 36 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=5 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 36 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 36 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 36 | ▶ | if ($self->keysource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 35 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 35 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | return undef unless $self->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | return undef unless eval { Term::ReadKey::ReadMode(3, $self->in); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $self->raw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 121 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 121 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 121 | ▶ | return $self unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | ▶ | eval { Term::ReadKey::ReadMode(0, $self->in) } unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | $self->raw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 266 | ▶ | sub read_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_char: called CC=6 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 266 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 266 | my $pending = $self->pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 266 | ▶ | return shift @{$pending} if @{$pending}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 262 | ▶ | return $self->keysource->($wait) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $char = Term::ReadKey::ReadKey($wait ? 0 : -1, $self->in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | select undef, undef, undef, 0.05; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return Term::ReadKey::ReadKey(-1, $self->in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 229 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 229 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 229 | my $char = $self->read_char(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 229 | ▶ | return undef unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 214 | ▶ | return $CONTROL{$char} if $CONTROL{$char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 104 | ▶ | return $self->read_sequence if $char eq "\e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 85 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 19 | ▶ | sub read_sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_sequence: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 19 | my $opener = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 19 | ▶ | return 'escape' unless defined $opener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 19 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | unshift @{ $self->pending }, $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | return 'escape'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 15 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 15 | ▶ | while (length $tail < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 18 | my $char = $self->read_char(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 18 | ▶ | last unless defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 18 | $tail .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 18 | ▶ | last if $char =~ m/[A-Za-z~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 15 | ▶ | return $SEQUENCE{$tail} || 'escape'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Game::Merrills::Terminal::SEQUENCE{$tail} || 'escape'
MC/DC0%0/1
$Game::Merrills::Terminal::SEQUENCE{$tail} || 'escape'
$Game::Merrills::Terminal::SEQUENCE{$tail}
Truth table50%1/2
A
A= $Game::Merrills::Terminal::SEQUENCE{$tail}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 94123 | ▶ | sub components { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
components: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 94123 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 94123 | return [ grep { defined } $move->from, $move->to, $move->remove ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 4387 | ▶ | sub matching { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matching: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 4387 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 4387 | my @match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 4387 | MOVE: for my $move (@{ $self->game->legal_moves }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 71622 | my $parts = $self->components($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 71622 | ▶ | next if @{$parts} < @{$prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 69955 | for my $i (0 .. $#{$prefix}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 61853 | ▶ | next MOVE unless $parts->[$i] == $prefix->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 22639 | push @match, $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 4387 | return \@match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1791 | ▶ | sub options_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options_for: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1791 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1791 | my %next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1791 | for my $move (@{ $self->matching($prefix) }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 17519 | my $parts = $self->components($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 17519 | ▶ | $next{ $parts->[ scalar @{$prefix} ] } = 1 if @{$parts} > @{$prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1791 | return [ sort { $a <=> $b } keys %next ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 2478 | ▶ | sub complete { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 2478 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2478 | for my $move (@{ $self->matching($prefix) }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 4978 | ▶ | return $move if @{ $self->components($move) } == @{$prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 854 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 8316 | ▶ | sub nearest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nearest: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 8316 | my ($self, $from, $direction, $candidates) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 8316 | my ($row, $col) = (Game::Merrills::Points::row_of($from), Game::Merrills::Points::col_of($from)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 8316 | my ($best, $best_cost, $best_off); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 8316 | for my $point (@{$candidates}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 92991 | ▶ | next if $point == $from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 84676 | my $down = Game::Merrills::Points::row_of($point) - $row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 84676 | my $right = Game::Merrills::Points::col_of($point) - $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 84676 | ▶ | my ($along, $off) = $direction eq 'up' ? (-$down, abs $right) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | : $direction eq 'down' ? ($down, abs $right) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | : $direction eq 'left' ? (-$right, abs $down) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | : ($right, abs $down); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 84676 | ▶ | next unless $along > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 37278 | my $cost = $along + 2 * $off; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 37278 | ▶ | next if defined $best && ($cost > $best_cost || ($cost == $best_cost && $off >= $best_off)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $best and $cost > $best_cost || $cost == $best_cost && $off >= $best_off
$cost > $best_cost or $cost == $best_cost and $off >= $best_off
$cost == $best_cost and $off >= $best_off
MC/DC100%4/4
defined $best and $cost > $best_cost || $cost == $best_cost && $off >= $best_off
defined $best
$cost > $best_cost
$cost == $best_cost
$off >= $best_off
Truth table100%5/5
A and B or C and D
A= defined $bestB= $cost > $best_costC= $cost == $best_costD= $off >= $best_off
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 16013 | ($best, $best_cost, $best_off) = ($point, $cost, $off); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 8316 | ▶ | return defined $best ? $best : $from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 164 | ▶ | sub step_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 164 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 164 | my $placing = $self->game->phase eq 'placing'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 164 | ▶ | my @steps = $placing ? qw/to remove/ : qw/from to remove/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 164 | return $steps[ scalar @{$prefix} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 65 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=39 SCAR=36.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 65 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 65 | ▶ | return undef unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 64 | ▶ | return undef unless @{ $self->game->legal_moves }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 64 | my (@prefix, $at, $hinted); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 64 | my $notice = [ @{ $self->heard } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 64 | $self->heard([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 64 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 164 | my $options = $self->options_for(\@prefix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 164 | ▶ | if ($hinted && !(defined $at && grep { $_ == $at } @{$options})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$hinted and not defined $at && grep({$_ == $at;} @{$options;})
defined $at && grep({$_ == $at;} @{$options;})
MC/DC33%1/3
$hinted and not defined $at && grep({$_ == $at;} @{$options;})
$hinted
defined $at
grep({$_ == $at;} @{$options;})
Truth table50%2/4
A and not(B && C)
A= $hintedB= defined $atC= grep({$_ == $at;} @{$options;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | my $parts = $self->components($hinted); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 4 | my $follows = !grep { $parts->[$_] != $prefix[$_] } 0 .. $#prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 4 | ▶ | $at = $parts->[ scalar @prefix ] if $follows && @{$parts} > @prefix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$follows and @{$parts;} > @prefix
MC/DC0%0/2
$follows and @{$parts;} > @prefix
$follows
@{$parts;} > @prefix
Truth table33%1/3
A and B
A= $followsB= @{$parts;} > @prefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 164 | ▶ | $at = $options->[0] unless defined $at && grep { $_ == $at } @{$options}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $at and grep {$_ == $at;} @{$options;}
MC/DC50%1/2
defined $at and grep {$_ == $at;} @{$options;}
defined $at
grep {$_ == $at;} @{$options;}
Truth table66%2/3
A and B
A= defined $atB= grep {$_ == $at;} @{$options;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 164 | $self->show_choice(\@prefix, $options, $at, $notice); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 164 | $notice = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 164 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 164 | ▶ | if (!defined $key || $key eq 'eof' || $key eq 'interrupt') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC100%3/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table100%4/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 16 | $self->done_picking; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 16 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 148 | ▶ | if ($key =~ m/^(?:up|down|left|right)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | $at = $self->nearest($at, $key, $options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 146 | ▶ | if ($key eq 'tab' || $key eq 'j' || $key eq 'back_tab' || $key eq 'k') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$key eq "tab" or $key eq "j" or $key eq "back_tab" or $key eq "k"
$key eq "tab" or $key eq "j" or $key eq "back_tab"
$key eq "tab" or $key eq "j"
MC/DC75%3/4
$key eq "tab" or $key eq "j" or $key eq "back_tab" or $key eq "k"
$key eq "tab"
$key eq "j"
$key eq "back_tab"
$key eq "k"
Truth table80%4/5
A or B or C or D
A= $key eq "tab"B= $key eq "j"C= $key eq "back_tab"D= $key eq "k"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 29 | my ($index) = grep { $options->[$_] == $at } 0 .. $#{$options}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 29 | ▶ | $index += $key eq 'tab' || $key eq 'j' ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "tab" or $key eq "j"
MC/DC50%1/2
$key eq "tab" or $key eq "j"
$key eq "tab"
$key eq "j"
Truth table66%2/3
A or B
A= $key eq "tab"B= $key eq "j"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 29 | $at = $options->[ $index % @{$options} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 29 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 117 | ▶ | if ($key eq 'home' || $key eq 'page_up') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "home" or $key eq "page_up"
MC/DC50%1/2
$key eq "home" or $key eq "page_up"
$key eq "home"
$key eq "page_up"
Truth table66%2/3
A or B
A= $key eq "home"B= $key eq "page_up"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | $at = $options->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 116 | ▶ | if ($key eq 'end' || $key eq 'page_down') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "end" or $key eq "page_down"
MC/DC100%2/2
$key eq "end" or $key eq "page_down"
$key eq "end"
$key eq "page_down"
Truth table100%3/3
A or B
A= $key eq "end"B= $key eq "page_down"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | $at = $options->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 114 | ▶ | if ($key =~ m/^[a-gA-G]$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 28 | my $rank = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 28 | ▶ | my $point = defined $rank ? Game::Merrills::Points::point($key . $rank) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 28 | ▶ | if (defined $point && grep { $_ == $point } @{$options}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $point and grep {$_ == $point;} @{$options;}
MC/DC100%2/2
defined $point and grep {$_ == $point;} @{$options;}
defined $point
grep {$_ == $point;} @{$options;}
Truth table100%3/3
A and B
A= defined $pointB= grep {$_ == $point;} @{$options;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 26 | $at = $point; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 2 | ▶ | $notice = [ $self->paint( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | defined $point ? ucfirst(Game::Merrills::Points::name($point)) . ' cannot be chosen here.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | : 'A point is a letter and a number, like d2.', 'warn') ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 28 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 86 | ▶ | 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 " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 68 | push @prefix, $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 68 | undef $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 68 | ▶ | my $move = $self->complete(\@prefix) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 41 | $self->done_picking; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 41 | $self->played($self->game->move($move)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 41 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 18 | ▶ | if ($key eq 'backspace' || $key eq 'escape') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "backspace" or $key eq "escape"
MC/DC100%2/2
$key eq "backspace" or $key eq "escape"
$key eq "backspace"
$key eq "escape"
Truth table100%3/3
A or B
A= $key eq "backspace"B= $key eq "escape"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 7 | ▶ | if (@prefix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 5 | $at = pop @prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | $notice = [ $self->paint('There is nothing to go back over.', 'warn') ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 11 | ▶ | if ($key eq 'h') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 2 | my $hint = $self->hint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 2 | $notice = [ $self->paint($hint->{line}, 'hint') ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 2 | $hinted = $hint->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 2 | @prefix = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | undef $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 9 | ▶ | if ($key eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | $notice = $self->key_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 8 | ▶ | if ($key eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | $self->done_picking; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2 | return $self->read_line(': '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 6 | ▶ | if ($KEY{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 5 | $self->done_picking; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 5 | return $KEY{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | $notice = [ $self->paint('That key does nothing here. Press ? for the ones that do.', 'warn') ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 64 | ▶ | sub done_picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
done_picking: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 64 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 64 | $self->highlight({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 64 | $self->preview(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 64 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 164 | ▶ | sub show_choice { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_choice: called CC=27 SCAR=33.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 164 | my ($self, $prefix, $options, $at, $notice) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 164 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 164 | my $step = $self->step_of($prefix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 164 | my $side = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 164 | my %mark = map { $_ => 'option' } @{$options}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 164 | my @said; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 164 | my $board = $game->board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | my ($from, $to) = $step eq 'from' ? ($at, undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | : $step eq 'to' ? ($game->phase eq 'placing' ? undef : $prefix->[0], $at) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 164 | ▶ | : ($game->phase eq 'placing' ? (undef, $prefix->[0]) : @{$prefix}[ 0, 1 ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 164 | ▶ | if (defined $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 124 | ▶ | $board->set($from, undef) if defined $from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 124 | $board->set($to, $side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 124 | ▶ | $mark{$from} = 'left' if defined $from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 124 | $mark{$to} = 'chosen'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 164 | ▶ | if ($step eq 'to') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 118 | my @takes = grep { defined $_->remove } @{ $self->matching([ @{$prefix}, $at ]) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 118 | $mark{ $_->remove } = 'takeable' for @takes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 118 | $mark{$at} = 'candidate'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 118 | ▶ | push @said, $takes[0]->closes > 1 ? 'closes two mills' : 'closes a mill' if @takes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 118 | ▶ | push @said, 'a flight' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $from and not Game::Merrills::Points::is_adjacent($from, $at)
MC/DC100%2/2
defined $from and not Game::Merrills::Points::is_adjacent($from, $at)
defined $from
not Game::Merrills::Points::is_adjacent($from, $at)
Truth table100%3/3
A and not(B)
A= defined $fromB= not Game::Merrills::Points::is_adjacent($from, $at)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | if defined $from && !Game::Merrills::Points::is_adjacent($from, $at); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | elsif ($step eq 'remove') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 6 | $mark{$_} = 'takeable' for @{$options}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 6 | $mark{$at} = 'candidate'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 6 | push @said, 'takes this man'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 40 | $mark{$at} = 'candidate'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 164 | $self->preview($board); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 164 | $self->highlight(\%mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 164 | $self->frames($self->frames + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 164 | my $name = Game::Merrills::Points::name($at); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 164 | my ($index) = grep { $options->[$_] == $at } 0 .. $#{$options}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 164 | ▶ | my $ask = $step eq 'from' ? 'Choose a man to move.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
$step eq "to" and not defined $from
MC/DC100%2/2
$step eq "to" and not defined $from
$step eq "to"
not defined $from
Truth table100%3/3
A and not(B)
A= $step eq "to"B= not defined $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | : $step eq 'to' && !defined $from ? 'Choose a point to place a man on.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | : $step eq 'to' ? sprintf('Move %s to where?', Game::Merrills::Points::name($from)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | : defined $from ? sprintf('Move %s to %s and take which man?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | Game::Merrills::Points::name($from), Game::Merrills::Points::name($to)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | : sprintf('Place on %s and take which man?', Game::Merrills::Points::name($to)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 164 | ▶ | my $cursor = sprintf '> %s%s', $name, @said ? ', ' . join(', ', @said) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 164 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 164 | $self->say($_) for @{ $self->board_lines }, '', @{ $self->status_lines }, '', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | $self->paint($ask, 'step'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | ' ' . $self->paint($cursor, 'cursor') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 164 | . $self->paint(sprintf(' %d of %d', $index + 1, scalar @{$options}), 'dim'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 164 | ▶ | $self->say('') if $notice && @{$notice}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$notice and @{$notice;}
MC/DC50%1/2
$notice and @{$notice;}
$notice
@{$notice;}
Truth table66%2/3
A and B
A= $noticeB= @{$notice;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 164 | ▶ | $self->say($_) for @{ $notice || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$notice || []
MC/DC0%0/1
$notice || []
$notice
Truth table50%1/2
A
A= $notice
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 164 | $self->say(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 164 | $self->say($self->legend); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 164 | $self->redraw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 164 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 164 | ▶ | sub legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 164 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 164 | my @keys = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | [ 'arrows', 'move' ], [ 'tab', 'next' ], [ 'enter', 'choose' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | [ 'backspace', 'back' ], [ 'h', 'hint' ], [ 'u', 'undo' ], [ 't', 'type' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | [ 'q', 'quit' ], [ '?', 'help' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | return join $self->paint(' | ', 'dim'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 164 | map { $self->paint($_->[0], 'key') . ' ' . $self->paint($_->[1], 'dim') } @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 1 | ▶ | sub key_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 1 | 'The arrow keys move to the nearest point that can be chosen that way.', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 'Tab and shift-tab, or j and k, go round every one of them in turn.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 'A letter and a number, like d2, jump straight to that point.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 'Enter or space chooses. A move is chosen a step at a time: the man,', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 'where it goes, and the man it takes if it closes a mill.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 'Backspace or escape goes back a step. h shows what the bot would play.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 'u takes a move back, t goes back to typing, q quits, : types a command.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | ▶ | sub keyed_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keyed_line: called CC=9 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 16 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 16 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC0%0/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table25%1/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 16 | ▶ | last if $key eq 'enter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 14 | ▶ | if ($key eq 'backspace') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | next unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 1 | chop $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | print {$out} "\b \b"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 13 | ▶ | next if length $key > 1 || $key lt ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $key > 1 or $key lt " "
MC/DC0%0/2
length $key > 1 or $key lt " "
length $key > 1
$key lt " "
Truth table33%1/3
A or B
A= length $key > 1B= $key lt " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 13 | $line .= $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 13 | print {$out} $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 2 | print {$out} "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 2 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 3 | ▶ | sub set_picking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_picking: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 3 | my ($self, $word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 3 | ▶ | if ($word eq 'type') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | $self->redraw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 1 | $self->say('Type your moves. The command pick brings the keys back.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 2 | ▶ | return $self->say('This terminal cannot be read a key at a time.') && 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say('This terminal cannot be read a key at a time.') && 0
MC/DC0%0/1
$self->say('This terminal cannot be read a key at a time.') && 0
$self->say('This terminal cannot be read a key at a time.')
Truth table50%1/2
A
A= $self->say('This terminal cannot be read a key at a time.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | unless $self->enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | $self->picking(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 3 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=7 SCAR=20.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 3 | my ($self, $record) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 3 | my $moves = Game::Merrills::Notation::parse_record($record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 3 | my $position = Game::Merrills::Notation::record_position($record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 3 | ▶ | my $game = Game::Merrills->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | flying => $self->game->flying, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | defined $position ? (position => $position) : () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 3 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 3 | $self->recent([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 3 | $self->render; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 3 | my $number = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 3 | for my $move (@{$moves}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 60 | $number++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 60 | ▶ | if ($self->interactive) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | my $line = $self->read_line($self->paint('enter for the next move, q to stop: ', 'dim')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | ▶ | last if !defined $line || $line =~ m/^\s*q/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $line or $line =~ /^\s*q/i
MC/DC0%0/2
not defined $line or $line =~ /^\s*q/i
not defined $line
$line =~ /^\s*q/i
Truth table0%0/3
not(A) or B
A= not defined $lineB= $line =~ /^\s*q/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 60 | my $played = $game->move($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 60 | ▶ | die "illegal record: move $number, '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | . Game::Merrills::Notation::format_move($move) . "': " . $played->message . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | if ref $played eq 'Game::Merrills::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 59 | $self->played($played); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 59 | $self->render; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 2 | return $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 662 | ▶ | sub bot_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot_for: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 662 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 662 | my $bot = $self->bot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 662 | ▶ | return ref $bot eq 'HASH' ? $bot->{$side} : $bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 489 | ▶ | sub bot_plays { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot_plays: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 489 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 489 | ▶ | return 0 if $self->human eq 'both' || !$self->bot_for($side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->human eq "both" or not $self->bot_for($side)
MC/DC50%1/2
$self->human eq "both" or not $self->bot_for($side)
$self->human eq "both"
not $self->bot_for($side)
Truth table66%2/3
A or not(B)
A= $self->human eq "both"B= not $self->bot_for($side)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 349 | ▶ | return 1 if $self->human eq 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 69 | ▶ | return $side eq $self->human ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 298 | ▶ | sub bot_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot_move: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 298 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 298 | my $side = $self->game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 298 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 298 | ▶ | print {$out} $self->paint(ucfirst($side) . ' is thinking', 'dim') if $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 298 | my $move = $self->bot_for($side)->choose($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 298 | ▶ | print {$out} "\r\e[K" if $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 298 | ▶ | return undef unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 298 | $self->played($self->game->move($move)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 298 | return $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 440 | ▶ | sub played { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
played: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 440 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 440 | my $recent = $self->recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 440 | push @{$recent}, $self->narrate($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 440 | ▶ | shift @{$recent} while @{$recent} > RECENT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 440 | $self->redraw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 440 | return $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 445 | ▶ | sub name_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 445 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 445 | ▶ | return $side eq $self->human ? 'You' : ucfirst $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 445 | ▶ | sub narrate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
narrate: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 445 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 445 | my $who = $self->name_of($move->side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 445 | my $to = Game::Merrills::Points::name($move->to); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 445 | ▶ | my $text = $move->is_placement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | ? sprintf('%s placed a man on %s', $who, $to) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | : sprintf('%s %s %s to %s', $who, $move->flew ? 'flew' : 'moved', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | Game::Merrills::Points::name($move->from), $to); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 445 | ▶ | if ($move->is_capture) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 56 | my $victim = $OTHER{ $move->side }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 56 | ▶ | $text .= sprintf ', closed %s and took %s man on %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | $move->closes > 1 ? 'two mills' : 'a mill', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | $victim eq $self->human ? 'your' : "the $victim", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | Game::Merrills::Points::name($move->remove); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 445 | return $text . '.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 152 | ▶ | sub read_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_line: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 152 | my ($self, $prompt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 152 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 152 | ▶ | print {$out} defined $prompt ? $prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | : $self->paint($self->game->turn . '>', $self->ink_of($self->game->turn)) . ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 152 | ▶ | return $self->keyed_line if $self->raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 150 | my $line = readline $self->in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 150 | ▶ | unless (defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 53 | ▶ | print {$out} "\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 53 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 97 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 97 | ▶ | print {$out} "$line\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 97 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 12677 | ▶ | sub say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 12677 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 12677 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 12677 | ▶ | print {$out} (defined $line ? $line : ''), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 12677 | ▶ | push @{ $self->heard }, $line if defined $line && length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $line and length $line
MC/DC50%1/2
defined $line and length $line
defined $line
length $line
Truth table66%2/3
A and B
A= defined $lineB= length $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 12677 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 654 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=10.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 654 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 654 | ▶ | return $self unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | print {$out} "\e[2J\e[H"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 18239 | ▶ | sub paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paint: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 18239 | my ($self, $text, @keys) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 18239 | ▶ | return $text unless $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 333 | ▶ | my @codes = grep { defined } map { $INK{$_} || $GROUND{$_} } @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Game::Merrills::Terminal::INK{$_} || $Game::Merrills::Terminal::GROUND{$_}
MC/DC0%0/2
$Game::Merrills::Terminal::INK{$_} || $Game::Merrills::Terminal::GROUND{$_}
$Game::Merrills::Terminal::INK{$_}
$Game::Merrills::Terminal::GROUND{$_}
Truth table66%2/3
A || B
A= $Game::Merrills::Terminal::INK{$_}B= $Game::Merrills::Terminal::GROUND{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 333 | ▶ | return $text unless @codes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 333 | return "\e[" . join(';', @codes) . 'm' . $text . "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 2186 | ▶ | sub ink_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ink_of: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 2186 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 2186 | ▶ | return 'turn' if $self->human eq 'both' || $self->human eq 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->human eq "both" or $self->human eq "none"
MC/DC100%2/2
$self->human eq "both" or $self->human eq "none"
$self->human eq "both"
$self->human eq "none"
Truth table100%3/3
A or B
A= $self->human eq "both"B= $self->human eq "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 250 | ▶ | return $side eq $self->human ? 'you' : 'them'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 490 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 490 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 490 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 490 | $self->say($_) for @{ $self->board_lines }, '', @{ $self->status_lines }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 490 | $self->redraw(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 490 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 1388 | ▶ | sub glyphs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glyphs: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 1388 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 1388 | ▶ | return $GLYPH{ $self->ascii ? 'ascii' : $self->colour ? 'painted' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 694 | ▶ | sub marks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
marks: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 694 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 694 | my %mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 694 | ▶ | if (my $last = $self->game->history->[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 462 | ▶ | $mark{ $last->from } = 'left' if defined $last->from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 462 | ▶ | $mark{ $last->remove } = 'taken' if defined $last->remove; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 462 | $mark{ $last->to } = 'last'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 694 | my $extra = $self->highlight; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 694 | $mark{$_} = $extra->{$_} for keys %{$extra}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 694 | return \%mark; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 694 | ▶ | sub canvas { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canvas: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 694 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 694 | my @canvas = map { [ map { [ ' ', 'gap' ] } 1 .. WIDTH ] } 1 .. ROWS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 694 | for my $mill (Game::Merrills::Points::mills()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 11104 | for my $step (0, 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 22208 | my ($one, $two) = @{$mill}[ $step, $step + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 22208 | my ($row, $col) = (2 * Game::Merrills::Points::row_of($one), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1 + PITCH * Game::Merrills::Points::col_of($one)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 22208 | my ($end_row, $end_col) = (2 * Game::Merrills::Points::row_of($two), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 1 + PITCH * Game::Merrills::Points::col_of($two)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 22208 | ▶ | if ($row == $end_row) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 11104 | $canvas[$row][$_] = [ 'across', 'line' ] for $col + 1 .. $end_col - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 11104 | $canvas[$_][$col] = [ 'down', 'line' ] for $row + 1 .. $end_row - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 694 | ▶ | my $board = $self->preview || $self->game->board; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->preview || $self->game->board
MC/DC0%0/2
$self->preview || $self->game->board
$self->preview
$self->game->board
Truth table66%2/3
A || B
A= $self->previewB= $self->game->board
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 694 | my $marks = $self->marks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 694 | for my $point (Game::Merrills::Points::all_points()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 16656 | my ($row, $col) = (2 * Game::Merrills::Points::row_of($point), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 1 + PITCH * Game::Merrills::Points::col_of($point)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 16656 | my $side = $board->side_at($point); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 16656 | my $mark = $marks->{$point}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 16656 | ▶ | my $ground = $mark ? $mark : $side && $board->in_mill($point) ? 'mill' : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$side and $board->in_mill($point)
MC/DC100%2/2
$side and $board->in_mill($point)
$side
$board->in_mill($point)
Truth table100%3/3
A and B
A= $sideB= $board->in_mill($point)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 16656 | ▶ | $canvas[$row][$col] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%6/6
$mark and $mark eq "taken"
$mark and $mark eq "taken"
MC/DC100%2/2
$mark and $mark eq "taken"
$mark
$mark eq "taken"
MC/DC100%2/2
$mark and $mark eq "taken"
$mark
$mark eq "taken"
Truth table100%3/3
A and B
A= $markB= $mark eq "taken"
Truth table100%3/3
A and B
A= $markB= $mark eq "taken"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | $side ? $side : $mark && $mark eq 'taken' ? 'taken' : 'empty', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | $side ? $side : $mark && $mark eq 'taken' ? 'taken' : 'empty', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | $ground, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 16656 | ▶ | next unless $mark && $BRACKET{$mark}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mark and $Game::Merrills::Terminal::BRACKET{$mark}
MC/DC100%2/2
$mark and $Game::Merrills::Terminal::BRACKET{$mark}
$mark
$Game::Merrills::Terminal::BRACKET{$mark}
Truth table100%3/3
A and B
A= $markB= $Game::Merrills::Terminal::BRACKET{$mark}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 1036 | $canvas[$row][ $col - 1 ] = [ $BRACKET{$mark}[0], 'bracket', $mark ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 1036 | $canvas[$row][ $col + 1 ] = [ $BRACKET{$mark}[1], 'bracket', $mark ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 694 | return \@canvas; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 694 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 694 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 694 | my $glyph = $self->glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 694 | my $canvas = $self->canvas; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 694 | my @aside = @{ $self->aside }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 694 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 694 | for my $row (0 .. ROWS - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 9022 | my $drawn = WIDTH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 9022 | ▶ | my $label = $row % 2 ? ' ' : 7 - ($row / 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 9022 | ▶ | my $line = ($row % 2 ? ' ' : $self->paint($label, 'label')) . ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 9022 | ▶ | if ($self->colour) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 156 | my $code = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 156 | for my $cell (@{ $canvas->[$row] }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 4212 | my ($what, $kind, $ground) = @{$cell}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 4212 | ▶ | my $want = join ';', $INK{$kind} || $INK{line}, $GROUND{ $ground || 'board' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$Game::Merrills::Terminal::INK{$kind} || $Game::Merrills::Terminal::INK{'line'}
$ground || 'board'
MC/DC0%0/2
$Game::Merrills::Terminal::INK{$kind} || $Game::Merrills::Terminal::INK{'line'}
$Game::Merrills::Terminal::INK{$kind}
$Game::Merrills::Terminal::INK{'line'}
MC/DC100%1/1
$ground || 'board'
$ground
Truth table66%2/3
A || B
A= $Game::Merrills::Terminal::INK{$kind}B= $Game::Merrills::Terminal::INK{'line'}
Truth table100%2/2
A
A= $ground
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 4212 | ▶ | $line .= "\e[${want}m" unless $want eq $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 4212 | $code = $want; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 4212 | ▶ | $line .= defined $glyph->{$what} ? $glyph->{$what} : $what; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 156 | $line .= "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 239382 | ▶ | my $text = join '', map { defined $glyph->{ $_->[0] } ? $glyph->{ $_->[0] } : $_->[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 8866 | @{ $canvas->[$row] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 8866 | $text =~ s/ +$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 8866 | $drawn = length $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 8866 | $line .= $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 9022 | my $note = $aside[$row]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 9022 | ▶ | if (defined $note && length $note) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $note and length $note
MC/DC100%2/2
defined $note and length $note
defined $note
length $note
Truth table100%3/3
A and B
A= defined $noteB= length $note
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 3534 | $line .= ' ' x (2 + WIDTH - $drawn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 3534 | $line .= $note; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 9022 | $line =~ s/ +$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 9022 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 694 | push @lines, ' ' . join ' ', map { $self->paint($_, 'label') } 'a' .. 'g'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 694 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 694 | ▶ | sub aside { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aside: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 694 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 694 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 694 | my $glyph = $self->glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 694 | my @aside; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 694 | my $row = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 694 | for my $side (qw/white black/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 1388 | my $man = $self->paint($glyph->{$side}, $side, 'board'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 1388 | my $name = $self->paint(sprintf('%-5s', ucfirst $side), $self->ink_of($side)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 1388 | ▶ | $name .= $self->paint(' (you)', 'dim') if $side eq $self->human; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 1388 | $aside[$row] = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 1388 | $aside[ $row + 1 ] = sprintf 'in hand %d on the board %d lost %d', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | $game->in_hand($side), $game->on_board($side), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | Game::Merrills::Board::MEN - $game->men($side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 1388 | my $hand = $game->in_hand($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | $aside[ $row + 2 ] = $hand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 1388 | ▶ | ? join ' ', ($self->colour ? $man : $glyph->{$side}) x $hand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 1388 | $row += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 694 | return \@aside; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 1342 | ▶ | sub mills_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mills_of: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 1342 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 1342 | my $board = $self->game->board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 1342 | my @mills; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 1342 | for my $mill (Game::Merrills::Points::mills()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 21472 | ▶ | next if grep { ($board->side_at($_) || '') ne $side } @{$mill}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$board->side_at($_) || ''
MC/DC100%1/1
$board->side_at($_) || ''
$board->side_at($_)
Truth table100%2/2
A
A= $board->side_at($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 258 | push @mills, join '-', map { Game::Merrills::Points::name($_) } @{$mill}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 1342 | return \@mills; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 671 | ▶ | sub status_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_lines: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 671 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 671 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 671 | my @lines = map { $self->paint($_, 'said') } @{ $self->recent }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 671 | for my $side (qw/white black/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 1342 | my $mills = $self->mills_of($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 1342 | ▶ | next unless @{$mills}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | push @lines, $self->paint( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 247 | sprintf('%s %s: %s', ucfirst $side, @{$mills} == 1 ? 'mill' : 'mills', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 247 | ▶ | join ', ', @{$mills}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 'mill' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 671 | ▶ | if (my $result = $game->result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 21 | ▶ | push @lines, $self->paint($result->stringify, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | $result->is_draw ? 'mill' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | : $result->winner eq $self->human ? 'good' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | : $self->human =~ m/^(?:white|black)$/ ? 'warn' : 'good'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 21 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 650 | my $turn = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 650 | ▶ | my $who = ucfirst($turn) . ($turn eq $self->human ? ' (you)' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 650 | my $phase = $game->phase; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 650 | ▶ | push @lines, $self->paint( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | $phase eq 'placing' ? sprintf('%s to place, %d in hand.', $who, $game->in_hand($turn)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | : $phase eq 'flying' ? sprintf('%s to move, and flying.', $who) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | : sprintf('%s to move.', $who), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | $self->ink_of($turn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 650 | my $limit = $Game::Merrills::NO_MILL_LIMIT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 650 | ▶ | push @lines, $self->paint( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$limit and $game->no_mill * 2 >= $limit
MC/DC50%1/2
$limit and $game->no_mill * 2 >= $limit
$limit
$game->no_mill * 2 >= $limit
Truth table66%2/3
A and B
A= $limitB= $game->no_mill * 2 >= $limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | sprintf('No mill for %d moves: it is a draw at %d.', $game->no_mill, $limit), 'warn' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | ) if $limit && $game->no_mill * 2 >= $limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 650 | ▶ | push @lines, $self->paint( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | sprintf('%s has offered a draw: accept or decline.', ucfirst $game->draw_offered_by), 'hint' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | ) if $game->draw_offered_by; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 650 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 131 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=25 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 131 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 131 | $line =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 131 | ▶ | return 0 unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 100 | my ($word, $argument) = split ' ', $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 100 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 100 | ▶ | return $self->show_help if $word eq 'help' || $word eq '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$word eq "help" or $word eq "?"
MC/DC100%2/2
$word eq "help" or $word eq "?"
$word eq "help"
$word eq "?"
Truth table100%3/3
A or B
A= $word eq "help"B= $word eq "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 97 | ▶ | return $self->redraw(1) && 0 if $word eq 'board'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->redraw(1) && 0
MC/DC0%0/1
$self->redraw(1) && 0
$self->redraw(1)
Truth table50%1/2
A
A= $self->redraw(1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 96 | ▶ | return $self->show_moves if $word eq 'moves'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 92 | ▶ | return $self->set_picking($word) if $word eq 'pick' || $word eq 'type'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$word eq "pick" or $word eq "type"
MC/DC100%2/2
$word eq "pick" or $word eq "type"
$word eq "pick"
$word eq "type"
Truth table100%3/3
A or B
A= $word eq "pick"B= $word eq "type"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 89 | ▶ | return $self->show_hint if $word eq 'hint'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 85 | ▶ | return $self->say($self->game->to_position) && 0 if $word eq 'position'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say($self->game->to_position) && 0
MC/DC0%0/1
$self->say($self->game->to_position) && 0
$self->say($self->game->to_position)
Truth table50%1/2
A
A= $self->say($self->game->to_position)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 80 | ▶ | return $self->take_back if $word eq 'undo'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 76 | ▶ | return $self->save($argument) if $word eq 'save'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 72 | ▶ | return $self->load($argument) if $word eq 'load'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 68 | ▶ | return $self->set_level($argument) if $word eq 'level'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 65 | ▶ | return $self->toggle($word) if $word eq 'ascii' || $word eq 'colour' || $word eq 'color'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$word eq "ascii" or $word eq "colour" or $word eq "color"
$word eq "ascii" or $word eq "colour"
MC/DC100%3/3
$word eq "ascii" or $word eq "colour" or $word eq "color"
$word eq "ascii"
$word eq "colour"
$word eq "color"
Truth table100%4/4
A or B or C
A= $word eq "ascii"B= $word eq "colour"C= $word eq "color"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 61 | ▶ | return $self->offer_draw if $word eq 'draw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 56 | ▶ | return $self->answer_draw($word) if $word eq 'accept' || $word eq 'decline'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$word eq "accept" or $word eq "decline"
MC/DC100%2/2
$word eq "accept" or $word eq "decline"
$word eq "accept"
$word eq "decline"
Truth table100%3/3
A or B
A= $word eq "accept"B= $word eq "decline"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 53 | ▶ | return $self->resign if $word eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 48 | ▶ | return $self->quit if $word eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 45 | ▶ | return $self->play_number($word) if $word =~ m/^[0-9]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 40 | return $self->play($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 40 | ▶ | sub play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 40 | my ($self, $notation) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 40 | my $move = $self->game->move($notation); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 40 | ▶ | unless (ref $move eq 'Game::Merrills::Error') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 36 | $self->played($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 36 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 4 | $self->say($self->paint(ucfirst($move->message) . '.', 'warn')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 4 | ▶ | $self->say('Type moves for the list, or help for the commands.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | if $move->not_a_move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 4 | my @legal = @{ $move->legal }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 4 | ▶ | $self->say('You could play: ' . join(', ', map { $_->notation } @legal[ 0 .. ($#legal > 11 ? 11 : $#legal) ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
@legal and not $move->not_a_move and not $move->game_over
@legal and not $move->not_a_move
MC/DC33%1/3
@legal and not $move->not_a_move and not $move->game_over
@legal
not $move->not_a_move
not $move->game_over
Truth table50%2/4
A and not(B) and not(C)
A= @legalB= not $move->not_a_moveC= not $move->game_over
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | . (@legal > 12 ? sprintf(', and %d more', @legal - 12) : '') . '.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | if @legal && !$move->not_a_move && !$move->game_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 5 | ▶ | sub play_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_number: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 5 | my ($self, $number) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 5 | my $legal = $self->game->legal_moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | return $self->say("There is no move $number. Type moves for the list.") && 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 5 | ▶ | unless $number >= 1 && $number <= @{$legal}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$number >= 1 and $number <= @{$legal;}
$self->say("There is no move $number. Type moves for the list.") && 0
MC/DC100%2/2
$number >= 1 and $number <= @{$legal;}
$number >= 1
$number <= @{$legal;}
MC/DC0%0/1
$self->say("There is no move $number. Type moves for the list.") && 0
$self->say("There is no move $number. Type moves for the list.")
Truth table100%3/3
A and B
A= $number >= 1B= $number <= @{$legal;}
Truth table50%1/2
A
A= $self->say("There is no move $number. Type moves for the list.")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 3 | $self->played($self->game->move($legal->[ $number - 1 ])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 4 | ▶ | sub show_moves { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_moves: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 4 | my $legal = $self->game->legal_moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 4 | ▶ | return $self->say('There is nothing to play.') && 0 unless @{$legal}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->say('There is nothing to play.') && 0
MC/DC0%0/1
$self->say('There is nothing to play.') && 0
$self->say('There is nothing to play.')
Truth table0%0/2
A
A= $self->say('There is nothing to play.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 4 | my @cells = map { sprintf '%2d. %-9s', $_ + 1, $legal->[$_]->notation } 0 .. $#{$legal}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 4 | ▶ | while (my @row = splice @cells, 0, 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 23 | my $text = join ' ', @row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 23 | $text =~ s/ +$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 23 | $self->say($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 4 | $self->say('Play one by its number, or type it out.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 7 | ▶ | sub hint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hint: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 7 | ▶ | my $bot = $self->bot_for($OTHER{ $self->game->turn }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->bot_for($OTHER{$self->game->turn}) || $self->bot_for($self->game->turn) || 'Game::Merrills::Bot'->new
$self->bot_for($OTHER{$self->game->turn}) or $self->bot_for($self->game->turn)
MC/DC0%0/3
$self->bot_for($OTHER{$self->game->turn}) || $self->bot_for($self->game->turn) || 'Game::Merrills::Bot'->new
$self->bot_for($OTHER{$self->game->turn})
$self->bot_for($self->game->turn)
'Game::Merrills::Bot'->new
Truth table50%2/4
A or B || C
A= $self->bot_for($OTHER{$self->game->turn})B= $self->bot_for($self->game->turn)C= 'Game::Merrills::Bot'->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | || $self->bot_for($self->game->turn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | || Game::Merrills::Bot->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 7 | my $move = $bot->choose($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 7 | ▶ | return { line => 'There is nothing to play.' } unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 6 | my $score = $bot->last_search->{score}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 6 | ▶ | move => $move, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | line => sprintf('Try %s%s.', $move->notation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | defined $score ? sprintf(' (it scores that %+.2f)', $score / 100) : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 4 | ▶ | sub show_hint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_hint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 4 | $self->say($self->paint($self->hint->{line}, 'hint')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 4 | ▶ | sub take_back { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
take_back: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 4 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 4 | ▶ | return $self->say('There is nothing to take back.') && 0 unless @{ $game->history }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say('There is nothing to take back.') && 0
MC/DC0%0/1
$self->say('There is nothing to take back.') && 0
$self->say('There is nothing to take back.')
Truth table50%1/2
A
A= $self->say('There is nothing to take back.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 3 | $game->undo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 3 | ▶ | $game->undo if @{ $game->history } && $self->bot_plays($game->turn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$game->history;} and $self->bot_plays($game->turn)
MC/DC50%1/2
@{$game->history;} and $self->bot_plays($game->turn)
@{$game->history;}
$self->bot_plays($game->turn)
Truth table66%2/3
A and B
A= @{$game->history;}B= $self->bot_plays($game->turn)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 3 | $self->recent([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 3 | $self->later('Taken back.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 4 | ▶ | sub later { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
later: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 4 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 4 | ▶ | if ($self->picking && $self->raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->picking and $self->raw
MC/DC50%1/2
$self->picking and $self->raw
$self->picking
$self->raw
Truth table66%2/3
A and B
A= $self->pickingB= $self->raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 1 | $self->redraw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 3 | $self->render; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 4 | $self->say($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 4 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 4 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 4 | ▶ | return $self->say('Save needs a file name.') && 0 unless $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say('Save needs a file name.') && 0
MC/DC0%0/1
$self->say('Save needs a file name.') && 0
$self->say('Save needs a file name.')
Truth table50%1/2
A
A= $self->say('Save needs a file name.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 3 | ▶ | open my $handle, '>', $file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say("Cannot write ${file}: $!") && 0
MC/DC0%0/1
$self->say("Cannot write ${file}: $!") && 0
$self->say("Cannot write ${file}: $!")
Truth table50%1/2
A
A= $self->say("Cannot write ${file}: $!")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | or return $self->say("Cannot write $file: $!") && 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 2 | print {$handle} $self->game->to_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 2 | close $handle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 2 | $self->say("Saved to $file."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 4 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 4 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 4 | ▶ | return $self->say('Load needs a file name.') && 0 unless $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say('Load needs a file name.') && 0
MC/DC0%0/1
$self->say('Load needs a file name.') && 0
$self->say('Load needs a file name.')
Truth table50%1/2
A
A= $self->say('Load needs a file name.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 3 | ▶ | open my $handle, '<', $file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say("Cannot read ${file}: $!") && 0
MC/DC0%0/1
$self->say("Cannot read ${file}: $!") && 0
$self->say("Cannot read ${file}: $!")
Truth table50%1/2
A
A= $self->say("Cannot read ${file}: $!")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | or return $self->say("Cannot read $file: $!") && 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 2 | my $text = do { local $/; <$handle> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 2 | close $handle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 2 | my $game = eval { Game::Merrills->from_text($text, flying => $self->game->flying) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 2 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1 | my $why = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 1 | $why =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 1 | ▶ | return $self->say("That is not a game I can read: $why") && 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->say("That is not a game I can read: $why") && 0
MC/DC0%0/1
$self->say("That is not a game I can read: $why") && 0
$self->say("That is not a game I can read: $why")
Truth table50%1/2
A
A= $self->say("That is not a game I can read: $why")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 1 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 1 | $self->recent([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 1 | $self->later("Loaded $file, " . scalar(@{ $game->history }) . ' moves in.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 3 | ▶ | sub set_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_level: called CC=7 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 3 | my ($self, $level) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 3 | ▶ | return $self->say('Level takes a number from 1 to 5.') && 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
defined $level and $level =~ /^[1-5]$/
$self->say('Level takes a number from 1 to 5.') && 0
MC/DC100%2/2
defined $level and $level =~ /^[1-5]$/
defined $level
$level =~ /^[1-5]$/
MC/DC0%0/1
$self->say('Level takes a number from 1 to 5.') && 0
$self->say('Level takes a number from 1 to 5.')
Truth table100%3/3
A and B
A= defined $levelB= $level =~ /^[1-5]$/
Truth table50%1/2
A
A= $self->say('Level takes a number from 1 to 5.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | unless defined $level && $level =~ m/^[1-5]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1 | my $bot = $self->bot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 1 | ▶ | if (ref $bot eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | $bot->{$_} = Game::Merrills::Bot->new(level => $level, seed => $bot->{$_}->seed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | for grep { $bot->{$_} } keys %{$bot}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 1 | ▶ | $self->bot(Game::Merrills::Bot->new(level => $level, seed => $bot ? $bot->seed : 0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 1 | $self->say("The bot is at level $level."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 4 | ▶ | sub toggle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toggle: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 4 | my ($self, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 4 | ▶ | $what = 'colour' if $what eq 'color'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 4 | ▶ | $self->$what($self->$what ? 0 : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 4 | $self->layer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 4 | $self->redraw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 5 | ▶ | sub offer_draw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer_draw: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 5 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 5 | ▶ | my $side = $self->human =~ m/^(?:white|black)$/ ? $self->human : $game->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 5 | my $offered = $game->offer_draw($side); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 5 | ▶ | return $self->say(ucfirst($offered->message) . '.') && 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->say(ucfirst($offered->message) . '.') && 0
MC/DC0%0/1
$self->say(ucfirst($offered->message) . '.') && 0
$self->say(ucfirst($offered->message) . '.')
Truth table0%0/2
A
A= $self->say(ucfirst($offered->message) . '.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | if ref $offered eq 'Game::Merrills::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 5 | ▶ | my $bot = $self->bot_plays($OTHER{$side}) ? $self->bot_for($OTHER{$side}) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 5 | ▶ | unless ($bot) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 2 | $self->say(ucfirst($side) . ' offers a draw. ' . ucfirst($OTHER{$side}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | . ' may accept or decline.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 3 | ▶ | my $score = $bot->last_search ? $bot->last_search->{score} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 3 | ▶ | if (defined $score && $score <= 30) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $score and $score <= 30
MC/DC50%1/2
defined $score and $score <= 30
defined $score
$score <= 30
Truth table66%2/3
A and B
A= defined $scoreB= $score <= 30
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 2 | $game->accept_draw($OTHER{$side}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 2 | $self->say('The bot takes the draw.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 2 | $self->redraw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 1 | $game->decline_draw($OTHER{$side}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 1 | $self->say('The bot plays on.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 3 | ▶ | sub answer_draw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
answer_draw: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 3 | my ($self, $word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 3 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 3 | my $offered = $game->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 3 | ▶ | my $side = $offered ? $OTHER{$offered} : $game->turn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 3 | ▶ | my $answer = $word eq 'accept' ? $game->accept_draw($side) : $game->decline_draw($side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 3 | ▶ | return $self->say(ucfirst($answer->message) . '.') && 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->say(ucfirst($answer->message) . '.') && 0
MC/DC0%0/1
$self->say(ucfirst($answer->message) . '.') && 0
$self->say(ucfirst($answer->message) . '.')
Truth table50%1/2
A
A= $self->say(ucfirst($answer->message) . '.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | if ref $answer eq 'Game::Merrills::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 2 | ▶ | return $self->redraw(1) && 0 if $word eq 'accept'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->redraw(1) && 0
MC/DC0%0/1
$self->redraw(1) && 0
$self->redraw(1)
Truth table50%1/2
A
A= $self->redraw(1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 1 | $self->say(ucfirst($side) . ' plays on.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 6 | ▶ | sub resign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resign: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 6 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 6 | ▶ | my $resigned = $game->resign($self->human =~ m/^(?:white|black)$/ ? $self->human : $game->turn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 6 | ▶ | return $self->say(ucfirst($resigned->message) . '.') && 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->say(ucfirst($resigned->message) . '.') && 0
MC/DC0%0/1
$self->say(ucfirst($resigned->message) . '.') && 0
$self->say(ucfirst($resigned->message) . '.')
Truth table0%0/2
A
A= $self->say(ucfirst($resigned->message) . '.')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | if ref $resigned eq 'Game::Merrills::Error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 6 | $self->redraw(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 6 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 3 | ▶ | sub quit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quit: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 3 | ▶ | return 1 unless $self->game->status eq 'active' && @{ $self->game->history }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->game->status eq "active" and @{$self->game->history;}
MC/DC50%1/2
$self->game->status eq "active" and @{$self->game->history;}
$self->game->status eq "active"
@{$self->game->history;}
Truth table66%2/3
A and B
A= $self->game->status eq "active"B= @{$self->game->history;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 2 | my $answer = $self->read_line('Really quit, with the game unfinished? (y/n) '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 2 | ▶ | return 1 if !defined $answer || $answer =~ m/^\s*y/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $answer or $answer =~ /^\s*y/i
MC/DC50%1/2
not defined $answer or $answer =~ /^\s*y/i
not defined $answer
$answer =~ /^\s*y/i
Truth table66%2/3
not(A) or B
A= not defined $answerB= $answer =~ /^\s*y/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 3 | ▶ | sub help_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help_lines: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 'A move is its points: d2 to place a man, d2-d3 to move one.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 'One that closes a mill says which man it takes: d2-d3xa1.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 57 | map { sprintf ' %-10s %s', $_, $COMMAND{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 3 | ▶ | sort { length $a <=> length $b || $a cmp $b } keys %COMMAND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
length $a <=> length $b || $a cmp $b
MC/DC0%0/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b
$a cmp $b
Truth table66%2/3
A || B
A= length $a <=> length $bB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 3 | ▶ | sub show_help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_help: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 3 | $self->say($_) for @{ $self->help_lines }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 18 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 18 | my @levels = Game::Merrills::Bot->levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 18 | my $levels = "$levels[0] to $levels[-1]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 18 | my $limit = Game::Merrills::NO_MILL_PLIES; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 18 | return <<"USAGE"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | merrills - play Nine Men's Morris | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | Usage: merrills [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | -l, --level N the bot's strength, $levels (default 3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | -s, --side SIDE the side you play: white, black or random (default white) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | --hotseat two people at one keyboard, and no bot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | --bot-vs-bot watch two bots; give --level twice for white and black | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | --position STR begin from a position, as the position command prints it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | --load FILE carry on a game that the save command wrote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | --replay FILE show such a game a move at a time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | --seed N makes a game repeatable: the same seed, the same game | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | --no-flying a side down to three men still moves along the lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | -a, --ascii letters and dashes, for a terminal without the glyphs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | --colour paint the board even off a terminal; --no-colour never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | --no-pick type the moves out instead of choosing them with the keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | -v, --version print the version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | -h, --help this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | White moves first. Place your nine men in turn, then move them along the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | lines. Three in a row is a mill and takes a man: one in a mill is safe while | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | any stands outside one. Down to three men, you fly. Two men, or no move, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | you have lost. A position three times, or $limit moves without a mill, is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | draw. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | On a terminal a move is chosen with the arrow keys, a step at a time: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | man, where it goes, the man it takes. The board is drawn as the move would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | leave it, so a mill is seen before it is closed. Needs Term::ReadKey; without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | it, or off a terminal, moves are typed: d2 to place, d2-d3 to move, d2-d3xa1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | to take. Type help in the game for the commands. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | The board marks what the last move did with shapes, so they survive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | --no-colour and a file: (W) the man that moved, (.) where it came from, (x) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | where a man was taken. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | Levels $levels[-2] and $levels[-1] look a good deal further and take noticeably longer a move. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | A level's effort is counted in positions and never in seconds, so a busy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | machine plays the same game as an idle one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | Exit status is 0 if you won or drew, 1 if you lost, 2 for a bad option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 2 | ▶ | sub _reason { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reason: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 2 | my ($why) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 2 | ▶ | $why = 'could not start' unless defined $why && length $why; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $why and length $why
MC/DC0%0/2
defined $why and length $why
defined $why
length $why
Truth table33%1/3
A and B
A= defined $whyB= length $why
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 2 | $why =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 2 | $why =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 2 | return $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 14 | ▶ | sub _bad { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bad: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 14 | my ($why) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 14 | print STDERR "merrills: $why\n\n", _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 14 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 63 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 63 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 63 | my $saved = Getopt::Long::Configure(qw(no_ignore_case)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 63 | my $status = $class->_run(\@argv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 63 | Getopt::Long::Configure($saved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 63 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 63 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=50 SCAR=39.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 63 | my ($class, $argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 63 | my %opt = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | level => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | side => 'white', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | flying => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | ascii => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | Getopt::Long::GetOptionsFromArray($argv, \%opt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 'level|l=s@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 'side|s=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 'hotseat', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 'bot-vs-bot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 'position=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | 'load=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 'replay=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 'seed=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 'flying!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 'ascii|a', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 'colour|color!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 'pick!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 'version|v', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 'help|h', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 63 | ▶ | ) or do { print STDERR _usage(); return 2 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 62 | ▶ | if ($opt{help}) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 59 | ▶ | if ($opt{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 2 | print "merrills $Game::Merrills::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 57 | ▶ | return _bad("there is nothing to do with '$argv->[0]': options begin with --") if @{$argv}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 56 | my @levels = Game::Merrills::Bot->levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 56 | my %is_level = map { $_ => 1 } @levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 56 | my @level = @{ $opt{level} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 56 | for my $level (@level) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | return _bad("--level takes a number from $levels[0] to $levels[-1], not '$level'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | 32 | ▶ | unless $is_level{$level}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 54 | ▶ | return _bad('--level can be given twice at most, once a side') if @level > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | return _bad('--level twice is for --bot-vs-bot, where each side has a bot') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 53 | ▶ | if @level == 2 && !$opt{'bot-vs-bot'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@level == 2 and not $opt{"bot-vs-bot"}
MC/DC100%2/2
@level == 2 and not $opt{"bot-vs-bot"}
@level == 2
not $opt{"bot-vs-bot"}
Truth table100%3/3
A and not(B)
A= @level == 2B= not $opt{"bot-vs-bot"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | return _bad('--hotseat is two people and --bot-vs-bot is none: choose one') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 52 | ▶ | if $opt{hotseat} && $opt{'bot-vs-bot'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt{"hotseat"} and $opt{"bot-vs-bot"}
MC/DC100%2/2
$opt{"hotseat"} and $opt{"bot-vs-bot"}
$opt{"hotseat"}
$opt{"bot-vs-bot"}
Truth table100%3/3
A and B
A= $opt{"hotseat"}B= $opt{"bot-vs-bot"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 51 | ▶ | return _bad('--hotseat has no bot for --level to set') if $opt{hotseat} && @level; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt{"hotseat"} and @level
MC/DC100%2/2
$opt{"hotseat"} and @level
$opt{"hotseat"}
@level
Truth table100%3/3
A and B
A= $opt{"hotseat"}B= @level
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | return _bad("--side is white, black or random, not '$opt{side}'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 50 | ▶ | unless $opt{side} =~ m/^(?:white|black|random)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | return _bad("--seed takes a whole number, not '$opt{seed}'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 49 | ▶ | if defined $opt{seed} && $opt{seed} !~ m/^[0-9]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opt{"seed"} and not $opt{"seed"} =~ /^[0-9]+$/
MC/DC100%2/2
defined $opt{"seed"} and not $opt{"seed"} =~ /^[0-9]+$/
defined $opt{"seed"}
not $opt{"seed"} =~ /^[0-9]+$/
Truth table100%3/3
A and not(B)
A= defined $opt{"seed"}B= not $opt{"seed"} =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 48 | my @sources = grep { defined $opt{$_} } qw/position load replay/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 48 | ▶ | return _bad('--' . join(' and --', @sources) . ' each say where the game begins: give one') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | if @sources > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 47 | ▶ | my $seed = defined $opt{seed} ? $opt{seed} : (time ^ $$) % 1_000_000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 47 | ▶ | my $side = $opt{side} eq 'random' ? ($seed % 2 ? 'black' : 'white') : $opt{side}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 47 | ▶ | @level = (3) unless @level; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 47 | ▶ | @level = (@level, @level) if @level == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 47 | my ($game, $record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 47 | ▶ | if (defined $opt{position}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 6 | ▶ | $game = eval { Game::Merrills->new(position => $opt{position}, flying => $opt{flying}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | or return _bad('--position: ' . _reason($@)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | ▶ | elsif (defined(my $file = defined $opt{load} ? $opt{load} : $opt{replay})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 5 | ▶ | open my $handle, '<', $file or return _bad("cannot read $file: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 3 | $record = do { local $/; <$handle> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 3 | close $handle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 3 | ▶ | $game = eval { Game::Merrills->from_text($record, flying => $opt{flying}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | or return _bad("$file is not a game that plays: " . _reason($@)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 36 | $game = Game::Merrills->new(flying => $opt{flying}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | 43 | my ($human, $bot, $who); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | 43 | ▶ | if (defined $opt{replay}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 1 | $human = 'both'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | elsif ($opt{hotseat}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 18 | $human = 'both'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 18 | $who = 'White and Black: two people at one keyboard.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | elsif ($opt{'bot-vs-bot'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 5 | $human = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 5 | $bot = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | white => Game::Merrills::Bot->new(level => $level[0], seed => $seed), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | black => Game::Merrills::Bot->new(level => $level[1], seed => $seed + 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 5 | $who = "White: the bot at level $level[0]. Black: the bot at level $level[1]."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 19 | $human = $side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 19 | $bot = Game::Merrills::Bot->new(level => $level[0], seed => $seed); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 19 | ▶ | $who = sprintf '%s: you. %s: the bot at level %d.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | ucfirst $side, $side eq 'white' ? 'Black' : 'White', $level[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 43 | ▶ | $who .= ' No flying.' if defined $who && !$opt{flying}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $who and not $opt{"flying"}
MC/DC100%2/2
defined $who and not $opt{"flying"}
defined $who
not $opt{"flying"}
Truth table100%3/3
A and not(B)
A= defined $whoB= not $opt{"flying"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | my $terminal = $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | game => $game, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | human => $human, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | ascii => $opt{ascii} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | (defined $bot ? (bot => $bot) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | (exists $opt{colour} ? (colour => $opt{colour} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 43 | ▶ | (exists $opt{pick} ? (picking => $opt{pick} ? 1 : 0) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 43 | local @SIG{qw(INT TERM HUP)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 43 | for my $sig (qw(INT TERM HUP)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 129 | ▶ | $SIG{$sig} = sub { $terminal->leave_raw; $SIG{$sig} = 'DEFAULT'; kill $sig, $$ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 43 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 43 | ▶ | if (defined $opt{replay}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 1 | $result = eval { $terminal->replay($record) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 42 | $terminal->say($who); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 42 | $result = eval { $terminal->start }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 43 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 43 | $terminal->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 43 | ▶ | die $died if $died; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | 43 | ▶ | return 0 unless $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 8 | ▶ | return 0 if $result->is_draw || $human eq 'both' || $human eq 'none' || defined $opt{replay}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$result->is_draw or $human eq "both" or $human eq "none" or defined $opt{"replay"}
$result->is_draw or $human eq "both" or $human eq "none"
$result->is_draw or $human eq "both"
MC/DC50%2/4
$result->is_draw or $human eq "both" or $human eq "none" or defined $opt{"replay"}
$result->is_draw
$human eq "both"
$human eq "none"
defined $opt{"replay"}
Truth table60%3/5
A or B or C or D
A= $result->is_drawB= $human eq "both"C= $human eq "none"D= defined $opt{"replay"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 2 | ▶ | return $result->winner eq $human ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 68 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||