| 1 | package Game::Backgammon::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::Backgammon; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use Game::Backgammon::Board (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 23 | ▶ | use Game::Backgammon::Bot; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 23 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 23 | ▶ | use Game::Terminal::Kit::History; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 23 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use Game::Terminal::Kit::Log; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 23 | ▶ | use Game::Terminal::Kit::Picker; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use Game::Terminal::Kit::Replay; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use Game::Terminal::Kit::Run; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 23 | ▶ | use Game::Terminal::Kit::Save; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | my %CHECKER = ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | white => { ascii => 'O', wide => "\x{25CB}", colour => '1;37', ink => '1;38;5;231' }, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | black => { ascii => 'X', wide => "\x{25CF}", colour => '1;36', ink => '1;38;5;16' }, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 23 | my %GROUND = ( | |||||||||||||||||||||||||||||||||||||||||
| 29 | light => '48;5;180', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | dark => '48;5;94', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | from => '48;5;136', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | to => '48;5;28', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | hit => '48;5;124', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | played => '48;5;24', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 23 | ▶ | use constant ROWS => 5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | has game => ( | ||||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | has out => ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 17 | ▶ | default => sub { \*STDOUT } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | has in => ( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 39 | ▶ | default => sub { \*STDIN } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | has mode => ( | ||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | default => 'bot' | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | has level => ( | ||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | default => 3 | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | has seat => ( | ||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | default => 'white' | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | has view => ( | ||||||||||||||||||||||||||||||||||||||||||
| 75 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | default => '' | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | has ascii => ( | ||||||||||||||||||||||||||||||||||||||||||
| 81 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | has [qw/colour interactive picking/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 87 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | has [qw/keyboard screen log picker/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 91 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | has highlight => ( | ||||||||||||||||||||||||||||||||||||||||||
| 95 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 49 | ▶ | default => sub { {} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | has keysource => ( | ||||||||||||||||||||||||||||||||||||||||||
| 101 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | isa => CodeRef | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | has pending => ( | ||||||||||||||||||||||||||||||||||||||||||
| 106 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 107 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 49 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | has save_file => ( | ||||||||||||||||||||||||||||||||||||||||||
| 112 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | has history => ( | ||||||||||||||||||||||||||||||||||||||||||
| 116 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 49 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=20 SCAR=30.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 49 | ▶ | $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 49 | ▶ | $self->colour($self->interactive && !Game::Terminal::Kit::Screen::no_colour() ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
MC/DC50%1/2
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
$self->interactive
not Game::Terminal::Kit::Screen::no_colour()
Truth table66%2/3
A and not(B)
A= $self->interactiveB= not Game::Terminal::Kit::Screen::no_colour()
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | unless defined $self->colour; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 49 | ▶ | $self->keyboard(Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | in => $self->in, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | pending => $self->pending, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ($self->keysource ? (keysource => $self->keysource) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 128 | )) unless $self->keyboard; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 49 | ▶ | $self->screen(Game::Terminal::Kit::Screen->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | out => $self->out, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | interactive => $self->interactive ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | colour => $self->colour ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ascii => $self->ascii ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | )) unless $self->screen; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 49 | ▶ | $self->log(Game::Terminal::Kit::Log->new) unless $self->log; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 49 | ▶ | $self->picker(Game::Terminal::Kit::Picker->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | window => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | log => $self->log, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | screen => $self->screen, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | )) unless $self->picker; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 49 | ▶ | $self->history(_new_history()) unless $self->history; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 49 | ▶ | $self->history->name('backgammon') unless defined $self->history->name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 49 | $self->history->version($VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 49 | ▶ | $self->history->file($self->save_file) if defined $self->save_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 49 | ▶ | $self->picking($self->interactive ? 1 : 0) unless defined $self->picking; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 49 | ▶ | $self->picking(0) unless $self->_keys_available; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 49 | $self->screen->utf8->flush_on; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 49 | return; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 49 | ▶ | sub _new_history { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_history: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | return Game::Terminal::Kit::History->new( | ||||||||||||||||||||||||||||||||||||||||||
| 153 | name => 'backgammon', | ||||||||||||||||||||||||||||||||||||||||||
| 154 | version => $VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 190 | ▶ | save => sub { $_[0]->to_text }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 18 | ▶ | load => sub { Game::Backgammon->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 49 | ); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 31522 | ▶ | sub say_to { my ($self, @what) = @_; $self->screen->say(join '', @what); return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 10490 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 10490 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 10490 | ▶ | $view ||= $self->view || $self->game->turn; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$view ||= $self->view || $self->game->turn
$self->view || $self->game->turn
MC/DC0%0/3
$view ||= $self->view || $self->game->turn
$view
$self->view
$self->game->turn
Truth table0%0/4
A ||= B || C
A= $viewB= $self->viewC= $self->game->turn
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 10490 | my $board = $self->game->board; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 10490 | my $other = Game::Backgammon::Board::other($view); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 10490 | my @lines = ( | |||||||||||||||||||||||||||||||||||||||||
| 169 | $self->_border(13 .. 24), | ||||||||||||||||||||||||||||||||||||||||||
| 170 | $self->_half($view, [13 .. 24], 0), | ||||||||||||||||||||||||||||||||||||||||||
| 171 | ' |' . (' ' x 18) . '|' . $self->_label('BAR') . '|' | ||||||||||||||||||||||||||||||||||||||||||
| 172 | . (' ' x 18) . '|' . $self->_label('OFF') . '|', | ||||||||||||||||||||||||||||||||||||||||||
| 173 | $self->_half($view, [reverse 1 .. 12], 1), | ||||||||||||||||||||||||||||||||||||||||||
| 174 | $self->_border(reverse 1 .. 12) | ||||||||||||||||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 10490 | $lines[1] .= sprintf ' %-5s %3d pips', ucfirst $other, $board->pip_count($other); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 10490 | $lines[11] .= sprintf ' %-5s %3d pips', ucfirst $view, $board->pip_count($view); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 10490 | ▶ | if (my $last = $self->game->history->[-1]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 10440 | $lines[6] .= sprintf ' last: %s %s', $last->player, $last->notation; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 10490 | push @lines, sprintf ' the points are numbered from %s', $view; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 10490 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 10336 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 10336 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 10336 | return join "\n", @{ $self->board_lines($view) }; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 20980 | ▶ | sub _border { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_border: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 20980 | my ($self, @points) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 20980 | my @cell = map { my $c = sprintf '%2d-', $_; $c =~ s/\A /-/; $c } @points; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 20980 | return ' ' . $self->_label( | |||||||||||||||||||||||||||||||||||||||||
| 195 | '+' . join('', @cell[0 .. 5]) . '+---+' . join('', @cell[6 .. 11]) . '+---+' | ||||||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 20980 | ▶ | sub _half { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_half: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 20980 | my ($self, $view, $points, $bottom) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 20980 | my $board = $self->game->board; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 20980 | my $other = Game::Backgammon::Board::other($view); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 20980 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 20980 | for my $row (0 .. ROWS - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 205 | 104900 | ▶ | my $edge = $bottom ? ROWS - 1 - $row : $row; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 104900 | ▶ | my $middle = $bottom ? $row : ROWS - 1 - $row; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 104900 | my @cell; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 104900 | for my $n (@$points) { | |||||||||||||||||||||||||||||||||||||||||
| 209 | 1258800 | my ($mine, $theirs) = $board->point_for($view, $n); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 1258800 | ▶ | push @cell, $mine | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | ? $self->_cell($view, $mine, $edge, $n) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | : $self->_cell($other, $theirs, $edge, $n); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 104900 | ▶ | my $bar = $bottom | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | ? $self->_cell($other, $board->bar($other), $middle) | ||||||||||||||||||||||||||||||||||||||||||
| 216 | : $self->_cell($view, $board->bar($view), $middle); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 104900 | ▶ | my $off = $bottom | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | ? $self->_cell($view, $board->off($view), $edge) | ||||||||||||||||||||||||||||||||||||||||||
| 219 | : $self->_cell($other, $board->off($other), $edge); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 104900 | push @lines, ' ' . $self->_label('|') . join('', @cell[0 .. 5]) | |||||||||||||||||||||||||||||||||||||||||
| 221 | . $self->_label('|') . $bar . $self->_label('|') | ||||||||||||||||||||||||||||||||||||||||||
| 222 | . join('', @cell[6 .. 11]) . $self->_label('|') . $off | ||||||||||||||||||||||||||||||||||||||||||
| 223 | . $self->_label('|'); | ||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 20980 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 1468600 | ▶ | sub _cell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 1468600 | my ($self, $player, $count, $edge, $point) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 1468600 | ▶ | return $self->_ground($point, ' ') unless $count && $edge < ROWS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count and $edge < 5
MC/DC50%1/2
$count and $edge < 5
$count
$edge < 5
Truth table66%2/3
A and B
A= $countB= $edge < 5
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 427555 | ▶ | return $self->_ground( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$edge == 4 and $count > 5
MC/DC100%2/2
$edge == 4 and $count > 5
$edge == 4
$count > 5
Truth table100%3/3
A and B
A= $edge == 4B= $count > 5
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | $point, $count > 9 ? "$count " : " $count ", $player | ||||||||||||||||||||||||||||||||||||||||||
| 233 | ) if $edge == ROWS - 1 && $count > ROWS; | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 407178 | ▶ | return $self->_ground($point, ' ') unless $edge < $count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | return $self->_ground( | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 172374 | ▶ | $point, ' ' . $CHECKER{$player}{$self->ascii ? 'ascii' : 'wide'} . ' ', $player | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 1468600 | ▶ | sub _ground { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ground: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1468600 | my ($self, $point, $text, $player) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | return $player | ||||||||||||||||||||||||||||||||||||||||||
| 243 | ? $self->_paint($text, $CHECKER{$player}{colour}) | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 1468600 | ▶ | : $text | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->colour and defined $point
MC/DC100%2/2
$self->colour and defined $point
$self->colour
defined $point
Truth table100%3/3
A and B
A= $self->colourB= defined $point
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | unless $self->colour && defined $point; | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 840 | my $mark = $self->highlight->{$point}; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 840 | ▶ | $mark = $point % 2 ? 'dark' : 'light' unless $mark && $GROUND{$mark}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$mark and $GROUND{$mark}
MC/DC50%1/2
$mark and $GROUND{$mark}
$mark
$GROUND{$mark}
Truth table66%2/3
A and B
A= $markB= $GROUND{$mark}
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 840 | my @code = ($GROUND{$mark}); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 840 | ▶ | push @code, $CHECKER{$player}{ink} if $player; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 840 | return "\e[" . join(';', @code) . "m$text\e[0m"; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 566460 | ▶ | sub _label { my ($self, $text) = @_; return $self->_paint($text, '2') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_label: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 759005 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 759005 | my ($self, $text, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 759005 | return $self->screen->paint($text, $code); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 10335 | ▶ | sub clear { my ($self) = @_; $self->screen->clear; return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 10251 | ▶ | sub raw { my ($self) = @_; return $self->keyboard->raw } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 49 | ▶ | sub _keys_available { my ($self) = @_; return $self->keyboard->keys_available } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys_available: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 23 | ▶ | sub _enter_raw { my ($self) = @_; return $self->keyboard->enter_raw ? $self : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_raw: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub _leave_raw { my ($self) = @_; $self->keyboard->leave_raw; return $self } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_leave_raw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 163 | ▶ | sub _read_key { my ($self) = @_; return $self->keyboard->read_key } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 10372 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=13 SCAR=26.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 10372 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 10372 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 10372 | ▶ | return 0 if $game->status ne 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 10372 | my $who = $game->turn; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 10372 | my $person = $self->_at_keys($who); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 10372 | ▶ | my $picking = $self->picking && $self->raw && $person; | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->picking && $self->raw && $person
$self->picking and $self->raw
MC/DC66%2/3
$self->picking && $self->raw && $person
$self->picking
$self->raw
$person
Truth table75%3/4
A and B && C
A= $self->pickingB= $self->rawC= $person
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 10372 | ▶ | unless ($picking) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 10309 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 10309 | $self->say_to($self->render($who)); | |||||||||||||||||||||||||||||||||||||||||
| 284 | 10309 | $self->say_to(sprintf ' %s to play %s', $who, join '-', @{ $game->dice }); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 10309 | $self->_say_notes; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 10372 | my $turns = $game->legal_turns; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 10372 | ▶ | if ($turns->[0]->is_forfeit && @$turns == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$turns->[0]->is_forfeit and @$turns == 1
MC/DC50%1/2
$turns->[0]->is_forfeit and @$turns == 1
$turns->[0]->is_forfeit
@$turns == 1
Truth table66%2/3
A and B
A= $turns->[0]->is_forfeitB= @$turns == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 28 | ▶ | if ($picking) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | ▶ | $self->say_to($self->render($self->view || $who)); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->view || $who
MC/DC0%0/2
$self->view || $who
$self->view
$who
Truth table33%1/3
A || B
A= $self->viewB= $who
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | $self->say_to(sprintf ' %s to play %s', $who, join '-', @{ $game->dice }); | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 28 | $self->say_to(' no play'); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 28 | $game->play($turns->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 28 | return $self->_played; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 10344 | ▶ | $self->person_turn if $person; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 10344 | my $turn = $self->_ask($who, $turns); | |||||||||||||||||||||||||||||||||||||||||
| 302 | 10344 | ▶ | return 0 unless $turn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 10322 | ▶ | return 1 unless ref $turn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | $game->play($turn) or do { $self->say_to(' ' . $@->message); return 1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 10310 | $self->say_to(' ' . $turn->notation); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 10310 | return $self->_played; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 10372 | ▶ | sub _at_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_at_keys: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 10372 | my ($self, $who) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 10372 | ▶ | return 1 if $self->mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 10367 | ▶ | return $self->mode eq 'bot' && $who eq $self->seat ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->mode eq "bot" and $who eq $self->seat
MC/DC100%2/2
$self->mode eq "bot" and $who eq $self->seat
$self->mode eq "bot"
$who eq $self->seat
Truth table100%3/3
A and B
A= $self->mode eq "bot"B= $who eq $self->seat
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 10338 | ▶ | sub _played { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_played: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 10338 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 10338 | ▶ | return 1 if $self->game->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | ▶ | $self->person_turn unless $self->mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 10310 | ▶ | sub _say_notes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say_notes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 10310 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 10310 | $self->say_to(" $_") for $self->log->lines; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 10310 | $self->log->shown; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 10310 | return; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 146 | ▶ | sub person_turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
person_turn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 146 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 146 | $self->history->turn($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 146 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 13 | ▶ | sub take_back { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
take_back: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 13 | my $game = $self->history->undo; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 13 | ▶ | return $self->_notify('There is nothing to take back.') unless $game; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 10 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||
| 340 | 10 | $self->_notify('Taken back.'); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | ▶ | sub play_again { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_again: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | my $game = $self->history->redo; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | ▶ | return $self->_notify('There is nothing to play again.') unless $game; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | $self->_notify('Played again.'); | |||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 13 | ▶ | sub swap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
swap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 13 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 13 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 13 | $self->highlight({}); | |||||||||||||||||||||||||||||||||||||||||
| 357 | 13 | $self->log->forget; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 17 | ▶ | sub _notify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_notify: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 17 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 17 | $self->log->note($line); | |||||||||||||||||||||||||||||||||||||||||
| 364 | 17 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 10344 | ▶ | sub _ask { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ask: called CC=18 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 10344 | my ($self, $who, $turns) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 10344 | ▶ | return Game::Backgammon::Bot->new(level => $self->level)->choose($self->game) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->mode eq "watch" or $self->mode eq "bot" and $who ne $self->seat
$self->mode eq "bot" and $who ne $self->seat
MC/DC100%3/3
$self->mode eq "watch" or $self->mode eq "bot" and $who ne $self->seat
$self->mode eq "watch"
$self->mode eq "bot"
$who ne $self->seat
Truth table100%4/4
A or B and C
A= $self->mode eq "watch"B= $self->mode eq "bot"C= $who ne $self->seat
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | if $self->mode eq 'watch' | ||||||||||||||||||||||||||||||||||||||||||
| 371 | || ($self->mode eq 'bot' && $who ne $self->seat); | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 143 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 62 | my $turn = $self->_pick_turn($who, $turns); | |||||||||||||||||||||||||||||||||||||||||
| 375 | 62 | $self->highlight({}); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 62 | return $turn; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 81 | $self->say_to($_) for @{ $self->offer_lines($turns) }; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 81 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 381 | 96 | my $line = $self->keyboard->read_line(" $who> ", $self->out); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 96 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 95 | ▶ | return undef if $line eq 'q' || $line eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line eq "q" or $line eq "quit"
MC/DC50%1/2
$line eq "q" or $line eq "quit"
$line eq "q"
$line eq "quit"
Truth table66%2/3
A or B
A= $line eq "q"B= $line eq "quit"
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 77 | ▶ | if ($line eq 'undo' || $line eq 'redo') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$line eq "undo" or $line eq "redo"
MC/DC100%2/2
$line eq "undo" or $line eq "redo"
$line eq "undo"
$line eq "redo"
Truth table100%3/3
A or B
A= $line eq "undo"B= $line eq "redo"
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 6 | ▶ | return 'swapped' if $line eq 'undo' ? $self->take_back : $self->play_again; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | $self->_say_notes; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 71 | ▶ | if (my (undef, $file) = Game::Terminal::Kit::Save::command($line)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 11 | $self->say_to(' ' . $self->save($file)); | |||||||||||||||||||||||||||||||||||||||||
| 391 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 60 | ▶ | return $turns->[ $line - 1 ] if $line =~ /\A\d+\z/ && $line >= 1 && $line <= @$turns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$line =~ /\A\d+\z/ and $line >= 1 and $line <= @$turns
$line =~ /\A\d+\z/ and $line >= 1
MC/DC100%3/3
$line =~ /\A\d+\z/ and $line >= 1 and $line <= @$turns
$line =~ /\A\d+\z/
$line >= 1
$line <= @$turns
Truth table100%4/4
A and B and C
A= $line =~ /\A\d+\z/B= $line >= 1C= $line <= @$turns
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 3 | $self->say_to(' pick a number from the list, or q to stop'); | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 209 | ▶ | sub _matching { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_matching: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 209 | my ($self, $turns, $chosen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 209 | my @match; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 209 | TURN: for my $turn (@$turns) { | |||||||||||||||||||||||||||||||||||||||||
| 402 | 3011 | my $moves = $turn->moves; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 3011 | ▶ | next TURN if @$moves < @$chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 3011 | for my $at (0 .. $#$chosen) { | |||||||||||||||||||||||||||||||||||||||||
| 405 | 2667 | ▶ | next TURN if $moves->[$at]->notation ne $chosen->[$at]->notation; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 1383 | push @match, $turn; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 209 | return \@match; | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 209 | ▶ | sub _next_moves { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_moves: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 209 | my ($self, $match, $chosen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 209 | my (@move, %seen); | |||||||||||||||||||||||||||||||||||||||||
| 415 | 209 | for my $turn (@$match) { | |||||||||||||||||||||||||||||||||||||||||
| 416 | 1466 | ▶ | my $move = $turn->moves->[ scalar @$chosen ] or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 1407 | ▶ | next if $seen{ $move->notation }++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 533 | push @move, $move; | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 209 | return \@move; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 197 | ▶ | sub _complete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_complete: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 197 | my ($self, $match, $chosen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 197 | for my $turn (@$match) { | |||||||||||||||||||||||||||||||||||||||||
| 426 | 1133 | ▶ | return $turn if @{ $turn->moves } == @$chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 139 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 149 | ▶ | sub _move_marks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_move_marks: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 149 | my ($self, $view, $player, $chosen, $hover) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 149 | my %mark; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 480 | ▶ | my $seen = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 480 | my ($point) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 480 | ▶ | return undef if $point eq 'bar' || $point eq 'off'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$point eq "bar" or $point eq "off"
MC/DC100%2/2
$point eq "bar" or $point eq "off"
$point eq "bar"
$point eq "off"
Truth table100%3/3
A or B
A= $point eq "bar"B= $point eq "off"
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 429 | ▶ | return $view eq $player ? $point : 25 - $point; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 149 | }; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 149 | for my $move (@$chosen) { | |||||||||||||||||||||||||||||||||||||||||
| 440 | 92 | for my $end ($move->from, $move->to) { | |||||||||||||||||||||||||||||||||||||||||
| 441 | 184 | ▶ | my $point = $seen->($end) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 160 | $mark{$point} = 'played'; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 149 | ▶ | if ($hover) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 148 | ▶ | if (my $to = $seen->($hover->to)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 147 | ▶ | $mark{$to} = $hover->hit ? 'hit' : 'to'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 148 | ▶ | if (my $from = $seen->($hover->from)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 122 | $mark{$from} = 'from'; | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 149 | return \%mark; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 139 | ▶ | sub _move_items { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_move_items: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 139 | my ($self, $next) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 139 | return [ map { { label => $_->notation, about => $self->_describe($_), value => $_ } } @$next ]; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 67 | ▶ | sub _pick_turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pick_turn: called CC=25 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 67 | my ($self, $who, $turns) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 67 | ▶ | return undef unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 67 | ▶ | my $view = $self->view || $who; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->view || $who
MC/DC0%0/2
$self->view || $who
$self->view
$who
Truth table33%1/3
A || B
A= $self->viewB= $who
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 67 | my $picker = $self->picker; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 67 | my $log = $self->log; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 67 | my (@chosen, $done); | |||||||||||||||||||||||||||||||||||||||||
| 468 | 67 | my $fresh = 1; | |||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 67 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 471 | 199 | ▶ | if ($fresh) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 194 | my $match = $self->_matching($turns, \@chosen); | |||||||||||||||||||||||||||||||||||||||||
| 473 | 194 | my $next = $self->_next_moves($match, \@chosen); | |||||||||||||||||||||||||||||||||||||||||
| 474 | 194 | $done = $self->_complete($match, \@chosen); | |||||||||||||||||||||||||||||||||||||||||
| 475 | 194 | ▶ | return $done if $done && !@$next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$done and not @$next
MC/DC50%1/2
$done and not @$next
$done
not @$next
Truth table66%2/3
A and not(B)
A= $doneB= not @$next
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 139 | $picker->reset($self->_move_items($next)); | |||||||||||||||||||||||||||||||||||||||||
| 477 | $picker->game_keys({ | ||||||||||||||||||||||||||||||||||||||||||
| 478 | k => 'up', j => 'down', v => 'view', '?' => 'help', | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 139 | %{ Game::Terminal::Kit::History->game_keys }, | |||||||||||||||||||||||||||||||||||||||||
| 480 | 139 | ▶ | %{ Game::Terminal::Kit::Save::game_keys() }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | ($done ? (f => 'finish') : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 482 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 139 | $fresh = 0; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | $self->highlight( | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 144 | $self->_move_marks($view, $who, \@chosen, $picker->current) | |||||||||||||||||||||||||||||||||||||||||
| 488 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 144 | $self->_draw_choice($who, $view, $picker, \@chosen, $done); | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 144 | my ($event, $value) = $picker->step($self->_read_key); | |||||||||||||||||||||||||||||||||||||||||
| 492 | 144 | ▶ | if ($event eq 'quit') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | $self->highlight({}); | |||||||||||||||||||||||||||||||||||||||||
| 494 | 5 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 139 | ▶ | if ($event eq 'chosen') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 125 | push @chosen, $value; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 125 | $fresh = 1; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 125 | next; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 14 | ▶ | if ($event eq 'back') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 2 | ▶ | $log->note('nothing taken back: no move chosen yet') unless @chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | pop @chosen; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 2 | $fresh = 1; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 12 | ▶ | next unless $event eq 'key'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 11 | ▶ | return $done if $value eq 'finish'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 11 | ▶ | if ($value eq 'undo' || $value eq 'redo') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$value eq "undo" or $value eq "redo"
MC/DC100%2/2
$value eq "undo" or $value eq "redo"
$value eq "undo"
$value eq "redo"
Truth table100%3/3
A or B
A= $value eq "undo"B= $value eq "redo"
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 9 | ▶ | next unless $value eq 'undo' ? $self->take_back : $self->play_again; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 7 | ▶ | $log->note('The moves chosen this turn were dropped.') if @chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 7 | return 'swapped'; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | ▶ | if ($value eq 'save') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | my $file = Game::Terminal::Kit::Save::ask_file($self->keyboard, $self->screen, | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | default => $self->save_default, head => [ @{ $self->board_lines($view) }, '' ]); | |||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | ▶ | $log->note($self->save($file)) if defined $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | ▶ | $picker->move($value eq 'up' ? -1 : 1) if $value eq 'up' || $value eq 'down'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$value eq "up" or $value eq "down"
MC/DC0%0/2
$value eq "up" or $value eq "down"
$value eq "up"
$value eq "down"
Truth table33%1/3
A or B
A= $value eq "up"B= $value eq "down"
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | ▶ | $self->view($view = Game::Backgammon::Board::other($view)) if $value eq 'view'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | $log->note(@{ $self->_key_lines }) if $value eq 'help'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | sub _key_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key_lines: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | 'up and down choose a move, enter plays it', | |||||||||||||||||||||||||||||||||||||||||
| 529 | 'backspace or escape takes back the move chosen before it', | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 'a digit jumps to that move, v turns the board round', | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 'f finishes the turn where one can end, q stops the game', | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 'u takes back your last turn, r plays it again', | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 'S saves the game, to carry on with --resume or watch with --replay', | ||||||||||||||||||||||||||||||||||||||||||
| 534 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | 144 | ▶ | sub _draw_choice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_choice: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 144 | my ($self, $who, $view, $picker, $chosen, $done) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 144 | my $log = $self->log; | |||||||||||||||||||||||||||||||||||||||||
| 540 | $self->screen->show([ | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 144 | @{ $self->board_lines($view) }, | |||||||||||||||||||||||||||||||||||||||||
| 542 | 144 | ▶ | sprintf(' %s to play %s', $who, join '-', @{ $self->game->dice }), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | (@$chosen | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 91 | ? ' so far: ' . join ' ', map { $_->notation } @$chosen | |||||||||||||||||||||||||||||||||||||||||
| 545 | : ' nothing chosen yet'), | ||||||||||||||||||||||||||||||||||||||||||
| 546 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 463 | ▶ | (map { " $_" } $picker->rows), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | ($done ? ('', ' f finishes the turn here') : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 144 | (map { " $_" } $log->lines), | |||||||||||||||||||||||||||||||||||||||||
| 550 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 551 | ' up and down to choose, enter to play it, S to save, ? for the keys', | ||||||||||||||||||||||||||||||||||||||||||
| 552 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 144 | $log->shown; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 144 | return; | |||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 441 | ▶ | sub _describe { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_describe: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 441 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 559 | 441 | my @note; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 441 | ▶ | push @note, 'from the bar' if $move->is_bar; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 441 | ▶ | push @note, 'bears off' if $move->is_off; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 441 | ▶ | push @note, 'hits' if $move->hit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 441 | ▶ | push @note, sprintf 'with the %d', $move->die unless @note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 441 | return join ', ', @note; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 83 | ▶ | sub offer_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer_lines: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 83 | my ($self, $turns) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 83 | my @item = map { sprintf '%2d) %s', $_ + 1, $turns->[$_]->notation } 0 .. $#$turns; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 83 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 83 | for my $item (@item) { | |||||||||||||||||||||||||||||||||||||||||
| 572 | 1231 | ▶ | $width = length $item if length $item > $width; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 83 | ▶ | my $columns = int(74 / ($width + 2)) || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
int 74 / ($width + 2) || 1
MC/DC0%0/1
int 74 / ($width + 2) || 1
int 74 / ($width + 2)
Truth table50%1/2
A
A= int 74 / ($width + 2)
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 83 | ▶ | $columns = 4 if $columns > 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 83 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 83 | ▶ | while (@item) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 503 | my @row = splice @item, 0, $columns; | |||||||||||||||||||||||||||||||||||||||||
| 579 | 503 | my $line = ' ' . join ' ', map { sprintf '%-*s', $width, $_ } @row; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 503 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 581 | 503 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 83 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 25 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 588 | 25 | ▶ | $self->game(Game::Backgammon->new(seed => $self->_seed)) unless $self->game; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 25 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 590 | 25 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 25 | ▶ | Game::Terminal::Kit::Run::guard(sub { $self->_turns }, $self->keyboard, $self->screen); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 25 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 25 | $self->highlight({}); | |||||||||||||||||||||||||||||||||||||||||
| 596 | 25 | ▶ | $self->say_to($self->render($self->mode eq 'bot' ? $self->seat : undef)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 25 | my $r = $self->game->result; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 25 | ▶ | $self->say_to($r ? $r->stringify : 'stopped'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 25 | return $r; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 25 | ▶ | sub _turns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_turns: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 25 | my $guard = 0; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 25 | ▶ | while ($self->step) { last if ++$guard > 10_000 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 25 | return; | |||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 8 | ▶ | sub _seed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seed: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 8 | require Digest::SHA; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 8 | ▶ | open my $ur, '<:raw', '/dev/urandom' or return Digest::SHA::sha256(rand() . $$ . time); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 8 | read $ur, my $bytes, 32; | |||||||||||||||||||||||||||||||||||||||||
| 613 | 8 | close $ur; | |||||||||||||||||||||||||||||||||||||||||
| 614 | 8 | ▶ | return length($bytes) == 32 ? $bytes : Digest::SHA::sha256(rand() . $$ . time); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | 12 | ▶ | sub settings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
settings: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 12 | ▶ | return { mode => $self->mode, level => $self->level, seat => $self->seat, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->view // ""
MC/DC100%1/1
$self->view // ""
$self->view
Truth table100%2/2
A
A= $self->view
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | (length($self->view // '') ? (view => $self->view) : ()) }; | ||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 7 | ▶ | sub save_default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_default: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 7 | my $file = $self->history->file; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 7 | ▶ | return defined $file ? $file : Game::Terminal::Kit::Save::default_file('backgammon'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 12 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 12 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 12 | my $history = $self->history; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 12 | $history->settings($self->settings); | |||||||||||||||||||||||||||||||||||||||||
| 634 | 12 | $history->version($VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 635 | 12 | my $path = eval { $history->saved($self->game)->write_file($file) }; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 12 | ▶ | return 'the game was not saved: ' . Game::Terminal::Kit::Save::why($@) unless $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 12 | $history->file($path); | |||||||||||||||||||||||||||||||||||||||||
| 638 | 12 | return "the game is saved to $path"; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 9 | ▶ | sub read_save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 9 | my ($class, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 643 | 9 | return Game::Terminal::Kit::Save->read_game($file, 'backgammon'); | |||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 3 | ▶ | sub replay_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay_lines: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | 3 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 648 | 3 | my $was = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 3 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||
| 650 | 3 | my @lines = eval { | |||||||||||||||||||||||||||||||||||||||||
| 651 | 3 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 3 | ▶ | (@{ $self->board_lines($self->mode eq 'bot' ? $self->seat : undef) }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | $result ? ' ' . $result->stringify | ||||||||||||||||||||||||||||||||||||||||||
| 654 | 3 | : sprintf(' %s to play %s', $game->turn, join '-', @{ $game->dice })); | |||||||||||||||||||||||||||||||||||||||||
| 655 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 3 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||
| 657 | 3 | $self->game($was); | |||||||||||||||||||||||||||||||||||||||||
| 658 | 3 | ▶ | die $died unless @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 3 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 9 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 9 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 664 | backgammon [--mode bot|hotseat|watch] [--level 1-3] [--seat white|black] | ||||||||||||||||||||||||||||||||||||||||||
| 665 | [--view white|black] [--ascii] [--no-colour] [--no-pick] | ||||||||||||||||||||||||||||||||||||||||||
| 666 | [--save FILE] [--resume FILE | --replay FILE] | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | bot play the computer (the default) | ||||||||||||||||||||||||||||||||||||||||||
| 669 | hotseat two people at one keyboard | ||||||||||||||||||||||||||||||||||||||||||
| 670 | watch the computer against itself | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | --view pin the board to one side's numbering. By default it is drawn | ||||||||||||||||||||||||||||||||||||||||||
| 673 | from the side on roll, because a turn is written in the mover's | ||||||||||||||||||||||||||||||||||||||||||
| 674 | own numbers and the board should agree with the list. | ||||||||||||||||||||||||||||||||||||||||||
| 675 | --ascii O and X instead of the round checkers. | ||||||||||||||||||||||||||||||||||||||||||
| 676 | --no-pick choose a whole turn by number from the list, as 0.01 did, rather | ||||||||||||||||||||||||||||||||||||||||||
| 677 | than one checker at a time with the keys. | ||||||||||||||||||||||||||||||||||||||||||
| 678 | --save FILE where S, or "save", writes the game: FILE, else the file | ||||||||||||||||||||||||||||||||||||||||||
| 679 | it was resumed from, else backgammon.save | ||||||||||||||||||||||||||||||||||||||||||
| 680 | --resume FILE carry on a saved game, with its undo and redo | ||||||||||||||||||||||||||||||||||||||||||
| 681 | --replay FILE watch a saved game a turn at a time; enter plays on | ||||||||||||||||||||||||||||||||||||||||||
| 682 | --help this | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | The board is the usual one: your home board is the bottom right quarter and | ||||||||||||||||||||||||||||||||||||||||||
| 685 | you run into it anticlockwise, the bar is the middle column and the tray the | ||||||||||||||||||||||||||||||||||||||||||
| 686 | one on the right. | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | On a terminal a turn is built one checker at a time: the moves you can make | ||||||||||||||||||||||||||||||||||||||||||
| 689 | with the dice you have left are listed, up and down choose one and enter plays | ||||||||||||||||||||||||||||||||||||||||||
| 690 | it, backspace or escape takes the last one back, and the board shows where the checker | ||||||||||||||||||||||||||||||||||||||||||
| 691 | under the cursor is going. A roll that can be played three hundred ways is | ||||||||||||||||||||||||||||||||||||||||||
| 692 | still only a handful of choices at each step. v turns the board round, u takes | ||||||||||||||||||||||||||||||||||||||||||
| 693 | back your last turn and r plays it again, S saves the game, and q stops. | ||||||||||||||||||||||||||||||||||||||||||
| 694 | Without a terminal, or with --no-pick, every legal turn is numbered and you | ||||||||||||||||||||||||||||||||||||||||||
| 695 | pick one, or type undo, redo or save. | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | Exit status is 0 when the game ended or was stopped, 2 for an option the game | ||||||||||||||||||||||||||||||||||||||||||
| 698 | will not take. | ||||||||||||||||||||||||||||||||||||||||||
| 699 | USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 2 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 2 | { name => 'mode', type => 'enum', choices => [qw(bot hotseat watch)], help => 'you against the program, two people at one keyboard, or two programs' }, | |||||||||||||||||||||||||||||||||||||||||
| 705 | { name => 'level', type => 'int', min => 1, max => 3, help => 'how hard the program plays' }, | ||||||||||||||||||||||||||||||||||||||||||
| 706 | { name => 'seat', type => 'enum', choices => [qw(white black)], help => 'your side' }, | ||||||||||||||||||||||||||||||||||||||||||
| 707 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 26 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=27 SCAR=34.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 26 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 26 | my %default = (mode => 'bot', level => 3, seat => 'white', view => ''); | |||||||||||||||||||||||||||||||||||||||||
| 713 | 26 | my %o = (ascii => 0); | |||||||||||||||||||||||||||||||||||||||||
| 714 | 26 | my ($colour, $pick, $help); | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 26 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 717 | 26 | ▶ | local $SIG{__WARN__} = sub { print STDERR "backgammon: $_[0]" }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | Getopt::Long::GetOptionsFromArray(\@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 'mode=s' => \$o{mode}, | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 'level=i' => \$o{level}, | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 'seat=s' => \$o{seat}, | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 'view=s' => \$o{view}, | ||||||||||||||||||||||||||||||||||||||||||
| 723 | 'ascii' => \$o{ascii}, | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 'colour!' => \$colour, | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 'pick!' => \$pick, | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 'help' => \$help, | ||||||||||||||||||||||||||||||||||||||||||
| 727 | 'save=s' => \$o{save}, | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 'resume=s' => \$o{resume}, | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 'replay=s' => \$o{replay}, | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 26 | ); | |||||||||||||||||||||||||||||||||||||||||
| 731 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 26 | ▶ | if (!$ok) { print STDERR _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 25 | ▶ | if ($help) { print _usage(); return 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | if (@argv) { print STDERR "backgammon: not an option: $argv[0]\n", _usage(); return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | 17 | ▶ | if (my $why = Game::Terminal::Kit::Save::check_flags(\%o)) { print STDERR "backgammon: $why.\n"; return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | 15 | my ($file, $resume, $replay) = delete @o{qw(save resume replay)}; | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 15 | my $save; | |||||||||||||||||||||||||||||||||||||||||
| 739 | 15 | ▶ | if (defined $resume || defined $replay) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $resume or defined $replay
MC/DC100%2/2
defined $resume or defined $replay
defined $resume
defined $replay
Truth table100%3/3
A or B
A= defined $resumeB= defined $replay
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 8 | ▶ | ($save, my $why) = $class->read_save(defined $resume ? $resume : $replay); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | 8 | ▶ | unless ($save) { print STDERR "backgammon: $why.\n"; return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 6 | my $settings = $save->settings; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 6 | ▶ | defined $o{$_} or $o{$_} = $settings->{$_} for grep { defined $settings->{$_} } qw(mode level seat view); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 13 | ▶ | defined $o{$_} or $o{$_} = $default{$_} for keys %default; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | 13 | my %refused = ( | |||||||||||||||||||||||||||||||||||||||||
| 748 | mode => [ qr/\A(?:bot|hotseat|watch)\z/, 'bot, hotseat or watch' ], | ||||||||||||||||||||||||||||||||||||||||||
| 749 | seat => [ qr/\A(?:white|black)\z/, 'white or black' ], | ||||||||||||||||||||||||||||||||||||||||||
| 750 | view => [ qr/\A(?:white|black|)\z/, 'white or black' ], | ||||||||||||||||||||||||||||||||||||||||||
| 751 | level => [ qr/\A[123]\z/, '1 to 3' ], | ||||||||||||||||||||||||||||||||||||||||||
| 752 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 13 | for my $k (qw(mode seat view level)) { | |||||||||||||||||||||||||||||||||||||||||
| 754 | 52 | ▶ | next if $o{$k} =~ $refused{$k}[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | print STDERR "backgammon: --$k takes $refused{$k}[1], not '$o{$k}'\n", _usage(); | |||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 13 | ▶ | my $terminal = $class->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | %o, | ||||||||||||||||||||||||||||||||||||||||||
| 761 | (defined $colour ? (colour => $colour) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 762 | (defined $pick ? (picking => $pick) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 763 | (defined $file ? (save_file => $file) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 764 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 13 | ▶ | if (defined $replay) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | my $watch = Game::Terminal::Kit::Replay->new( | ||||||||||||||||||||||||||||||||||||||||||
| 768 | save => $save, | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 3 | ▶ | load => sub { Game::Backgammon->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | 3 | ▶ | draw => sub { $terminal->replay_lines($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 1 | ▶ | head => [ 'backgammon, a replay of ' . $save->file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | . (defined $save->saved_at ? ', saved ' . $save->saved_at : ''), '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 773 | screen => $terminal->screen, | ||||||||||||||||||||||||||||||||||||||||||
| 774 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 775 | my ($event, $step) = Game::Terminal::Kit::Run::guard( | ||||||||||||||||||||||||||||||||||||||||||
| 776 | 1 | ▶ | sub { $watch->play($terminal->keyboard, $terminal->screen) }, $terminal->keyboard, $terminal->screen); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | 1 | ▶ | return 0 unless $event eq 'chosen'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $save = $save->from_step($step); | |||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 12 | ▶ | if ($save) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 5 | my $game = eval { $terminal->history->resume($save) }; | |||||||||||||||||||||||||||||||||||||||||
| 782 | 5 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | print STDERR "backgammon: '" . $save->file . "' cannot be carried on: " | |||||||||||||||||||||||||||||||||||||||||
| 784 | . Game::Terminal::Kit::Save::why($@) . ".\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 5 | ▶ | $terminal->history->file($file) if defined $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 5 | $terminal->game($game); | |||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | my $result = Game::Terminal::Kit::Run::guard( | ||||||||||||||||||||||||||||||||||||||||||
| 792 | 12 | ▶ | sub { $terminal->start }, $terminal->keyboard, $terminal->screen, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 12 | ▶ | return 1 if $result && $terminal->mode eq 'bot' && $result->winner ne $terminal->seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$result and $terminal->mode eq "bot" and $result->winner ne $terminal->seat
$result and $terminal->mode eq "bot"
MC/DC0%0/3
$result and $terminal->mode eq "bot" and $result->winner ne $terminal->seat
$result
$terminal->mode eq "bot"
$result->winner ne $terminal->seat
Truth table25%1/4
A and B and C
A= $resultB= $terminal->mode eq "bot"C= $result->winner ne $terminal->seat
| |||||||||||||||||||||||||||||||||||||||||||
| 795 | 12 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | __END__ | ||||||||||||||||||||||||||||||||||||||||||