| 1 | package Game::Senet::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 75 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 75 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 75 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 75 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 75 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 75 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 75 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 75 | ▶ | use Game::Terminal::Kit::Frame; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 75 | ▶ | use Game::Terminal::Kit::History; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 75 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 75 | ▶ | use Game::Terminal::Kit::Replay; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 75 | ▶ | use Game::Terminal::Kit::Run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 75 | ▶ | use Game::Terminal::Kit::Save; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 75 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 75 | ▶ | use Game::Terminal::Kit::Steer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 75 | ▶ | use Game::Senet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 75 | ▶ | use Game::Senet::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 75 | ▶ | use Game::Senet::Variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 75 | ▶ | use Game::Senet::Notation (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 75 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 75 | my (%STYLE, %GLYPH, %SIGN, %OTHER, %ROW_OF, %COL_OF); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 75 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 75 | %STYLE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | title => '1;38;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | grid => '38;5;241', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | label => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sign => '1;38;5;205', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | light => '1;38;5;229', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | dark => '1;38;5;39', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | cursor => '1;38;5;16;48;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | target => '1;38;5;16;48;5;114', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | from => '1;38;5;231;48;5;160', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | recent => '38;5;250', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | face => '1;38;5;229', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | back => '38;5;240', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | key => '1;38;5;214', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | good => '1;38;5;114', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | bad => '1;38;5;203', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | quiet => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 75 | %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | light => "\x{25CF}", dark => "\x{25CB}", face => "\x{25AF}", back => "\x{25AE}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | h => "\x{2500}", v => "\x{2502}", tl => "\x{250C}", tr => "\x{2510}", bl => "\x{2514}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | br => "\x{2518}", td => "\x{252C}", tu => "\x{2534}", lt => "\x{251C}", rt => "\x{2524}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | x => "\x{253C}", ankh => "\x{2625}", turn_a => "\x{2500}\x{2510}", turn_b => "\x{2502}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | turn_c => "\x{2500}\x{2518}", turn_d => "\x{250C}\x{2500}", turn_e => "\x{2502}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | turn_f => "\x{2514}\x{2500}", into => "\x{25B6}", from => "\x{25C0}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | light => 'O', dark => '@', face => '|', back => '#', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | h => '-', v => '|', tl => '+', tr => '+', bl => '+', br => '+', td => '+', tu => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | lt => '+', rt => '+', x => '+', ankh => '+', turn_a => '-.', turn_b => '|', turn_c => "-'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | turn_d => '.-', turn_e => '|', turn_f => "'-", into => '>', from => '<', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 75 | %SIGN = (26 => 'X', 27 => '~', 28 => 'III', 29 => 'II', 30 => 'I'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 75 | %OTHER = (light => 'dark', dark => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 75 | for my $h (1 .. 30) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2250 | my $row = int(($h - 1) / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2250 | $ROW_OF{$h} = $row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2250 | ▶ | $COL_OF{$h} = $row == 1 ? 20 - $h : ($h - 1) % 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 75 | has game => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 75 | has [qw/in out/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 75 | has [qw/interactive colour unicode picking/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 75 | has mode => (is => 'rw', default => 'bot'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 75 | has side => (is => 'rw', default => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 75 | has level => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 75 | has rules => (is => 'rw', default => 'kendall'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 75 | has pieces => (is => 'rw', default => 5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 75 | has first => (is => 'rw', default => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 75 | has seed => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 75 | has pace => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 75 | has save_file => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 75 | has record => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 75 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 75 | has history => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 75 | has sleeper => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 75 | has [qw/_keyboard _screen/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 75 | has _events => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 75 | has _told => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 75 | has _cursor => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 75 | has _note => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 927 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=34 SCAR=35.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 927 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 927 | ▶ | $self->in(\*STDIN) unless $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 927 | ▶ | $self->out(\*STDOUT) unless $self->out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 927 | ▶ | $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 927 | ▶ | $self->colour($self->interactive && !Game::Terminal::Kit::Screen::no_colour() ? 1 : 0) unless defined $self->colour; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
MC/DC0%0/2
$self->interactive and not Game::Terminal::Kit::Screen::no_colour()
$self->interactive
not Game::Terminal::Kit::Screen::no_colour()
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not Game::Terminal::Kit::Screen::no_colour()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 927 | ▶ | $self->unicode($self->interactive ? 1 : 0) unless defined $self->unicode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 927 | ▶ | $self->_keyboard(Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | in => $self->in, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ($self->keysource ? (keysource => $self->keysource) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 927 | ▶ | $self->_screen(Game::Terminal::Kit::Screen->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | out => $self->out, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | interactive => $self->interactive, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | colour => $self->colour, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ascii => $self->unicode ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 927 | ▶ | $self->picking($self->interactive ? 1 : 0) unless defined $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 927 | ▶ | $self->picking(0) unless $self->_keyboard->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 927 | ▶ | $self->pace($self->interactive && !$self->keysource ? 1 : 0) unless defined $self->pace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->interactive and not $self->keysource
MC/DC0%0/2
$self->interactive and not $self->keysource
$self->interactive
not $self->keysource
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $self->keysource
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 927 | ▶ | Carp::croak("Game::Senet::Terminal: mode is bot, hotseat or watch, not '" . $self->mode . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | unless $self->mode =~ /\A(?:bot|hotseat|watch)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 926 | ▶ | Carp::croak("Game::Senet::Terminal: side is light or dark, not '" . $self->side . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | unless $self->side =~ /\A(?:light|dark)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 925 | ▶ | Carp::croak("Game::Senet::Terminal: first is light or dark, not '" . $self->first . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | unless $self->first =~ /\A(?:light|dark)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 924 | ▶ | Carp::croak('Game::Senet::Terminal: pieces is 5 or 7') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | unless $self->pieces =~ /\A[57]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 923 | ▶ | Carp::croak('Game::Senet::Terminal: pace is a number of seconds, 0 or more') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | unless $self->pace =~ /\A\d+(?:\.\d+)?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 921 | ▶ | my $variant = $self->game ? $self->game->variant : $self->_variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 920 | my @levels = Game::Senet::Bot->levels($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 920 | ▶ | $self->level($levels[-1]) unless defined $self->level; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 920 | ▶ | Carp::croak('Game::Senet::Terminal: level is a whole number from 1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | unless $self->level =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 919 | ▶ | $self->level($levels[-1]) if $self->level > $levels[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 919 | ▶ | $self->seed($self->_system_seed) unless defined $self->seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 919 | $self->_events([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 919 | $self->_told(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 919 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 919 | ▶ | if ($self->game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 856 | $self->_told(scalar @{ $self->game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 63 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 919 | ▶ | $self->history($self->_new_history) unless $self->history; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 919 | ▶ | $self->history->name('senet') unless defined $self->history->name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 919 | $self->history->version($VERSION); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 919 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 919 | ▶ | $self->save_file($self->record) if defined $self->record && !defined $self->save_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->record and not defined $self->save_file
MC/DC50%1/2
defined $self->record and not defined $self->save_file
defined $self->record
not defined $self->save_file
Truth table66%2/3
A and not(B)
A= defined $self->recordB= not defined $self->save_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 919 | ▶ | $self->history->file($self->save_file) if defined $self->save_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 919 | $self->_screen->utf8->flush_on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 919 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 816 | ▶ | sub _system_seed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_system_seed: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 816 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 816 | ▶ | if (open my $fh, '<:raw', '/dev/urandom') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 816 | read $fh, $bytes, 16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 816 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 816 | ▶ | return length $bytes == 16 ? $bytes : Digest::SHA::sha256(join '|', 'senet', $$, time, rand); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 129 | ▶ | sub _variant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_variant: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 129 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 129 | my $rules = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 129 | ▶ | return $rules if ref $rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 129 | return Game::Senet::Variant->named($rules, pieces => $self->pieces); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 918 | ▶ | sub _new_history { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_history: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | return Game::Terminal::Kit::History->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | name => 'senet', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | version => $VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1181 | ▶ | save => sub { $_[0]->to_text }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 9 | ▶ | load => sub { Game::Senet->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 918 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 64 | ▶ | sub _fresh_game { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fresh_game: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 64 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 64 | return Game::Senet->new(seed => $self->seed, rules => $self->_variant, first => $self->first); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 311988 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 311988 | my ($self, $text, $style) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 311988 | ▶ | return $text unless defined $style; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 311988 | return $self->_screen->paint($text, $STYLE{$style}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2434 | ▶ | sub _raw { $_[0]->_keyboard->raw } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_raw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 136026 | ▶ | sub _glyph { $GLYPH{ $_[0]->unicode ? 'wide' : 'ascii' }{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glyph: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1300 | ▶ | sub _event { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1300 | my ($self, $side, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1300 | push @{ $self->_events }, { side => $side, text => $text }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1300 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | sub events { [ map { $_->{text} } @{ $_[0]->_events } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2492 | ▶ | sub _person { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_person: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2492 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2492 | ▶ | return 0 if $self->mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 672 | ▶ | return 1 if $self->mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 559 | ▶ | return $side eq $self->side ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 4216 | ▶ | sub _who { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_who: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 4216 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 4216 | ▶ | return ucfirst $side if $self->mode ne 'bot'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 703 | ▶ | return $side eq $self->side ? 'You' : ucfirst $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2939 | ▶ | sub sticks_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sticks_text: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2939 | my ($self, $sticks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2939 | ▶ | return '[ ' . join(' ', map { $self->_paint($self->_glyph($_ ? 'face' : 'back'), $_ ? 'face' : 'back') } @$sticks) . ' ]'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2935 | ▶ | sub roll_words { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
roll_words: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2935 | my ($self, $roll, $again, $bound) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2935 | ▶ | my $words = $roll == 5 ? 'no light face: a roll of 5' : "a roll of $roll"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2935 | ▶ | $words .= ', and throws again' if $again; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2935 | ▶ | $words .= ', for the piece on 26' if $bound; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2935 | return $words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1272 | ▶ | sub _what_it_does { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_what_it_does: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1272 | my ($self, $entry, $rules) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1272 | my @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1272 | ▶ | push @does, 'a backward move: nothing can go forward' if $entry->{back}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1272 | ▶ | push @does, 'swaps with ' . $OTHER{ $entry->{side} } if $entry->{swap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1272 | ▶ | if ($entry->{walk}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 15 | my ($from, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 15 | ▶ | push @does, ($from == 26 ? 'into the House of Water' : 'out of the water') . ": back to $to"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1272 | ▶ | push @does, 'bears off' if $entry->{off}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1272 | my (undef, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1272 | ▶ | push @does, 'onto the House of Happiness' if $to eq '26'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1272 | return @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1235 | ▶ | sub _briefly { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_briefly: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1235 | my ($self, $entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1235 | my ($from, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1235 | my @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1235 | ▶ | push @does, 'back' if $entry->{back}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1235 | ▶ | push @does, 'swaps' if $entry->{swap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1235 | ▶ | push @does, ($from == 26 ? 'into the water' : 'out of the water') . ", to $to" if $entry->{walk}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1235 | ▶ | push @does, 'bears off' if $entry->{off}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1235 | ▶ | push @does, 'onto the House of Happiness' if $to eq '26'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1235 | return @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1299 | ▶ | sub _tell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tell: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1299 | my ($self, $pause) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1299 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1299 | my $log = $game->log; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1299 | my $told = $self->_told; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 1299 | ▶ | while ($told < @$log) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1256 | my $entry = $log->[ $told++ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1256 | $self->_event($entry->{side}, $self->_describe($entry)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1256 | $self->_told($told); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1256 | ▶ | my $slow = !defined $entry->{move} || !$self->_person($entry->{side}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $entry->{'move'} && $self->_person($entry->{'side'})
MC/DC100%2/2
defined $entry->{'move'} && $self->_person($entry->{'side'})
defined $entry->{'move'}
$self->_person($entry->{'side'})
Truth table100%3/3
A && B
A= defined $entry->{'move'}B= $self->_person($entry->{'side'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1256 | ▶ | if ($pause && $slow && $self->_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$pause and $slow and $self->_raw
$pause and $slow
MC/DC66%2/3
$pause and $slow and $self->_raw
$pause
$slow
$self->_raw
Truth table75%3/4
A and B and C
A= $pauseB= $slowC= $self->_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 140 | $self->show('wait'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 140 | $self->_wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1299 | my $turn = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1299 | ▶ | if ($turn && $turn->{bound}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$turn and $turn->{"bound"}
MC/DC100%2/2
$turn and $turn->{"bound"}
$turn
$turn->{"bound"}
Truth table100%3/3
A and B
A= $turnB= $turn->{"bound"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 17 | my $last = $self->_events->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $self->_event($turn->{side}, $self->_who($turn->{side}) . ' throws again for the piece on 26.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 17 | ▶ | unless $last && $last->{text} =~ /for the piece on 26/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$last and $last->{"text"} =~ /for the piece on 26/
MC/DC0%0/2
$last and $last->{"text"} =~ /for the piece on 26/
$last
$last->{"text"} =~ /for the piece on 26/
Truth table33%1/3
A and B
A= $lastB= $last->{"text"} =~ /for the piece on 26/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1299 | $self->_told($told); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1299 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1270 | ▶ | sub _describe { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_describe: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1270 | my ($self, $entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1270 | my $who = $self->_who($entry->{side}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1270 | ▶ | if (!defined $entry->{move}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | return "$who threw " . (defined $entry->{sticks} ? $self->_plain_sticks($entry->{sticks}) . " (a $entry->{roll})" : "a $entry->{roll}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 35 | ▶ | . ' and could not move' . ($entry->{again} ? ': throws again.' : '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1235 | my @does = $self->_briefly($entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | return "$who played " . Game::Senet::Notation::format_display({ %$entry, from => (split /-/, $entry->{move})[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | to => (split /-/, $entry->{move})[1] }, 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | . (@does ? ', ' . join(', ', @does) : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1235 | ▶ | . ($entry->{again} ? '; throws again.' : '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 34 | ▶ | sub _plain_sticks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain_sticks: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 34 | my ($self, $sticks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 34 | ▶ | return defined $sticks ? join('', map { $_ ? $self->_glyph('face') : $self->_glyph('back') } split //, $sticks) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 273 | ▶ | sub _wait { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 273 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 273 | my $pace = $self->pace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 273 | ▶ | return unless $pace > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 273 | ▶ | return $self->sleeper->($pace) if $self->sleeper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | select undef, undef, undef, $pace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 56910 | ▶ | sub candidates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
candidates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 56910 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 56910 | return $self->game->legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 169983 | ▶ | sub place_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 169983 | my ($class, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 169983 | return ($COL_OF{$house}, $ROW_OF{$house}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 55243 | ▶ | sub steer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
steer: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 55243 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 55243 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 55243 | ▶ | return $self->_cursor unless @moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 55243 | my $at = $self->_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 55243 | ▶ | $at = $#moves if $at > $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 55243 | ▶ | if ($key eq 'tab') { $at = Game::Terminal::Kit::Steer::ring(scalar @moves, $at, 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 55243 | ▶ | if ($key eq 'back_tab' || $key eq 'backtab') { $at = Game::Terminal::Kit::Steer::ring(scalar @moves, $at, -1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "back_tab" or $key eq "backtab"
MC/DC50%1/2
$key eq "back_tab" or $key eq "backtab"
$key eq "back_tab"
$key eq "backtab"
Truth table66%2/3
A or B
A= $key eq "back_tab"B= $key eq "backtab"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 55243 | ▶ | if ($key =~ /\A[1-7]\z/ && $key <= @moves) { $at = $key - 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key =~ /\A[1-7]\z/ and $key <= @moves
MC/DC100%2/2
$key =~ /\A[1-7]\z/ and $key <= @moves
$key =~ /\A[1-7]\z/
$key <= @moves
Truth table100%3/3
A and B
A= $key =~ /\A[1-7]\z/B= $key <= @moves
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 55243 | ▶ | if (my ($dx, $dy) = Game::Terminal::Kit::Steer::way($key)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 51983 | my @points = map { [ $self->place_of($_->from) ] } @moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 51983 | $at = Game::Terminal::Kit::Steer::axis(\@points, $at, $dx, $dy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 55243 | $self->_cursor($at); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 55243 | return $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 2983 | ▶ | sub _cells_after { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cells_after: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 2983 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 2983 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 2983 | my (%cell, %home, %mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 2983 | $cell{$_} = $game->at($_) for 1 .. 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 2983 | $home{$_} = $game->home($_) for qw(light dark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 2983 | ▶ | return (\%cell, \%home, \%mark) unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1115 | my $side = $move->side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1115 | $cell{ $move->from } = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1115 | ▶ | if ($move->off) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 34 | $home{$side}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 34 | $mark{"home $side"} = 'target'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1081 | ▶ | if ($move->swap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 191 | $cell{ $move->from } = $OTHER{$side}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 191 | $mark{ $move->from } = 'from'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1081 | $cell{ $move->to } = $side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1081 | $mark{ $move->to } = 'target'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1115 | ▶ | $mark{ $move->from } //= 'cursor'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mark{$move->from} //= "cursor"
MC/DC100%1/1
$mark{$move->from} //= "cursor"
$mark{$move->from}
Truth table100%2/2
A
A= $mark{$move->from}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1115 | return (\%cell, \%home, \%mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 89524 | ▶ | sub _marked { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_marked: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 89524 | my ($self, $text, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 89524 | ▶ | my ($open, $close) = Game::Terminal::Kit::Frame::brackets($mark // 'plain'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mark // "plain"
MC/DC100%1/1
$mark // "plain"
$mark
Truth table100%2/2
A
A= $mark
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 89524 | ▶ | return $self->_paint($open . $text . $close, $mark) if $mark && $mark ne 'recent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mark and $mark ne "recent"
MC/DC100%2/2
$mark and $mark ne "recent"
$mark
$mark ne "recent"
Truth table100%3/3
A and B
A= $markB= $mark ne "recent"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 87294 | return $open . $text . $close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 89490 | ▶ | sub _house_top { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_house_top: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 89490 | my ($self, $h) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 89490 | ▶ | my $sign = $h == 15 ? $self->_glyph('ankh') : $SIGN{$h} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$SIGN{$h} // ""
MC/DC100%1/1
$SIGN{$h} // ""
$SIGN{$h}
Truth table100%2/2
A
A= $SIGN{$h}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 89490 | my $number = sprintf '%-2s ', $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 89490 | my $pad = 3 - length $sign; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 89490 | return $self->_paint($number, 'label') . $self->_paint($sign, 'sign') . (' ' x $pad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 89490 | ▶ | sub _house_piece { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_house_piece: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 89490 | my ($self, $who, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 89490 | ▶ | my $painted = $mark && $mark ne 'recent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$mark && $mark ne 'recent'
MC/DC100%2/2
$mark && $mark ne 'recent'
$mark
$mark ne 'recent'
Truth table100%3/3
A && B
A= $markB= $mark ne 'recent'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 89490 | ▶ | my $inside = !defined $who ? ' ' : $painted ? $self->_glyph($who) : $self->_paint($self->_glyph($who), $who); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 89490 | return ' ' . $self->_marked($inside, $mark) . ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 11932 | ▶ | sub _border { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_border: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 11932 | my ($self, $left, $mid, $right) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 11932 | ▶ | my $g = sub { $self->_glyph($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 11932 | return $self->_paint($g->($left) . join($g->($mid), ($g->('h') x 6) x 10) . $g->($right), 'grid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 8949 | ▶ | sub _row_houses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_row_houses: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 8949 | my ($row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 8949 | ▶ | return $row == 0 ? (1 .. 10) : $row == 1 ? (reverse 11 .. 20) : (21 .. 30); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 5966 | ▶ | sub _home_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_home_line: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 5966 | my ($self, $side, $home, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 5966 | my @shown = map { $self->_paint($self->_glyph($side), $side) } 1 .. $home->{$side}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | $shown[-1] = $self->_marked($self->_glyph($side), 'target') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 5966 | ▶ | if @shown && $mark->{"home $side"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@shown and $$mark{"home $side"}
MC/DC100%2/2
@shown and $$mark{"home $side"}
@shown
$$mark{"home $side"}
Truth table100%3/3
A and B
A= @shownB= $$mark{"home $side"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 5966 | ▶ | return sprintf ' %s home: %s', $self->_paint(sprintf('%-5s', $side), $side), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | @shown ? join(' ', @shown) : $self->_paint('none', 'quiet'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 2983 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 2983 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 2983 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2983 | my ($cell, $home, $mark) = $self->_cells_after($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 2983 | my %recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 2983 | for my $entry (@{ $game->log }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 294013 | ▶ | next unless defined $entry->{move}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 290806 | my (undef, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 290806 | $recent{ $entry->{side} } = $to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2983 | for my $side (keys %recent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 5683 | my $to = $recent{$side}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 5683 | ▶ | next if $to eq 'off'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 5368 | ▶ | $mark->{$to} //= 'recent' if defined $cell->{$to} && $cell->{$to} eq $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
defined $cell->{$to} and $cell->{$to} eq $side
$mark->{$to} //= "recent"
MC/DC100%2/2
defined $cell->{$to} and $cell->{$to} eq $side
defined $cell->{$to}
$cell->{$to} eq $side
MC/DC100%1/1
$mark->{$to} //= "recent"
$mark->{$to}
Truth table100%3/3
A and B
A= defined $cell->{$to}B= $cell->{$to} eq $side
Truth table100%2/2
A
A= $mark->{$to}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 2983 | my $v = $self->_paint($self->_glyph('v'), 'grid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 8949 | ▶ | my $row_lines = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 8949 | my ($row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 8949 | my @houses = _row_houses($row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 8949 | my $top = $v . join($v, map { $self->_house_top($_) } @houses) . $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 8949 | my $low = $v . join($v, map { $self->_house_piece($cell->{$_}, $mark->{$_}) } @houses) . $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 8949 | return ($top, $low); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 2983 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 2983 | my ($r0a, $r0b) = $row_lines->(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 2983 | my ($r1a, $r1b) = $row_lines->(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 2983 | my ($r2a, $r2b) = $row_lines->(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 2983 | ▶ | my $g = sub { $self->_paint($self->_glyph($_[0]), 'grid') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2983 | my $sp = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 2983 | $self->_home_line('dark', $home, $mark), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | $sp . $self->_border('tl', 'td', 'tr'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | $sp . $r0a, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | $sp . $r0b . $g->('into') . $g->('turn_a'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | $sp . $self->_border('lt', 'x', 'rt') . ' ' . $g->('turn_b'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | ' ' . $g->('turn_d') . $g->('from') . $r1a . $g->('from') . $g->('turn_c'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | ' ' . $g->('turn_e') . ' ' . $r1b, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | ' ' . $g->('turn_e') . ' ' . $self->_border('lt', 'x', 'rt'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | ' ' . $g->('turn_f') . $g->('into') . $r2a . $g->('into') . $self->_paint('off', 'grid'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | $sp . $r2b, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | $sp . $self->_border('bl', 'tu', 'br'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | $self->_home_line('light', $home, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2947 | ▶ | sub _shield_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shield_lines: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 2947 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 2947 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 2947 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 2947 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 2947 | for my $side (qw(light dark)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 5894 | my (@runs, $run); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 5894 | for my $h (1 .. 30) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 176820 | ▶ | if (($game->at($h) // '') eq $side) { push @{ $run //= [] }, $h; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$game->at($h) // ""
$run //= []
MC/DC100%1/1
$game->at($h) // ""
$game->at($h)
MC/DC100%1/1
$run //= []
$run
Truth table100%2/2
A
A= $game->at($h)
Truth table100%2/2
A
A= $run
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 151479 | ▶ | push @runs, $run if $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 151479 | undef $run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 5894 | ▶ | push @runs, $run if $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 5894 | my (@kept, @blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5894 | for my $r (grep { @$_ >= 2 } @runs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 4621 | ▶ | push @kept, $variant->protect eq 'run' ? @$r : $variant->protect eq 'ends' ? ($r->[0], $r->[-1]) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 4621 | ▶ | push @blocks, "$r->[0]-$r->[-1]" if $variant->blockade && @$r >= $variant->blockade; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$variant->blockade and @$r >= $variant->blockade
MC/DC50%1/2
$variant->blockade and @$r >= $variant->blockade
$variant->blockade
@$r >= $variant->blockade
Truth table66%2/3
A and B
A= $variant->blockadeB= @$r >= $variant->blockade
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 5894 | ▶ | my @said = ((@kept ? 'protected ' . join(' ', @kept) : 'nothing protected'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | (@blocks ? 'blockades ' . join(' ', @blocks) : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 5894 | push @lines, ' ' . $self->_paint(sprintf('%-5s ', $side) . join('; ', @said), 'quiet'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 2947 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 2947 | ▶ | sub _sticks_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sticks_line: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 2947 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2947 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 2947 | ▶ | return () if $game->is_over || !defined $game->roll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$game->is_over or not defined $game->roll
MC/DC100%2/2
$game->is_over or not defined $game->roll
$game->is_over
not defined $game->roll
Truth table100%3/3
A or not(B)
A= $game->is_overB= not defined $game->roll
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 2929 | my $turn = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | return (sprintf(' %s threw %d %s %s', $self->_who($game->side), $game->throw, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | $self->sticks_text($game->sticks), $self->roll_words($game->roll, $turn->{extra})), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2929 | ▶ | ($turn->{bound} ? ' ' . $self->_paint('This throw is for the piece on 26: it alone may move.', 'key') : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 2947 | ▶ | sub _result_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_line: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2947 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 2947 | ▶ | my $result = $self->game->result or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 16 | ▶ | return ' ' . $self->_paint('The game ran its full length with no end. It is drawn.', 'bad') if $result->is_draw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 16 | my $winner = $result->winner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 16 | ▶ | return ' ' . $self->_paint(sprintf('%s won: %s resigned.', ucfirst $winner, $result->loser), 'good') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | if $result->how eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 16 | my $home = $result->home; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | return ' ' . $self->_paint(sprintf('%s won, all %d home to %d, in %d plies.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 16 | ucfirst $winner, $home->{$winner}, $home->{ $result->loser }, $result->plies), 'good'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 2939 | ▶ | sub _event_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event_lines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 2939 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2939 | my @recent = @{ $self->_events }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2939 | ▶ | @recent = @recent[ -4 .. -1 ] if @recent > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 2939 | ▶ | return map { ' ' . $self->_paint($_->{text}, $_->{side} || 'quiet') } @recent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->{'side'} || 'quiet'
MC/DC100%1/1
$_->{'side'} || 'quiet'
$_->{'side'}
Truth table100%2/2
A
A= $_->{'side'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 1272 | ▶ | sub readout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readout: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 1272 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 1272 | my %entry = (side => $move->side, move => Game::Senet::Notation::format_move($move), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | back => $move->back, swap => $move->swap, walk => $move->walk, off => $move->off); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 1272 | my @does = $self->_what_it_does(\%entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 1272 | ▶ | return $self->_paint(Game::Senet::Notation::format_display($move, 0), 'key') . (@does ? ' ' . join(', ', @does) : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 2040 | ▶ | sub _legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legend: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 2040 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 2040 | ▶ | my $k = sub { $self->_paint($_[0], 'key') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 2040 | ▶ | return ' ' . join(' ', $k->('enter') . ' leave', $k->('n') . ' new game', $k->('u') . ' take back', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | ($self->history->can_redo ? $k->('r') . ' play again' : ()), $k->('S') . ' save') if $mode eq 'ended'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 2035 | ▶ | return ' ' . $self->_paint('...', 'quiet') if $mode eq 'wait'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 1097 | return ' ' . join(' ', $k->('arrows') . ' choose', $k->('enter') . ' move', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | $k->('u') . ' back', $k->('r') . ' again', $k->('S') . ' save', $k->('?') . ' help', $k->('q') . ' leave'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 2939 | ▶ | sub screen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
screen: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2939 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 2939 | ▶ | $mode = 'plain' unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2939 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2939 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 2939 | ▶ | my @lines = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ' ' . $self->_paint('Senet', 'title') . ' ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | . $self->_paint(join(', ', $variant->describe, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | ($self->mode eq 'bot' ? 'you are ' . $self->side . ', against level ' . $self->level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | : $self->mode eq 'hotseat' ? 'two players' : 'level ' . $self->level . ' against itself')), 'quiet'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 2939 | ▶ | if ($mode eq 'help') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | push @lines, map { " $_" } @{ $self->help_lines }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 2939 | ▶ | my @moves = $mode eq 'pick' ? $self->candidates : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 2939 | my $at = $self->_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 2939 | ▶ | $at = $#moves if $at > $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 2939 | ▶ | my $move = @moves ? $moves[$at] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 2939 | push @lines, @{ $self->board_lines($move) }, $self->_shield_lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 2939 | push @lines, $self->_sticks_line, $self->_result_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 2939 | ▶ | push @lines, ' ' . $self->readout($move) if $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2939 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 2939 | push @lines, $self->_event_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 2939 | ▶ | push @lines, ' ' . $self->_paint($self->_note, 'bad') if defined $self->_note; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 2939 | ▶ | push @lines, '', $self->_legend($mode) if $mode eq 'pick' || $mode eq 'ended' || $mode eq 'wait'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$mode eq "pick" or $mode eq "ended" or $mode eq "wait"
$mode eq "pick" or $mode eq "ended"
MC/DC100%3/3
$mode eq "pick" or $mode eq "ended" or $mode eq "wait"
$mode eq "pick"
$mode eq "ended"
$mode eq "wait"
Truth table100%4/4
A or B or C
A= $mode eq "pick"B= $mode eq "ended"C= $mode eq "wait"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 2939 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 442 | ▶ | sub show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 442 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 442 | $self->_screen->show($self->screen($mode)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 442 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | sub help_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | 'A move is a piece. The sticks say how far it goes, so choosing the piece is', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 'the whole move. A roll of 1, 4 or 5 throws again.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | ' arrows, tab walk the pieces that can move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | ' 1 to 7 go straight to one of them', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | ' enter, space move it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | ' u take back your last turn and every reply to it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | ' r play a turn taken back again', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | ' n a new game', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ' S save the game, to carry on with --resume or watch with --replay', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | ' q leave (asked twice)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | ' enter, q leave, once the game is over', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 'The board shows what the move would leave: [ ] the house the piece leaves,', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | '< > where it lands, ( ) the house a swapped piece goes back to, and { } the', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 'last move each side made.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 'Typing instead: a number from the list, or a move such as 12-15 or 26-off;', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 'and undo, redo, new, moves, save [FILE], level N, help, quit.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 9 | ▶ | sub _enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_raw: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 9 | ▶ | return 1 if $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 9 | ▶ | return 0 unless $self->_keyboard->enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 9 | ▶ | $self->_screen->hide_cursor->clear unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 151 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=16 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 151 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 151 | my $leaving = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 151 | ▶ | $self->_cursor(0) if $self->_cursor > $self->candidates - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 151 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 164 | $self->show('pick'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 164 | my $key = $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 164 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC33%1/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table50%2/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 162 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 162 | ▶ | if ($key eq 'q' || $key eq 'escape') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "q" or $key eq "escape"
MC/DC50%1/2
$key eq "q" or $key eq "escape"
$key eq "q"
$key eq "escape"
Truth table66%2/3
A or B
A= $key eq "q"B= $key eq "escape"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 11 | ▶ | return 'quit' if $leaving; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 6 | $leaving = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 6 | $self->_note('Press q again to leave the game, or any other key to stay.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 151 | $leaving = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 151 | ▶ | if ($key eq 'enter' || $key eq ' ') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "enter" or $key eq " "
MC/DC100%2/2
$key eq "enter" or $key eq " "
$key eq "enter"
$key eq " "
Truth table100%3/3
A or B
A= $key eq "enter"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 140 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 140 | ▶ | next unless @moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 140 | return Game::Senet::Notation::format_move($moves[ $self->_cursor ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 11 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 10 | ▶ | return 'redo' if $key eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 10 | ▶ | return 'new' if $key eq 'n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 10 | ▶ | return 'save' if $key eq 'S'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 7 | ▶ | if ($key eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | $self->show('help'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 7 | $self->steer($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 5 | ▶ | sub _ended_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ended_key: called CC=12 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 5 | $self->show('ended'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 5 | my $key = $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 5 | ▶ | return undef if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC0%0/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table25%1/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 5 | ▶ | return 'new' if $key eq 'n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 4 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 4 | ▶ | return 'redo' if $key eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 4 | ▶ | return 'save' if $key eq 'S'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 4 | ▶ | return 'quit' if $key eq 'q' || $key eq 'escape' || $key eq 'enter' || $key eq ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$key eq "q" or $key eq "escape" or $key eq "enter" or $key eq " "
$key eq "q" or $key eq "escape" or $key eq "enter"
$key eq "q" or $key eq "escape"
MC/DC0%0/4
$key eq "q" or $key eq "escape" or $key eq "enter" or $key eq " "
$key eq "q"
$key eq "escape"
$key eq "enter"
$key eq " "
Truth table60%3/5
A or B or C or D
A= $key eq "q"B= $key eq "escape"C= $key eq "enter"D= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 168 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 168 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 168 | ▶ | $self->_screen->say(@lines) if @lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 168 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 78 | ▶ | sub _read_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_line: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 78 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 78 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 78 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 78 | $self->_say(@{ $self->screen('plain') }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 78 | ▶ | if (!$game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 78 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 78 | $self->_say(map { sprintf ' %s %s', $self->_paint($_ + 1, 'key'), $self->readout($moves[$_]) } 0 .. $#moves); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 78 | ▶ | my $line = $self->_keyboard->read_line( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | $game->is_over ? 'new, undo, or enter to leave> ' : $game->side . ' (' . $game->roll . ')> ', $out); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 78 | ▶ | print {$out} "\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 78 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 245 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=33 SCAR=44.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 245 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 245 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 245 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 245 | ▶ | return 0 unless defined $line && length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $line and length $line
MC/DC0%0/2
defined $line and length $line
defined $line
length $line
Truth table33%1/3
A and B
A= defined $lineB= length $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 245 | my ($word, $rest) = split ' ', $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 245 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 245 | ▶ | return 1 if $word eq 'quit' || $word eq 'q' || $word eq 'exit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$word eq "quit" or $word eq "q" or $word eq "exit"
$word eq "quit" or $word eq "q"
MC/DC33%1/3
$word eq "quit" or $word eq "q" or $word eq "exit"
$word eq "quit"
$word eq "q"
$word eq "exit"
Truth table50%2/4
A or B or C
A= $word eq "quit"B= $word eq "q"C= $word eq "exit"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 191 | ▶ | if ($word eq 'help' || $word eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word eq "help" or $word eq "?"
MC/DC0%0/2
$word eq "help" or $word eq "?"
$word eq "help"
$word eq "?"
Truth table33%1/3
A or B
A= $word eq "help"B= $word eq "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | $self->_say(map { " $_" } @{ $self->help_lines }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 191 | ▶ | if ($word eq 'new' || $word eq 'n') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "new" or $word eq "n"
MC/DC50%1/2
$word eq "new" or $word eq "n"
$word eq "new"
$word eq "n"
Truth table66%2/3
A or B
A= $word eq "new"B= $word eq "n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 1 | $self->seed(Digest::SHA::sha256($self->seed . 'next')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 1 | $self->_events([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 1 | $self->_told(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 1 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 190 | ▶ | if ($word eq 'undo' || $word eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "undo" or $word eq "u"
MC/DC50%1/2
$word eq "undo" or $word eq "u"
$word eq "undo"
$word eq "u"
Truth table66%2/3
A or B
A= $word eq "undo"B= $word eq "u"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 3 | $self->take_back; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 187 | ▶ | if ($word eq 'redo' || $word eq 'r') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word eq "redo" or $word eq "r"
MC/DC0%0/2
$word eq "redo" or $word eq "r"
$word eq "redo"
$word eq "r"
Truth table33%1/3
A or B
A= $word eq "redo"B= $word eq "r"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | $self->play_again; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 187 | ▶ | if ($word eq 'moves') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | $self->_say(map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | ' ' . (defined $_->{move} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | ? Game::Senet::Notation::format_display({ %$_, from => (split /-/, $_->{move})[0], to => (split /-/, $_->{move})[1] }, $_->{again}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 5 | ▶ | : Game::Senet::Notation::format_forfeit($_->{roll}, $_->{again})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 2 | } @{ $game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 185 | ▶ | if ($word eq 'save' || $word eq 'record') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word eq "save" or $word eq "record"
MC/DC50%1/2
$word eq "save" or $word eq "record"
$word eq "save"
$word eq "record"
Truth table66%2/3
A or B
A= $word eq "save"B= $word eq "record"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 12 | ▶ | my $file = defined $rest && length $rest ? $rest : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $rest and length $rest
MC/DC50%1/2
defined $rest and length $rest
defined $rest
length $rest
Truth table66%2/3
A and B
A= defined $restB= length $rest
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 12 | ▶ | if (!defined $file && $self->_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $file and $self->_raw
MC/DC100%2/2
not defined $file and $self->_raw
not defined $file
$self->_raw
Truth table100%3/3
not(A) and B
A= not defined $fileB= $self->_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 3 | $file = Game::Terminal::Kit::Save::ask_file($self->_keyboard, $self->_screen, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | default => $self->save_default, head => $self->screen('plain')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 3 | ▶ | return 0 unless defined $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 11 | $self->save($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 11 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 173 | ▶ | if ($word eq 'level') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | my @levels = Game::Senet::Bot->levels($game->variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | if (defined $rest && $rest =~ /\A\d+\z/ && $rest >= 1 && $rest <= $levels[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1
defined $rest and $rest =~ /\A\d+\z/
MC/DC0%0/4
defined $rest and $rest =~ /\A\d+\z/ and $rest >= 1 and $rest <= $levels[-1]
defined $rest
$rest =~ /\A\d+\z/
$rest >= 1
$rest <= $levels[-1]
Truth table0%0/5
A and B and C and D
A= defined $restB= $rest =~ /\A\d+\z/C= $rest >= 1D= $rest <= $levels[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | $self->level($rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $self->_event(undef, "The program now plays at level $rest."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | else { $self->_note('A level is a number from 1 to ' . $levels[-1] . '.') } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 173 | ▶ | if ($game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | $self->_note('The game is over. Type new, undo or quit.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 173 | my $move = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 173 | ▶ | if ($line =~ /\A[1-7]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 35 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 35 | ▶ | if ($line > @moves) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | $self->_note('There are only ' . scalar(@moves) . ' moves to choose from.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 35 | $move = $moves[ $line - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 173 | ▶ | if ($game->play($move)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 173 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 173 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my $error = $game->error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | ▶ | $self->_note($error->code eq 'bad_move' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | ? "I do not know '$line'. A move is two houses, like 12-15 or 26-off, or its number in the list." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | : ucfirst($error->message) . '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 173 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 4 | ▶ | sub take_back { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
take_back: called CC=2 SCAR=7.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 4 | $self->_keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 4 | my $game = $self->history->undo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 4 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | $self->_note('There is nothing to take back.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 4 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 4 | $self->_event(undef, 'Taken back.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | sub play_again { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_again: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | $self->_keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | my $game = $self->history->redo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | $self->_note('There is nothing to play again.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | $self->_event(undef, 'Played again.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 4 | ▶ | sub _keep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keep: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 4 | ▶ | $self->history->record($self->game) if $self->mode ne 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 4 | ▶ | sub swap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
swap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 4 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 4 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 4 | $self->_told(scalar @{ $game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 4 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 4 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 244 | ▶ | sub person_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
person_turn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 244 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 244 | $self->history->turn($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 244 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 15 | ▶ | sub settings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
settings: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 15 | my $variant = $self->game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | mode => $self->mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | side => $self->side, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | level => $self->level, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | first => $self->first, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | pieces => $variant->pieces, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 15 | ▶ | ((grep { $_ eq $variant->exits } Game::Senet::Variant->names) ? (rules => $variant->exits) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 15 | ▶ | sub save_default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_default: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 15 | my $file = $self->history->file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 15 | ▶ | return defined $file ? $file : Game::Terminal::Kit::Save::default_file('senet'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 15 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 15 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 15 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 15 | my $history = $self->history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 15 | $history->settings($self->settings); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 15 | $history->version($VERSION); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 15 | my $path = eval { $history->saved($self->game)->write_file($file) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 15 | ▶ | unless ($path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 1 | $self->_note('The game was not saved: ' . _plain($@) . '.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 14 | $history->file($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 14 | $self->_event(undef, "The game is saved to $path."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 20 | ▶ | sub _plain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 20 | my ($why) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 20 | ▶ | $why = 'it failed without a reason' unless defined $why && length $why; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $why and length $why
MC/DC0%0/2
defined $why and length $why
defined $why
length $why
Truth table33%1/3
A and B
A= defined $whyB= length $why
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 20 | $why =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 20 | $why =~ s/\A(?:Game::Terminal::Kit::\w+|Game::Senet(?:::\w+)*): //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 20 | $why =~ s/\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 20 | return $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 8 | ▶ | sub replay_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay_lines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 8 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 8 | my $was = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 8 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 8 | my @lines = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 8 | my @log = @{ $game->log }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 8 | ▶ | @log = @log[ -4 .. -1 ] if @log > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 8 | ▶ | (@{ $self->board_lines }, $self->_shield_lines, '', $self->_sticks_line, $self->_result_line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 8 | (@log ? '' : ()), map { ' ' . $self->_paint($self->_describe($_), $_->{side}) } @log); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 8 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 8 | $self->game($was); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 8 | ▶ | die $died unless @lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 8 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 18 | ▶ | sub read_save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_save: called CC=16 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 18 | my ($class, $file, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 18 | my $save = eval { Game::Terminal::Kit::Save->read_file($file, game => 'senet') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 18 | ▶ | return $save if $save; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 11 | my $why = _plain($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 11 | ▶ | return (undef, $why) unless $why =~ /is not a saved game\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | # Not a save: a record, as --record wrote before saves were kept. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 6 | ▶ | open my $fh, '<', $file or return (undef, "I could not read '$file'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 6 | my $text = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 6 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 6 | my ($game, $error) = Game::Senet->replay($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 6 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 2 | my $detail = $error->detail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | return (undef, "'$file' is not a game I can replay: " . $error->message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 2 | ▶ | . (defined $detail->{line} ? " (line $detail->{line})" : defined $detail->{ply} ? ' (ply ' . ($detail->{ply} + 1) . ')' : '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 4 | my $current = $game->to_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 4 | my @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 4 | ▶ | if (($option{steps} || '') eq 'ply') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$option{'steps'} || ''
MC/DC100%1/1
$option{'steps'} || ''
$option{'steps'}
Truth table100%2/2
A
A= $option{'steps'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 2 | my ($record) = Game::Senet::Notation::parse_record($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 2 | ▶ | my @plies = @{ $record->{plies} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$record->{'plies'} || []
MC/DC0%0/1
$record->{'plies'} || []
$record->{'plies'}
Truth table50%1/2
A
A= $record->{'plies'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 2 | for my $n (0 .. $#plies) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 7 | my ($before) = Game::Senet->replay({ %{$record}, plies => [ @plies[0 .. $n - 1] ], result => undef }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 7 | ▶ | next unless $before; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 7 | my $step = $before->to_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 7 | ▶ | push @steps, $step unless @steps && $steps[-1] eq $step; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@steps and $steps[-1] eq $step
MC/DC0%0/2
@steps and $steps[-1] eq $step
@steps
$steps[-1] eq $step
Truth table66%2/3
A and B
A= @stepsB= $steps[-1] eq $step
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 2 | ▶ | pop @steps while @steps && $steps[-1] eq $current; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@steps and $steps[-1] eq $current
MC/DC0%0/2
@steps and $steps[-1] eq $current
@steps
$steps[-1] eq $current
Truth table33%1/3
A and B
A= @stepsB= $steps[-1] eq $current
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 4 | $save = Game::Terminal::Kit::Save->new(name => 'senet', past => \@steps, current => $current); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 4 | $save->file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 4 | return $save; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 1048 | ▶ | sub _bot_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_move: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 1048 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 1048 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 1048 | my $bot = Game::Senet::Bot->new(level => $self->level); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 1048 | ▶ | my $move = $bot->choose($game) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 1048 | ▶ | if ($self->_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 133 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 133 | my ($at) = grep { $moves[$_] == $move } 0 .. $#moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 133 | ▶ | $self->_cursor($at // 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$at // 0
MC/DC0%0/1
$at // 0
$at
Truth table50%1/2
A
A= $at
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 133 | $self->show('pick'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 133 | $self->_wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 1048 | $game->play_or_die($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 1048 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 1048 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 1048 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 61 | ▶ | sub _turns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_turns: called CC=14 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 61 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 61 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 61 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 1282 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 1282 | ▶ | my $picking = $self->picking && $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->picking && $self->_raw
MC/DC50%1/2
$self->picking && $self->_raw
$self->picking
$self->_raw
Truth table66%2/3
A && B
A= $self->pickingB= $self->_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 1282 | ▶ | if ($game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 11 | ▶ | last if $self->mode eq 'watch' && !$self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->mode eq "watch" and not $self->interactive
MC/DC50%1/2
$self->mode eq "watch" and not $self->interactive
$self->mode eq "watch"
not $self->interactive
Truth table66%2/3
A and not(B)
A= $self->mode eq "watch"B= not $self->interactive
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 5 | ▶ | my $line = $picking ? $self->_ended_key : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 5 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 5 | ▶ | last if !$picking && $line eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $picking and $line eq ""
MC/DC0%0/2
not $picking and $line eq ""
not $picking
$line eq ""
Truth table33%1/3
not(A) and B
A= not $pickingB= $line eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 5 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 1 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 1271 | ▶ | if (!$self->_person($game->side)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 1048 | $self->_bot_move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 1048 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 223 | $self->person_turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 223 | ▶ | my $line = $picking ? $self->pick : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 223 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 222 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 61 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 61 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 61 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 61 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 61 | ▶ | Game::Terminal::Kit::Run::guard(sub { $self->_turns }, $self->_keyboard, $self->_screen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 61 | ▶ | $self->_say(@{ $self->screen('plain') }) if $self->mode eq 'watch' || $self->game->is_over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->mode eq "watch" or $self->game->is_over
MC/DC100%2/2
$self->mode eq "watch" or $self->game->is_over
$self->mode eq "watch"
$self->game->is_over
Truth table100%3/3
A or B
A= $self->mode eq "watch"B= $self->game->is_over
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 61 | my $result = $self->game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 61 | ▶ | return 1 if $self->mode eq 'bot' && $result && defined $result->winner && $result->winner ne $self->side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$self->mode eq "bot" and $result and defined $result->winner and $result->winner ne $self->side
$self->mode eq "bot" and $result and defined $result->winner
$self->mode eq "bot" and $result
MC/DC50%2/4
$self->mode eq "bot" and $result and defined $result->winner and $result->winner ne $self->side
$self->mode eq "bot"
$result
defined $result->winner
$result->winner ne $self->side
Truth table60%3/5
A and B and C and D
A= $self->mode eq "bot"B= $resultC= defined $result->winnerD= $result->winner ne $self->side
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 60 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 5 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 5 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | senet - Senet, the race game of ancient Egypt, in a terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | senet [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | --mode HOW bot (the default): you against the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | hotseat: two people at one keyboard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | watch: the program against itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | --rules NAME kendall (the default) or skyruk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | --pieces N 5 (the default) or 7 a side | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | --level N how well the program plays, 1 upward; the top by default, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | and above the top plays the top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | --side WHICH light (the default) or dark: your side against the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | --first WHO light (the default) or dark: who throws first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | --seed HEX hexadecimal; the same seed throws the same sticks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | --pace SECONDS how long a lost turn and the program's move stay up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | --save FILE where S, or save, writes the game: FILE, else the file it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | was resumed from, else senet.save | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | --resume FILE carry on a saved game, with its undo and redo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | --replay FILE watch a saved game a step at a time; enter plays on from there | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | --record FILE the old name for --save | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | --ascii plain letters and lines, for a terminal with no Unicode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | --unicode line and shape characters, where they are not the default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | --no-colour no colour; nothing is lost without it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | --no-pick type moves instead of choosing them with the arrow keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | --version the version, and stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | --help this, and stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | In a terminal, the pieces that can move are walked with the arrow keys and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | board shows what each move would leave; press ? for the keys. Anywhere else, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | type a number from the list, a move such as 12-15 or 26-off, or help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | A record written by --record before 0.03 can be given to --resume and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | --replay as it is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 1 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 1 | my $top = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 1 | for my $name (Game::Senet::Variant->names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 2 | my @levels = Game::Senet::Bot->levels($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 2 | ▶ | $top = $levels[-1] if $levels[-1] > $top; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 1 | { name => 'mode', type => 'enum', choices => [qw(bot hotseat watch)], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | help => 'you against the program, two people, or the program against itself' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | { name => 'rules', type => 'enum', choices => [ Game::Senet::Variant->names ], help => 'the rules' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | { name => 'pieces', type => 'enum', choices => [qw(5 7)], help => 'pieces a side' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | { name => 'level', type => 'int', min => 1, max => $top, help => 'how well the program plays; the top by default' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | { name => 'side', type => 'enum', choices => [qw(light dark)], help => 'your side against the program' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | { name => 'first', type => 'enum', choices => [qw(light dark)], help => 'who throws first' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | { name => 'seed', type => 'str', help => 'hexadecimal; the same seed throws the same sticks' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 79 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 79 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 79 | my $saved = Getopt::Long::Configure(qw(default no_ignore_case no_auto_abbrev)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 79 | my %given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 79 | my $parsed = Getopt::Long::GetOptionsFromArray( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | \@argv, \%given, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 'mode=s', 'rules=s', 'pieces=i', 'level=i', 'side=s', 'first=s', 'seed=s', 'pace=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | Game::Terminal::Kit::Save::flags(), 'record=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 'ascii', 'unicode!', 'colour|color!', 'pick!', 'version', 'help', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 79 | Getopt::Long::Configure($saved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 79 | ▶ | if (!$parsed || @argv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $parsed or @argv
MC/DC100%2/2
not $parsed or @argv
not $parsed
@argv
Truth table100%3/3
not(A) or B
A= not $parsedB= @argv
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 3 | ▶ | print STDERR "senet: I do not know '@argv'.\n" if $parsed && @argv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$parsed and @argv
MC/DC50%1/2
$parsed and @argv
$parsed
@argv
Truth table66%2/3
A and B
A= $parsedB= @argv
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 3 | print STDERR _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 3 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 76 | ▶ | if ($given{help}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 2 | print _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 74 | ▶ | if ($given{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 3 | print "senet $Game::Senet::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 71 | ▶ | if (defined $given{record}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 2 | print STDERR "senet: --record is now --save, and the game is written when you save it: S, or save.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 2 | ▶ | $given{save} = $given{record} unless defined $given{save}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 71 | ▶ | if (my $why = Game::Terminal::Kit::Save::check_flags(\%given)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 2 | print STDERR "senet: $why.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 69 | my %with; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 69 | $with{$_} = $given{$_} for grep { defined $given{$_} } qw(mode rules pieces level side first pace); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 69 | ▶ | $with{save_file} = $given{save} if defined $given{save}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 69 | ▶ | $with{colour} = $given{colour} if defined $given{colour}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 69 | ▶ | $with{picking} = $given{pick} if defined $given{pick}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 69 | ▶ | $with{unicode} = $given{unicode} if defined $given{unicode}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 69 | ▶ | $with{unicode} = 0 if $given{ascii}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 69 | ▶ | if (defined $given{seed}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 49 | ▶ | if ($given{seed} !~ /\A(?:[0-9a-fA-F]{2})+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 2 | print STDERR "senet: a seed is hexadecimal, two characters a byte.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 47 | $with{seed} = pack 'H*', $given{seed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 67 | ▶ | my $from = defined $given{resume} ? $given{resume} : $given{replay}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 67 | ▶ | return $class->_play(undef, %with) unless defined $from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 13 | ▶ | my ($save, $why) = $class->read_save($from, steps => defined $given{replay} ? 'ply' : 'one'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 13 | ▶ | unless ($save) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 5 | print STDERR "senet: $why.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 5 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | # What the game was played with, unless the command line says otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 8 | my $settings = $save->settings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 8 | for my $key (qw(mode side level first)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 32 | ▶ | $with{$key} = $settings->{$key} if !exists $with{$key} && defined $settings->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $with{$key} and defined $settings->{$key}
MC/DC100%2/2
not exists $with{$key} and defined $settings->{$key}
not exists $with{$key}
defined $settings->{$key}
Truth table100%3/3
not(A) and B
A= not exists $with{$key}B= defined $settings->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 8 | ▶ | return defined $given{replay} ? $class->_replay($save, %with) : $class->_play($save, %with); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 60 | ▶ | sub _play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_play: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 60 | my ($class, $save, %with) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 60 | ▶ | if ($save) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 6 | my $history = $class->_new_history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 6 | my $game = eval { $history->resume($save) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 6 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 0 | print STDERR "senet: '" . $save->file . "' cannot be carried on: " . _plain($@) . ".\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 6 | $with{game} = $game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 6 | $with{history} = $history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 6 | $with{rules} = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 6 | ▶ | $with{seed} = $game->seed if defined $game->seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 60 | my $terminal = eval { $class->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 60 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 8 | print STDERR "senet: " . _plain($@) . ".\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 8 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 52 | return $terminal->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 2 | ▶ | sub _replay { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replay: called CC=7 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 2 | my ($class, $save, %with) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 2 | my $first = eval { Game::Senet->from_text(($save->steps)[0]) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 2 | ▶ | my $terminal = $first && eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$first && eval {
do {
$class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ())
}
}
MC/DC0%0/2
$first && eval {
do {
$class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ())
}
}
$first
eval {
do {
$class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ())
}
}
Truth table33%1/3
A && B
A= $firstB= eval {
do {
$class->new(%with, 'game', $first, 'rules', $first->variant, defined $first->seed ? ('seed', $first->seed) : ())
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 2 | ▶ | $class->new(%with, game => $first, rules => $first->variant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | (defined $first->seed ? (seed => $first->seed) : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 2 | ▶ | unless ($terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | print STDERR "senet: '" . $save->file . "' cannot be watched: " . _plain($@) . ".\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | my $replay = Game::Terminal::Kit::Replay->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | save => $save, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 7 | ▶ | load => sub { Game::Senet->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 7 | ▶ | draw => sub { $terminal->replay_lines($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 2 | ▶ | head => [ $terminal->screen('plain')->[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | ' ' . $terminal->_paint('A replay of ' . $save->file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | . (defined $save->saved_at ? ', saved ' . $save->saved_at : ''), 'quiet'), '' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | screen => $terminal->_screen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | ($terminal->pace > 0 ? (pace => $terminal->pace) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 2 | my ($event, $step) = $replay->play($terminal->_keyboard, $terminal->_screen); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 2 | ▶ | return 0 unless $event eq 'chosen'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 0 | return $class->_play($save->from_step($step), %with); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 75 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||