| 1 | package Game::Reversi::Terminal; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 23 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 23 | ▶ | use Game::Reversi; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use Game::Reversi::Board; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 23 | ▶ | use Game::Reversi::Bot; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 23 | ▶ | use Game::Reversi::Notation; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 23 | ▶ | use Game::Reversi::Opening; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 23 | ▶ | use Game::Terminal::Kit::History; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 23 | ▶ | use Game::Terminal::Kit::Replay; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use Game::Terminal::Kit::Run; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use Game::Terminal::Kit::Save; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 23 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | ▶ | use Game::Terminal::Kit::Steer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 23 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 23 | my %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | b => { wide => "\x{25CF}", ascii => 'X' }, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | w => { wide => "\x{25CB}", ascii => 'O' }, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 23 | my %TURNED = ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | b => { wide => "\x{25C9}", ascii => 'x' }, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | w => { wide => "\x{25CE}", ascii => 'o' }, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 23 | my %NAME = (b => 'dark', w => 'light'); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 23 | my %LINE = ( | |||||||||||||||||||||||||||||||||||||||||
| 36 | wide => { h => "\x{2500}", v => "\x{2502}", tl => "\x{250C}", tr => "\x{2510}", | ||||||||||||||||||||||||||||||||||||||||||
| 37 | bl => "\x{2514}", br => "\x{2518}", t => "\x{252C}", b => "\x{2534}", | ||||||||||||||||||||||||||||||||||||||||||
| 38 | l => "\x{251C}", r => "\x{2524}", x => "\x{253C}" }, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ascii => { h => '-', v => '|', tl => '+', tr => '+', bl => '+', br => '+', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | t => '+', b => '+', l => '+', r => '+', x => '+' }, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 23 | my %INK = (b => '1', w => '2', '*' => '33', grid => '2', | |||||||||||||||||||||||||||||||||||||||||
| 44 | turned => '1;32', placed => '1;36', cursor => '1;7'); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 23 | my %STEP = (left => -1, up => -1, back_tab => -1, | |||||||||||||||||||||||||||||||||||||||||
| 47 | right => 1, down => 1, tab => 1); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | has in => ( | ||||||||||||||||||||||||||||||||||||||||||
| 50 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 31 | ▶ | default => sub { \*STDIN } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | has out => ( | ||||||||||||||||||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 21 | ▶ | default => sub { \*STDOUT } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | has level => ( | ||||||||||||||||||||||||||||||||||||||||||
| 62 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | default => 3 | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | has variant => ( | ||||||||||||||||||||||||||||||||||||||||||
| 68 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | default => 'historic' | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | has colour => ( | ||||||||||||||||||||||||||||||||||||||||||
| 74 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | default => 'b' | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | has seed => ( | ||||||||||||||||||||||||||||||||||||||||||
| 80 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | default => 'terminal' | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | has [qw/quiet ascii/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 85 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | has game => ( | ||||||||||||||||||||||||||||||||||||||||||
| 91 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | isa => Any | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 23 | has last_move => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 23 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 55 | ▶ | has pending => (is => 'rw', default => sub { [] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 23 | has [qw/keyboard screen/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | has history => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 23 | has save_file => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 23 | has _picking => (is => 'rw', init_arg => 'picking', private => 1); | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | has _wants_ansi => ( | ||||||||||||||||||||||||||||||||||||||||||
| 110 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | init_arg => 'ansi', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 55 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 55 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 55 | ▶ | $self->keyboard(Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | in => $self->in, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | pending => $self->pending, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | ($self->keysource ? (keysource => $self->keysource) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 122 | )) unless $self->keyboard; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 55 | ▶ | $self->screen(Game::Terminal::Kit::Screen->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | out => $self->out, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | interactive => $self->interactive, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | colour => $self->ansi, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ascii => $self->ascii, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | )) unless $self->screen; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 55 | $self->screen->utf8->flush_on; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 55 | ▶ | $self->history(_new_history()) unless $self->history; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 55 | ▶ | $self->history->name('reversi') unless defined $self->history->name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 55 | $self->history->version($VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 55 | ▶ | $self->history->file($self->save_file) if defined $self->save_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 55 | ▶ | die "Game::Reversi::Terminal: colour must be b or w" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->colour eq "b" or $self->colour eq "w"
MC/DC100%2/2
$self->colour eq "b" or $self->colour eq "w"
$self->colour eq "b"
$self->colour eq "w"
Truth table100%3/3
A or B
A= $self->colour eq "b"B= $self->colour eq "w"
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | unless $self->colour eq 'b' || $self->colour eq 'w'; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 54 | ▶ | die "Game::Reversi::Terminal: there is no variant '" . $self->variant . "'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | unless Game::Reversi::Opening->describes($self->variant); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | die 'Game::Reversi::Terminal: there is no level ' . $self->level | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 53 | ▶ | unless grep { $_ == $self->level } Game::Reversi::Bot->levels; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 52 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 55 | ▶ | sub _new_history { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_history: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | return Game::Terminal::Kit::History->new( | ||||||||||||||||||||||||||||||||||||||||||
| 148 | name => 'reversi', | ||||||||||||||||||||||||||||||||||||||||||
| 149 | version => $VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 242 | ▶ | save => sub { $_[0]->to_text }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 12 | ▶ | load => sub { Game::Reversi->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 55 | ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 14346 | ▶ | sub ansi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ansi: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 14346 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 14346 | ▶ | return 0 if Game::Terminal::Kit::Screen::no_colour(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 12819 | ▶ | return $self->_wants_ansi ? 1 : 0 if defined $self->_wants_ansi; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 10655 | return $self->interactive; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 497 | ▶ | sub _reader { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reader: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 497 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 497 | my $keyboard = $self->keyboard; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 497 | $keyboard->in($self->in); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 497 | $keyboard->pending($self->pending); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 497 | ▶ | $keyboard->keysource($self->keysource) if $self->keysource; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 497 | return $keyboard; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 14286 | ▶ | sub _writer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_writer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 14286 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 14286 | my $screen = $self->screen; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 14286 | $screen->out($self->out); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 14286 | $screen->interactive($self->interactive); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 14286 | $screen->colour($self->ansi); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 14286 | return $screen; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 13097 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 13097 | my ($self, $glyph, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 13097 | return $self->_writer->paint($glyph, $INK{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 1127 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 1127 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 1127 | $self->_writer->say(@lines); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 1127 | return; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 208 | ▶ | sub _ask { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ask: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 208 | my ($self, $prompt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 208 | my $line = $self->_reader->read_line($prompt, $self->out); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 208 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 207 | $self->_say(''); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 207 | ▶ | return wantarray ? (lc $line, $line) : lc $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 6409 | ▶ | sub glyph { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glyph: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 6409 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 6409 | ▶ | return $GLYPH{$colour}{ $self->ascii ? 'ascii' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 308 | ▶ | sub board_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_text: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 308 | my ($self, $game, $colour, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 1616 | my %legal = map { $_->square => 1 } | |||||||||||||||||||||||||||||||||||||||||
| 207 | 308 | ▶ | @{ defined $colour ? $game->legal($colour) : [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 308 | ▶ | my %flipped = map { $_ => 1 } @{ $o{flips} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{'flips'} || []
MC/DC100%1/1
$o{'flips'} || []
$o{'flips'}
Truth table100%2/2
A
A= $o{'flips'}
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 308 | ▶ | my $line = $LINE{ $self->ascii ? 'ascii' : 'wide' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 308 | ▶ | my $kind = $self->ascii ? 'ascii' : 'wide'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 308 | my $files = ' ' . join ' ', 'a' .. 'h'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 2772 | ▶ | my $rule = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 2772 | my ($left, $join, $right) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | return ' ' . $self->_paint( | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 2772 | $left . join($join, ($line->{h} x 3) x 8) . $right, 'grid'); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 308 | }; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 308 | my @lines = ($files, $rule->(@{$line}{qw/tl t tr/})); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 308 | for my $row (0 .. 7) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 2464 | my $rank = 8 - $row; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 2464 | my @cells; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 2464 | for my $col (0 .. 7) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 19712 | my $square = $row * 8 + $col; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 19712 | my $cell = $game->board->[$square]; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 19712 | push @cells, $self->_cell($square, $cell, $kind, \%legal, | |||||||||||||||||||||||||||||||||||||||||
| 227 | \%flipped, %o); | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 2464 | my $bar = $self->_paint($line->{v}, 'grid'); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 2464 | push @lines, " $rank " . $bar . join($bar, @cells) . $bar . " $rank"; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 2464 | ▶ | push @lines, $rule->(@{$line}{qw/l x r/}) unless $row == 7; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 308 | push @lines, $rule->(@{$line}{qw/bl b br/}), $files; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 308 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 271 | ▶ | sub since { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
since: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 271 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 271 | ▶ | my $move = $self->last_move or return (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 187 | return (last => $move->square, flips => $move->flips); | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 349 | ▶ | sub remember { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remember: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 349 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 349 | ▶ | $self->last_move(ref $move && $move->can('square') ? $move : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $move and $move->can("square")
MC/DC0%0/2
ref $move and $move->can("square")
ref $move
$move->can("square")
Truth table33%1/3
A and B
A= ref $moveB= $move->can("square")
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 349 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 19712 | ▶ | sub _cell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 19712 | my ($self, $square, $cell, $kind, $legal, $flipped, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 19712 | ▶ | my $cursor = defined $o{cursor} && $o{cursor} == $square; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $o{'cursor'} && $o{'cursor'} == $square
MC/DC100%2/2
defined $o{'cursor'} && $o{'cursor'} == $square
defined $o{'cursor'}
$o{'cursor'} == $square
Truth table100%3/3
A && B
A= defined $o{'cursor'}B= $o{'cursor'} == $square
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 19712 | ▶ | my $placed = defined $o{last} && $o{last} == $square; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $o{'last'} && $o{'last'} == $square
MC/DC100%2/2
defined $o{'last'} && $o{'last'} == $square
defined $o{'last'}
$o{'last'} == $square
Truth table100%3/3
A && B
A= defined $o{'last'}B= $o{'last'} == $square
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 19712 | ▶ | if ($cursor) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | my $face = defined $cell ? $self->glyph($cell) | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 61 | ▶ | : $o{to_play} ? $GLYPH{ $o{to_play} }{$kind} : '*'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 61 | return $self->_paint('>' . $face . '<', 'cursor'); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 19651 | ▶ | return $self->_paint('[' . $self->glyph($cell) . ']', 'placed') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$placed and defined $cell
MC/DC50%1/2
$placed and defined $cell
$placed
defined $cell
Truth table66%2/3
A and B
A= $placedB= defined $cell
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | if $placed && defined $cell; | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | return ' ' . $self->_paint($TURNED{$cell}{$kind}, 'turned') . ' ' | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 19464 | ▶ | if defined $cell && $flipped->{$square}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cell and $flipped->{$square}
MC/DC100%2/2
defined $cell and $flipped->{$square}
defined $cell
$flipped->{$square}
Truth table100%3/3
A and B
A= defined $cellB= $flipped->{$square}
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | return ' ' . (defined $cell ? $self->_paint($self->glyph($cell), $cell) | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 19050 | ▶ | : $legal->{$square} ? $self->_paint('*', '*') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | : ' ') . ' '; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 27 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 27 | ▶ | $self->game(Game::Reversi->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | variant => $self->variant, seed => $self->seed)) unless $self->game; | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 27 | my $bot = Game::Reversi::Bot->new( | |||||||||||||||||||||||||||||||||||||||||
| 278 | level => $self->level, seed => $self->seed . ':bot'); | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 27 | my $me = $self->colour; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 27 | $self->_intro; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 27 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 27 | my $seen = scalar @{ $self->game->events }; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 27 | ▶ | while ($self->game->status eq 'active') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 374 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 374 | my $turn = $game->turn; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 374 | ▶ | if ($turn eq $me) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 203 | $self->history->turn($game); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 203 | my $outcome = $self->_human_turn($game, $me); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 203 | ▶ | if ($outcome && $outcome eq 'swap') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$outcome and $outcome eq "swap"
MC/DC100%2/2
$outcome and $outcome eq "swap"
$outcome
$outcome eq "swap"
Truth table100%3/3
A and B
A= $outcomeB= $outcome eq "swap"
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 7 | $seen = scalar @{ $self->game->events }; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 196 | ▶ | if ($outcome) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 22 | $game->resign($me); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 22 | last; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 171 | my $move = $bot->choose($game, $turn); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 171 | ▶ | last unless $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 171 | my $done = $game->play($turn, $move->square); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 171 | $self->remember($done); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 171 | ▶ | $self->_say('', $NAME{$turn} . ' plays ' . $move->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | . ', turning ' . $move->turned | ||||||||||||||||||||||||||||||||||||||||||
| 308 | . ($move->turned == 1 ? ' disc' : ' discs')) | ||||||||||||||||||||||||||||||||||||||||||
| 309 | if $move->phase eq 'play'; | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 171 | ▶ | $self->_say('', $NAME{$turn} . ' places on ' . $move->name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | if $move->phase eq 'place'; | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 345 | $seen = $self->_announce_passes($game, $seen); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 27 | $self->_finish($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 27 | return $self->game->result; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 12 | ▶ | sub _travel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_travel: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 12 | my ($self, $way) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 12 | my $history = $self->history; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 12 | ▶ | my $rebuilt = $way eq 'redo' ? $history->redo : $history->undo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 12 | ▶ | return $way eq 'redo' ? 'nothing to redo' : 'nothing to take back' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | unless $rebuilt; | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 7 | $self->game($rebuilt); | |||||||||||||||||||||||||||||||||||||||||
| 328 | 7 | $self->last_move(undef); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 27 | ▶ | sub _intro { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_intro: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 27 | my $me = $self->colour; | |||||||||||||||||||||||||||||||||||||||||
| 335 | $self->_say( | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 27 | ▶ | 'Reversi. You are ' . $self->glyph($me) . ', ' . $NAME{$me} . '.', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | $self->variant eq 'historic' | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ? 'The historic opening: the first four discs are placed by the ' | ||||||||||||||||||||||||||||||||||||||||||
| 339 | . 'players, on the centre four, and turn nothing.' | ||||||||||||||||||||||||||||||||||||||||||
| 340 | : 'The Othello opening: four discs are already on the board.', | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 'Enter a square such as d3. "help" for help, "quit" to give up.', | ||||||||||||||||||||||||||||||||||||||||||
| 342 | ) unless $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 27 | return; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 185 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 185 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 185 | return $self->_reader->keys_available; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 205 | ▶ | sub picking { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picking: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 205 | my ($self, @set) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 205 | ▶ | $self->_picking($set[0] ? 1 : 0) if @set; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 205 | ▶ | return 0 if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 203 | ▶ | return $self->_picking ? 1 : 0 if defined $self->_picking; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 184 | return $self->keys_available; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return $self->keyboard->raw; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 24 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 24 | ▶ | return $self->_reader->enter_raw ? $self : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $self->_reader->leave_raw; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 80 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 80 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 80 | return $self->_reader->read_key; | |||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 24996 | ▶ | sub interactive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 24996 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 24996 | ▶ | my $out = $self->out or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 24996 | ▶ | return (eval { -t $out }) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->_writer->clear(scrollback => 1); | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 62 | ▶ | sub square_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
square_line: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 62 | my ($self, $game, $me, $square) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 62 | my $name = Game::Reversi::Board->name_of($square); | |||||||||||||||||||||||||||||||||||||||||
| 396 | 62 | my $trial = $game->clone; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 62 | my $move = $trial->play($me, $square); | |||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 62 | ▶ | return "$name: " . $move->message | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $move and $move->isa("Game::Reversi::Error")
MC/DC0%0/2
ref $move and $move->isa("Game::Reversi::Error")
ref $move
$move->isa("Game::Reversi::Error")
Truth table33%1/3
A and B
A= ref $moveB= $move->isa("Game::Reversi::Error")
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | if ref $move && $move->isa('Game::Reversi::Error'); | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 62 | ▶ | return "$name: placed, turning nothing yet" if $move->phase eq 'place'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 62 | my $count = $trial->counts; | |||||||||||||||||||||||||||||||||||||||||
| 405 | return sprintf '%s: turns %d %s, and you would be %d to %d', | ||||||||||||||||||||||||||||||||||||||||||
| 406 | $name, $move->turned, ($move->turned == 1 ? 'disc' : 'discs'), | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 62 | ▶ | $count->{$me}, $count->{ $me eq 'b' ? 'w' : 'b' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | sub pick_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | 'arrows walk the squares marked *, which are the only ones that play.', | |||||||||||||||||||||||||||||||||||||||||
| 413 | 'the line under the board says what the move would turn.', | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 'enter plays it, t goes back to typing, q gives up.', | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 'u takes your last turn back, r plays it again.', | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 'S saves the game, to carry on with --resume or watch with --replay.', | ||||||||||||||||||||||||||||||||||||||||||
| 417 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 23 | ▶ | sub pick_square { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_square: called CC=25 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 23 | my ($self, $game, $me) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 23 | my @legal = sort { $a <=> $b } map { $_->square } @{ $game->legal($me) }; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 23 | ▶ | return $self->_typed_turn($game, $me) unless @legal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 23 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 23 | ▶ | if (my $last = $self->last_move) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 5 | my ($gap) = sort { $a <=> $b } map { abs($_ - $last->square) } @legal; | |||||||||||||||||||||||||||||||||||||||||
| 429 | $at = Game::Terminal::Kit::Steer::rest(\@legal, | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 5 | ▶ | sub { abs($_[0] - $last->square) == $gap }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 23 | my @notice; | |||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 23 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 436 | 61 | my $count = $game->counts; | |||||||||||||||||||||||||||||||||||||||||
| 437 | $self->_writer->show([ | ||||||||||||||||||||||||||||||||||||||||||
| 438 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 439 | $self->board_text($game, $me, $self->since, | ||||||||||||||||||||||||||||||||||||||||||
| 440 | cursor => $legal[$at], to_play => $me), | ||||||||||||||||||||||||||||||||||||||||||
| 441 | ' discs: ' . $self->glyph(q{b}) . ' ' . $count->{b} | ||||||||||||||||||||||||||||||||||||||||||
| 442 | . ' ' . $self->glyph(q{w}) . ' ' . $count->{w}, | ||||||||||||||||||||||||||||||||||||||||||
| 443 | ' ' . $self->square_line($game, $me, $legal[$at]), | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 61 | ▶ | (map { ' ' . $_ } @notice), | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->history->legend || ()
MC/DC0%0/2
$self->history->legend || ()
$self->history->legend
()
Truth table66%2/3
A || B
A= $self->history->legendB= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | ' ' . $self->_paint(join(', ', 'arrows to choose, enter to play, ? for the keys', | ||||||||||||||||||||||||||||||||||||||||||
| 446 | $self->history->legend || (), 'S save'), 'grid'), | ||||||||||||||||||||||||||||||||||||||||||
| 447 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 61 | @notice = (); | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 61 | my $key = $self->read_key; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 61 | ▶ | return 1 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 61 | ▶ | if ($STEP{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 32 | $at = Game::Terminal::Kit::Steer::ring(scalar @legal, $at, $STEP{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 455 | 32 | next; | |||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if ($key eq 'home') { $at = 0; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if ($key eq 'end') { $at = $#legal; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 29 | ▶ | 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 " "
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | my $played = $game->play($me, $legal[$at]); | |||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | ▶ | if (ref $played && $played->isa('Game::Reversi::Error')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $played and $played->isa("Game::Reversi::Error")
MC/DC0%0/2
ref $played and $played->isa("Game::Reversi::Error")
ref $played
$played->isa("Game::Reversi::Error")
Truth table33%1/3
A and B
A= ref $playedB= $played->isa("Game::Reversi::Error")
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | @notice = ($played->message . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | $self->remember($played); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | ▶ | $self->_say(' you play ' . $played->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | . ($played->phase eq 'play' | ||||||||||||||||||||||||||||||||||||||||||
| 469 | ? ', turning ' . $played->turned | ||||||||||||||||||||||||||||||||||||||||||
| 470 | . ($played->turned == 1 ? ' disc' : ' discs') | ||||||||||||||||||||||||||||||||||||||||||
| 471 | : '')); | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 25 | ▶ | if ($key eq 'u' || $key eq 'r') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "u" or $key eq "r"
MC/DC100%2/2
$key eq "u" or $key eq "r"
$key eq "u"
$key eq "r"
Truth table100%3/3
A or B
A= $key eq "u"B= $key eq "r"
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 7 | ▶ | my $nothing = $self->_travel($key eq 'u' ? 'undo' : 'redo'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 7 | ▶ | return 'swap' unless $nothing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | @notice = ($nothing . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 18 | ▶ | if ($key eq 'S') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | my $file = Game::Terminal::Kit::Save::ask_file($self->keyboard, $self->_writer, | |||||||||||||||||||||||||||||||||||||||||
| 483 | default => $self->save_default, | ||||||||||||||||||||||||||||||||||||||||||
| 484 | head => [ '', $self->board_text($game, $me, $self->since, to_play => $me), '' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | ▶ | @notice = ($self->save($file)) if defined $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 17 | ▶ | if ($key eq 'q') { return 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | if ($key eq 't') { $self->picking(0); $self->leave_raw; return $self->_typed_turn($game, $me) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ($key eq '?') { @notice = $self->pick_help; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | @notice = ('that key does nothing here. ? for the ones that do'); | |||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 203 | ▶ | sub _human_turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_human_turn: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 203 | my ($self, $game, $me) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 203 | ▶ | if ($self->picking) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 13 | ▶ | return $self->pick_square($game, $me) if $self->enter_raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | $self->picking(0); | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 191 | return $self->_typed_turn($game, $me); | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 191 | ▶ | sub _typed_turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_typed_turn: called CC=19 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 191 | my ($self, $game, $me) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 191 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 511 | 208 | my $count = $game->counts; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 208 | $self->_say("", $self->board_text($game, $me, $self->since)); | |||||||||||||||||||||||||||||||||||||||||
| 513 | $self->_say( | ||||||||||||||||||||||||||||||||||||||||||
| 514 | ' discs: ' . $self->glyph(q{b}) . ' ' . $count->{b} . ' ' | ||||||||||||||||||||||||||||||||||||||||||
| 515 | . $self->glyph(q{w}) . ' ' . $count->{w}, | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 208 | ▶ | ' ' . ($game->phase eq 'opening' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | ? 'Place a disc on one of the centre four.' | ||||||||||||||||||||||||||||||||||||||||||
| 518 | : 'Your move. The squares marked * are the ones that outflank something.'), | ||||||||||||||||||||||||||||||||||||||||||
| 519 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 208 | my ($answer, $typed) = $self->_ask(' > '); | |||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 208 | ▶ | return 1 unless defined $answer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 207 | ▶ | return 1 if $answer eq 'quit' || $answer eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$answer eq "quit" or $answer eq "resign"
MC/DC50%1/2
$answer eq "quit" or $answer eq "resign"
$answer eq "quit"
$answer eq "resign"
Truth table66%2/3
A or B
A= $answer eq "quit"B= $answer eq "resign"
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 192 | ▶ | if ($answer eq 'help') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | $self->_help($game, $me); | |||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 191 | ▶ | if ($answer eq 'board' || $answer eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$answer eq "board" or $answer eq ""
MC/DC0%0/2
$answer eq "board" or $answer eq ""
$answer eq "board"
$answer eq ""
Truth table33%1/3
A or B
A= $answer eq "board"B= $answer eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 191 | ▶ | if ($answer eq 'undo' || $answer eq 'redo') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$answer eq "undo" or $answer eq "redo"
MC/DC100%2/2
$answer eq "undo" or $answer eq "redo"
$answer eq "undo"
$answer eq "redo"
Truth table100%3/3
A or B
A= $answer eq "undo"B= $answer eq "redo"
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 5 | my $nothing = $self->_travel($answer); | |||||||||||||||||||||||||||||||||||||||||
| 535 | 5 | ▶ | return 'swap' unless $nothing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | $self->_say(' ' . $nothing . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 186 | ▶ | if (my ($saving, $file) = Game::Terminal::Kit::Save::command($typed)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 11 | $self->_say(' ' . $self->save($file)); | |||||||||||||||||||||||||||||||||||||||||
| 541 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 175 | my $square = Game::Reversi::Notation->text_to_square($answer); | |||||||||||||||||||||||||||||||||||||||||
| 545 | 175 | ▶ | if (!defined $square) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 3 | $self->_say(' "' . $answer . '" is not a square. Try d3, or "help".'); | |||||||||||||||||||||||||||||||||||||||||
| 547 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 172 | my $played = $game->play($me, $square); | |||||||||||||||||||||||||||||||||||||||||
| 551 | 172 | ▶ | $self->remember($played) unless ref $played && $played->isa("Game::Reversi::Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $played and $played->isa("Game::Reversi::Error")
MC/DC50%1/2
ref $played and $played->isa("Game::Reversi::Error")
ref $played
$played->isa("Game::Reversi::Error")
Truth table66%2/3
A and B
A= ref $playedB= $played->isa("Game::Reversi::Error")
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 172 | ▶ | if (ref $played && $played->isa('Game::Reversi::Error')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $played and $played->isa("Game::Reversi::Error")
MC/DC50%1/2
ref $played and $played->isa("Game::Reversi::Error")
ref $played
$played->isa("Game::Reversi::Error")
Truth table66%2/3
A and B
A= ref $playedB= $played->isa("Game::Reversi::Error")
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | $self->_say(' ' . $played->message . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 171 | ▶ | $self->_say(' you play ' . $played->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | . ($played->phase eq 'play' | ||||||||||||||||||||||||||||||||||||||||||
| 559 | ? ', turning ' . $played->turned | ||||||||||||||||||||||||||||||||||||||||||
| 560 | . ($played->turned == 1 ? ' disc' : ' discs') | ||||||||||||||||||||||||||||||||||||||||||
| 561 | : '')); | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 171 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | ▶ | sub _help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_help: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | my ($self, $game, $me) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 568 | 1 | $self->_say( | |||||||||||||||||||||||||||||||||||||||||
| 569 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 570 | ' Enter a square as a file and a rank, such as d3 or f5.', | ||||||||||||||||||||||||||||||||||||||||||
| 571 | ' A move must outflank at least one of the other side\'s discs;', | ||||||||||||||||||||||||||||||||||||||||||
| 572 | ' every disc it outflanks is turned, and you do not get to choose.', | ||||||||||||||||||||||||||||||||||||||||||
| 573 | ' The squares marked * are the ones you can play.', | ||||||||||||||||||||||||||||||||||||||||||
| 574 | ' A turn with no legal move is forfeited for you automatically.', | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ' The game ends when neither side can move, which can happen with', | ||||||||||||||||||||||||||||||||||||||||||
| 576 | ' the board not full. "undo" takes your last turn back, "redo"', | ||||||||||||||||||||||||||||||||||||||||||
| 577 | ' plays it again, "save" or "save FILE" saves the game to carry', | ||||||||||||||||||||||||||||||||||||||||||
| 578 | ' on with --resume, and "quit" gives up.', | ||||||||||||||||||||||||||||||||||||||||||
| 579 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 580 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 345 | ▶ | sub _announce_passes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_announce_passes: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 345 | my ($self, $game, $seen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 586 | 345 | my $events = $game->events; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 345 | for my $i ($seen .. $#$events) { | |||||||||||||||||||||||||||||||||||||||||
| 588 | 354 | my $event = $events->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 354 | ▶ | next unless $event->{kind} eq 'pass'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 4 | my $colour = $event->{payload}{colour}; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 4 | $self->_say(' ' . $NAME{$colour} . ' has no legal move, so that turn is ' | |||||||||||||||||||||||||||||||||||||||||
| 592 | . 'forfeited and the other side plays again.'); | ||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 345 | return scalar @$events; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 28 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 28 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 28 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||
| 600 | 28 | ▶ | return unless $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 28 | $self->_say('', $self->board_text($game, undef), ''); | |||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 28 | my $count = $result->counts; | |||||||||||||||||||||||||||||||||||||||||
| 605 | $self->_say(' discs on the board: ' . $self->glyph(q{b}) . ' ' . $count->{b} | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 28 | . ' ' . $self->glyph(q{w}) . ' ' . $count->{w}); | |||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 28 | my $score = $result->score; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 28 | ▶ | if ($score) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 6 | my $empty = Game::Reversi::Board->empties($game->board); | |||||||||||||||||||||||||||||||||||||||||
| 611 | $self->_say(' final score: ' . $self->glyph(q{b}) . ' ' . $score->{b} | ||||||||||||||||||||||||||||||||||||||||||
| 612 | . ' ' . $self->glyph(q{w}) . ' ' . $score->{w} | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 6 | ▶ | . ($empty ? " (the $empty empty squares go to the winner)" : '')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 28 | my $me = $self->colour; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 28 | ▶ | $self->_say('', !defined $result->winner ? ' A tie.' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | : $result->winner eq $me ? ' You win.' | ||||||||||||||||||||||||||||||||||||||||||
| 619 | : ' You lose.'); | ||||||||||||||||||||||||||||||||||||||||||
| 620 | 28 | ▶ | $self->_say(' (' . $result->result . ')') unless $result->natural; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 28 | return; | |||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | 12 | ▶ | sub settings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
settings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 12 | return { level => $self->level, variant => $self->variant, colour => $self->colour, seed => $self->seed }; | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 7 | ▶ | sub save_default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_default: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 7 | my $file = $self->history->file; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 7 | ▶ | return defined $file ? $file : Game::Terminal::Kit::Save::default_file('reversi'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 12 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 12 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 12 | ▶ | $file = $self->save_default unless defined $file && length $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and length $file
MC/DC50%1/2
defined $file and length $file
defined $file
length $file
Truth table66%2/3
A and B
A= defined $fileB= length $file
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 12 | my $history = $self->history; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 12 | $history->settings($self->settings); | |||||||||||||||||||||||||||||||||||||||||
| 640 | 12 | $history->version($VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 641 | 12 | my $path = eval { $history->saved($self->game)->write_file($file) }; | |||||||||||||||||||||||||||||||||||||||||
| 642 | 12 | ▶ | return 'the game was not saved: ' . Game::Terminal::Kit::Save::why($@) . '.' unless $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 12 | $history->file($path); | |||||||||||||||||||||||||||||||||||||||||
| 644 | 12 | return "the game is saved to $path."; | |||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 9 | ▶ | sub read_save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | 9 | my ($class, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 9 | return Game::Terminal::Kit::Save->read_game($file, 'reversi'); | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | 4 | ▶ | sub replay_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay_lines: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 4 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 654 | 4 | my $count = $game->counts; | |||||||||||||||||||||||||||||||||||||||||
| 655 | 4 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||
| 656 | return ($self->board_text($game, undef), | ||||||||||||||||||||||||||||||||||||||||||
| 657 | ' discs: ' . $self->glyph(q{b}) . ' ' . $count->{b} . ' ' . $self->glyph(q{w}) . ' ' . $count->{w}, | ||||||||||||||||||||||||||||||||||||||||||
| 658 | 4 | ▶ | ($result ? ' the game is over' . (defined $result->winner ? ': ' . $NAME{ $result->winner } . ' won.' : ': a tie.') : ())); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 9 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | 9 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 663 | reversi - play Reversi in a terminal | ||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | reversi [--level 1..5] [--variant historic|othello] | ||||||||||||||||||||||||||||||||||||||||||
| 666 | [--colour b|w] [--seed STRING] [--ascii] | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | --level how hard the opponent is, 1 to 5. Default 3. | ||||||||||||||||||||||||||||||||||||||||||
| 669 | --variant historic, the real Reversi opening where the players place the | ||||||||||||||||||||||||||||||||||||||||||
| 670 | first four discs themselves, or othello, where those four are | ||||||||||||||||||||||||||||||||||||||||||
| 671 | already down. Default historic. | ||||||||||||||||||||||||||||||||||||||||||
| 672 | --colour b to play dark and move first, w to play light. Default b. | ||||||||||||||||||||||||||||||||||||||||||
| 673 | --seed makes a game reproducible, and decides how the bot opens. | ||||||||||||||||||||||||||||||||||||||||||
| 674 | --ascii X and O on a plain grid, for a terminal without box characters. | ||||||||||||||||||||||||||||||||||||||||||
| 675 | --nopick type the squares out instead of pointing at them. | ||||||||||||||||||||||||||||||||||||||||||
| 676 | --save FILE where S, or "save", writes the game: FILE, else the file it | ||||||||||||||||||||||||||||||||||||||||||
| 677 | was resumed from, else reversi.save. | ||||||||||||||||||||||||||||||||||||||||||
| 678 | --resume FILE carry on a saved game, with its undo and redo. | ||||||||||||||||||||||||||||||||||||||||||
| 679 | --replay FILE watch a saved game a turn at a time; enter plays on from there. | ||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | On a terminal the arrow keys walk the squares marked *, which are the only | ||||||||||||||||||||||||||||||||||||||||||
| 682 | ones that play, and the line under the board says what the move would turn | ||||||||||||||||||||||||||||||||||||||||||
| 683 | and what the score would become. Enter plays it, t goes back to typing, | ||||||||||||||||||||||||||||||||||||||||||
| 684 | u takes your last turn back, r plays it again, S saves the game and ? lists | ||||||||||||||||||||||||||||||||||||||||||
| 685 | the keys. Typed, the same are undo, redo and save. Needs Term::ReadKey; without it the squares are typed. | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | The square the last move went on is bracketed and the discs it turned are | ||||||||||||||||||||||||||||||||||||||||||
| 688 | drawn ringed, so both are visible with --ascii and with colour off. | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | Exit status is 0 if you won or tied, 1 if you lost, 2 for a bad option. | ||||||||||||||||||||||||||||||||||||||||||
| 691 | USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 2 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | { name => 'level', type => 'int', min => 1, max => 5, help => 'how hard the opponent is' }, | |||||||||||||||||||||||||||||||||||||||||
| 697 | { name => 'variant', type => 'enum', choices => [qw(historic othello)], help => 'place the first four discs yourselves, or find them down' }, | ||||||||||||||||||||||||||||||||||||||||||
| 698 | { name => 'colour', type => 'enum', choices => [qw(b w)], help => 'b plays dark and moves first, w plays light' }, | ||||||||||||||||||||||||||||||||||||||||||
| 699 | { name => 'seed', type => 'str', help => 'makes a game reproducible' }, | ||||||||||||||||||||||||||||||||||||||||||
| 700 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 26 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=30 SCAR=37.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 26 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 705 | 26 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 26 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 708 | 26 | ▶ | local $SIG{__WARN__} = sub { print STDERR "reversi: $_[0]" }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 26 | Getopt::Long::GetOptionsFromArray(\@argv, \%opt, | |||||||||||||||||||||||||||||||||||||||||
| 710 | 'level=i', 'variant=s', 'colour=s', 'seed=s', 'ascii', 'pick!', 'help|h', | ||||||||||||||||||||||||||||||||||||||||||
| 711 | Game::Terminal::Kit::Save::flags()); | ||||||||||||||||||||||||||||||||||||||||||
| 712 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 26 | ▶ | if (!$ok) { print STDERR _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | 25 | ▶ | if ($opt{help}) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | if (@argv) { print STDERR "reversi: not an option: $argv[0]\n", _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 17 | ▶ | if (my $why = Game::Terminal::Kit::Save::check_flags(\%opt)) { print STDERR "reversi: $why.\n"; return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | 15 | ▶ | my $from = defined $opt{resume} ? $opt{resume} : $opt{replay}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | 15 | my $save; | |||||||||||||||||||||||||||||||||||||||||
| 720 | 15 | ▶ | if (defined $from) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | 8 | ($save, my $why) = $class->read_save($from); | |||||||||||||||||||||||||||||||||||||||||
| 722 | 8 | ▶ | unless ($save) { print STDERR "reversi: $why.\n"; return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 6 | my $settings = $save->settings; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 6 | ▶ | defined $opt{$_} or $opt{$_} = $settings->{$_} for grep { defined $settings->{$_} } qw(level variant colour seed); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 13 | my %default = (level => 3, variant => 'historic', colour => 'b', seed => 'reversi'); | |||||||||||||||||||||||||||||||||||||||||
| 727 | 13 | ▶ | defined $opt{$_} or $opt{$_} = $default{$_} for keys %default; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | 13 | ▶ | $opt{colour} = 'b' if lc $opt{colour} eq 'dark' || lc $opt{colour} eq 'black'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
lc $opt{"colour"} eq "dark" or lc $opt{"colour"} eq "black"
MC/DC0%0/2
lc $opt{"colour"} eq "dark" or lc $opt{"colour"} eq "black"
lc $opt{"colour"} eq "dark"
lc $opt{"colour"} eq "black"
Truth table33%1/3
A or B
A= lc $opt{"colour"} eq "dark"B= lc $opt{"colour"} eq "black"
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 13 | ▶ | $opt{colour} = 'w' if lc $opt{colour} eq 'light' || lc $opt{colour} eq 'white'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
lc $opt{"colour"} eq "light" or lc $opt{"colour"} eq "white"
MC/DC0%0/2
lc $opt{"colour"} eq "light" or lc $opt{"colour"} eq "white"
lc $opt{"colour"} eq "light"
lc $opt{"colour"} eq "white"
Truth table33%1/3
A or B
A= lc $opt{"colour"} eq "light"B= lc $opt{"colour"} eq "white"
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 13 | my $terminal = eval { | |||||||||||||||||||||||||||||||||||||||||
| 733 | $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 734 | level => $opt{level}, variant => $opt{variant}, | ||||||||||||||||||||||||||||||||||||||||||
| 735 | colour => $opt{colour}, seed => $opt{seed}, | ||||||||||||||||||||||||||||||||||||||||||
| 736 | ascii => $opt{ascii}, | ||||||||||||||||||||||||||||||||||||||||||
| 737 | (defined $opt{save} ? (save_file => $opt{save}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 13 | ▶ | (defined $opt{pick} ? (picking => $opt{pick} ? 1 : 0) : ())); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 739 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 740 | 13 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | my $why = $@ || "could not start\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "could not start\n"
MC/DC0%0/1
$@ || "could not start\n"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | $why =~ s/ at \S+ line \d+\.?\n?\z//; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | $why =~ s/\AGame::Reversi(?:::\w+)*: //; | |||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | chomp $why; | |||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | print STDERR "reversi: $why\n"; | |||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | 13 | ▶ | if (defined $opt{replay}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | my $replay = Game::Terminal::Kit::Replay->new( | ||||||||||||||||||||||||||||||||||||||||||
| 751 | save => $save, | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 3 | ▶ | load => sub { Game::Reversi->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 3 | ▶ | draw => sub { $terminal->replay_lines($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 1 | ▶ | head => [ 'Reversi, a replay of ' . $save->file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | . (defined $save->saved_at ? ', saved ' . $save->saved_at : ''), '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 756 | screen => $terminal->screen, | ||||||||||||||||||||||||||||||||||||||||||
| 757 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 758 | my ($event, $step) = Game::Terminal::Kit::Run::guard( | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | ▶ | sub { $replay->play($terminal->keyboard, $terminal->screen) }, $terminal->keyboard, $terminal->screen); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | 1 | ▶ | return 0 unless $event eq 'chosen'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | $save = $save->from_step($step); | |||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 12 | ▶ | if ($save) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | 5 | my $game = eval { $terminal->history->resume($save) }; | |||||||||||||||||||||||||||||||||||||||||
| 765 | 5 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | print STDERR "reversi: '" . $save->file . "' cannot be carried on: " | |||||||||||||||||||||||||||||||||||||||||
| 767 | . Game::Terminal::Kit::Save::why($@) . ".\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 5 | $terminal->game($game); | |||||||||||||||||||||||||||||||||||||||||
| 771 | 5 | ▶ | $terminal->history->file($terminal->save_file) if defined $terminal->save_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | my $result = Game::Terminal::Kit::Run::guard( | ||||||||||||||||||||||||||||||||||||||||||
| 775 | 12 | ▶ | sub { $terminal->start }, $terminal->keyboard, $terminal->screen); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 12 | ▶ | return 0 unless $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | 12 | ▶ | return 0 if !defined $result->winner; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 12 | ▶ | return 0 if $result->winner eq $opt{colour}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 12 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | __END__ | ||||||||||||||||||||||||||||||||||||||||||