| 1 | package Game::Senet::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 54 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 54 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 54 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 54 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 54 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 54 | ▶ | use Game::Terminal::Kit::Frame; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 54 | ▶ | use Game::Terminal::Kit::History; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 54 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 54 | ▶ | use Game::Terminal::Kit::Run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 54 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 54 | ▶ | use Game::Terminal::Kit::Steer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 54 | ▶ | use Game::Senet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 54 | ▶ | use Game::Senet::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 54 | ▶ | use Game::Senet::Variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 54 | ▶ | use Game::Senet::Notation (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 54 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 54 | my (%STYLE, %GLYPH, %SIGN, %OTHER, %ROW_OF, %COL_OF); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 54 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 54 | %STYLE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | title => '1;38;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | grid => '38;5;241', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | label => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sign => '1;38;5;205', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | light => '1;38;5;229', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | dark => '1;38;5;39', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | cursor => '1;38;5;16;48;5;220', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | target => '1;38;5;16;48;5;114', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | from => '1;38;5;231;48;5;160', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | recent => '38;5;250', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | face => '1;38;5;229', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | back => '38;5;240', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | key => '1;38;5;214', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | good => '1;38;5;114', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | bad => '1;38;5;203', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | quiet => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 54 | %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | light => "\x{25CF}", dark => "\x{25CB}", face => "\x{25AF}", back => "\x{25AE}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | h => "\x{2500}", v => "\x{2502}", tl => "\x{250C}", tr => "\x{2510}", bl => "\x{2514}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | br => "\x{2518}", td => "\x{252C}", tu => "\x{2534}", lt => "\x{251C}", rt => "\x{2524}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | x => "\x{253C}", ankh => "\x{2625}", turn_a => "\x{2500}\x{2510}", turn_b => "\x{2502}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | turn_c => "\x{2500}\x{2518}", turn_d => "\x{250C}\x{2500}", turn_e => "\x{2502}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | turn_f => "\x{2514}\x{2500}", into => "\x{25B6}", from => "\x{25C0}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | light => 'O', dark => '@', face => '|', back => '#', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | h => '-', v => '|', tl => '+', tr => '+', bl => '+', br => '+', td => '+', tu => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | lt => '+', rt => '+', x => '+', ankh => '+', turn_a => '-.', turn_b => '|', turn_c => "-'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | turn_d => '.-', turn_e => '|', turn_f => "'-", into => '>', from => '<', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 54 | %SIGN = (26 => 'X', 27 => '~', 28 => 'III', 29 => 'II', 30 => 'I'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 54 | %OTHER = (light => 'dark', dark => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 54 | for my $h (1 .. 30) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1620 | my $row = int(($h - 1) / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1620 | $ROW_OF{$h} = $row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1620 | ▶ | $COL_OF{$h} = $row == 1 ? 20 - $h : ($h - 1) % 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 54 | has game => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 54 | has [qw/in out/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 54 | has [qw/interactive colour unicode picking/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 54 | has mode => (is => 'rw', default => 'bot'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 54 | has side => (is => 'rw', default => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 54 | has level => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 54 | has rules => (is => 'rw', default => 'kendall'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 54 | has pieces => (is => 'rw', default => 5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 54 | has first => (is => 'rw', default => 'light'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 54 | has seed => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 54 | has pace => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 54 | has record => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 54 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 54 | has history => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 54 | has sleeper => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 54 | has [qw/_keyboard _screen/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 54 | has _events => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 54 | has _told => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 54 | has _cursor => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 54 | has _note => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 900 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=30 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 900 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 900 | ▶ | $self->in(\*STDIN) unless $self->in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 900 | ▶ | $self->out(\*STDOUT) unless $self->out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 900 | ▶ | $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 900 | ▶ | $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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 900 | ▶ | $self->unicode($self->interactive ? 1 : 0) unless defined $self->unicode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 900 | ▶ | $self->_keyboard(Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | in => $self->in, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ($self->keysource ? (keysource => $self->keysource) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 900 | ▶ | $self->_screen(Game::Terminal::Kit::Screen->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | out => $self->out, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | interactive => $self->interactive, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | colour => $self->colour, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ascii => $self->unicode ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 900 | ▶ | $self->picking($self->interactive ? 1 : 0) unless defined $self->picking; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 900 | ▶ | $self->picking(0) unless $self->_keyboard->keys_available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 900 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 900 | ▶ | Carp::croak("Game::Senet::Terminal: mode is bot, hotseat or watch, not '" . $self->mode . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | unless $self->mode =~ /\A(?:bot|hotseat|watch)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 899 | ▶ | Carp::croak("Game::Senet::Terminal: side is light or dark, not '" . $self->side . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | unless $self->side =~ /\A(?:light|dark)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 898 | ▶ | Carp::croak("Game::Senet::Terminal: first is light or dark, not '" . $self->first . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | unless $self->first =~ /\A(?:light|dark)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 897 | ▶ | Carp::croak('Game::Senet::Terminal: pieces is 5 or 7') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | unless $self->pieces =~ /\A[57]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 896 | ▶ | Carp::croak('Game::Senet::Terminal: pace is a number of seconds, 0 or more') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | unless $self->pace =~ /\A\d+(?:\.\d+)?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 894 | ▶ | my $variant = $self->game ? $self->game->variant : $self->_variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 893 | my @levels = Game::Senet::Bot->levels($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 893 | ▶ | $self->level($levels[-1]) unless defined $self->level; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 893 | ▶ | Carp::croak('Game::Senet::Terminal: level is a whole number from 1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | unless $self->level =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 892 | ▶ | $self->level($levels[-1]) if $self->level > $levels[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 892 | ▶ | $self->seed($self->_system_seed) unless defined $self->seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 892 | $self->_events([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 892 | $self->_told(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 892 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 892 | ▶ | if ($self->game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 848 | $self->_told(scalar @{ $self->game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 44 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $self->history(Game::Terminal::Kit::History->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1071 | ▶ | save => sub { $_[0]->to_text }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | load => sub { Game::Senet->from_text($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 892 | ▶ | )) unless $self->history; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 892 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 892 | $self->_screen->utf8->flush_on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 892 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 816 | ▶ | sub _system_seed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_system_seed: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 816 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 816 | ▶ | if (open my $fh, '<:raw', '/dev/urandom') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 816 | read $fh, $bytes, 16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 816 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 816 | ▶ | return length $bytes == 16 ? $bytes : Digest::SHA::sha256(join '|', 'senet', $$, time, rand); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 91 | ▶ | sub _variant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_variant: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 91 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 91 | my $rules = $self->rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 91 | ▶ | return $rules if ref $rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 91 | return Game::Senet::Variant->named($rules, pieces => $self->pieces); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 45 | ▶ | sub _fresh_game { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fresh_game: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 45 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 45 | return Game::Senet->new(seed => $self->seed, rules => $self->_variant, first => $self->first); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 304046 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 304046 | my ($self, $text, $style) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 304046 | ▶ | return $text unless defined $style; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 304046 | return $self->_screen->paint($text, $STYLE{$style}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2410 | ▶ | sub _raw { $_[0]->_keyboard->raw } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_raw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 133174 | ▶ | sub _glyph { $GLYPH{ $_[0]->unicode ? 'wide' : 'ascii' }{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glyph: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1250 | ▶ | sub _event { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1250 | my ($self, $side, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1250 | push @{ $self->_events }, { side => $side, text => $text }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1250 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | sub events { [ map { $_->{text} } @{ $_[0]->_events } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2411 | ▶ | sub _person { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_person: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2411 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2411 | ▶ | return 0 if $self->mode eq 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 591 | ▶ | return 1 if $self->mode eq 'hotseat'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 554 | ▶ | return $side eq $self->side ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4106 | ▶ | sub _who { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_who: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4106 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 4106 | ▶ | return ucfirst $side if $self->mode ne 'bot'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 689 | ▶ | return $side eq $self->side ? 'You' : ucfirst $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2876 | ▶ | sub sticks_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sticks_text: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2876 | my ($self, $sticks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2876 | ▶ | return '[ ' . join(' ', map { $self->_paint($self->_glyph($_ ? 'face' : 'back'), $_ ? 'face' : 'back') } @$sticks) . ' ]'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2872 | ▶ | sub roll_words { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
roll_words: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2872 | my ($self, $roll, $again, $bound) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2872 | ▶ | my $words = $roll == 5 ? 'no light face: a roll of 5' : "a roll of $roll"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 2872 | ▶ | $words .= ', and throws again' if $again; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2872 | ▶ | $words .= ', for the piece on 26' if $bound; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 2872 | return $words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1151 | ▶ | sub _what_it_does { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_what_it_does: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1151 | my ($self, $entry, $rules) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1151 | my @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1151 | ▶ | push @does, 'a backward move: nothing can go forward' if $entry->{back}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1151 | ▶ | push @does, 'swaps with ' . $OTHER{ $entry->{side} } if $entry->{swap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1151 | ▶ | if ($entry->{walk}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 15 | my ($from, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 15 | ▶ | push @does, ($from == 26 ? 'into the House of Water' : 'out of the water') . ": back to $to"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1151 | ▶ | push @does, 'bears off' if $entry->{off}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1151 | my (undef, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1151 | ▶ | push @does, 'onto the House of Happiness' if $to eq '26'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1151 | return @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1188 | ▶ | sub _briefly { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_briefly: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1188 | my ($self, $entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1188 | my ($from, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1188 | my @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1188 | ▶ | push @does, 'back' if $entry->{back}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1188 | ▶ | push @does, 'swaps' if $entry->{swap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1188 | ▶ | push @does, ($from == 26 ? 'into the water' : 'out of the water') . ", to $to" if $entry->{walk}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1188 | ▶ | push @does, 'bears off' if $entry->{off}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1188 | ▶ | push @does, 'onto the House of Happiness' if $to eq '26'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1188 | return @does; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1234 | ▶ | sub _tell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tell: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1234 | my ($self, $pause) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1234 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1234 | my $log = $game->log; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1234 | my $told = $self->_told; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1234 | ▶ | while ($told < @$log) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1223 | my $entry = $log->[ $told++ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1223 | my $who = $self->_who($entry->{side}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1223 | my $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1223 | ▶ | if (!defined $entry->{move}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | $text = "$who threw " . (defined $entry->{sticks} ? $self->_plain_sticks($entry->{sticks}) . " (a $entry->{roll})" : "a $entry->{roll}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 35 | ▶ | . ' and could not move' . ($entry->{again} ? ': throws again.' : '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1188 | my @does = $self->_briefly($entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $text = "$who played " . Game::Senet::Notation::format_display({ %$entry, from => (split /-/, $entry->{move})[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | to => (split /-/, $entry->{move})[1] }, 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | . (@does ? ', ' . join(', ', @does) : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1188 | ▶ | . ($entry->{again} ? '; throws again.' : '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1223 | $self->_event($entry->{side}, $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1223 | $self->_told($told); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1223 | ▶ | 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'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1223 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 140 | $self->show('wait'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 140 | $self->_wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1234 | my $turn = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1234 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 17 | my $last = $self->_events->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | $self->_event($turn->{side}, $self->_who($turn->{side}) . ' throws again for the piece on 26.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1234 | $self->_told($told); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1234 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 34 | ▶ | sub _plain_sticks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain_sticks: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 34 | my ($self, $sticks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 34 | ▶ | return defined $sticks ? join('', map { $_ ? $self->_glyph('face') : $self->_glyph('back') } split //, $sticks) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 273 | ▶ | sub _wait { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 273 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 273 | my $pace = $self->pace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 273 | ▶ | return unless $pace > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 273 | ▶ | return $self->sleeper->($pace) if $self->sleeper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | select undef, undef, undef, $pace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 56824 | ▶ | sub candidates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
candidates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 56824 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 56824 | return $self->game->legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 169983 | ▶ | sub place_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 169983 | my ($class, $house) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 169983 | return ($COL_OF{$house}, $ROW_OF{$house}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 55243 | ▶ | sub steer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
steer: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 55243 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 55243 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 55243 | ▶ | return $self->_cursor unless @moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 55243 | my $at = $self->_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 55243 | ▶ | $at = $#moves if $at > $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 55243 | ▶ | if ($key eq 'tab') { $at = Game::Terminal::Kit::Steer::ring(scalar @moves, $at, 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 55243 | ▶ | if (my ($dx, $dy) = Game::Terminal::Kit::Steer::way($key)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 51983 | my @points = map { [ $self->place_of($_->from) ] } @moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 51983 | $at = Game::Terminal::Kit::Steer::axis(\@points, $at, $dx, $dy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 55243 | $self->_cursor($at); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 55243 | return $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2918 | ▶ | sub _cells_after { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cells_after: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2918 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2918 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2918 | my (%cell, %home, %mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 2918 | $cell{$_} = $game->at($_) for 1 .. 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 2918 | $home{$_} = $game->home($_) for qw(light dark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 2918 | ▶ | return (\%cell, \%home, \%mark) unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1106 | my $side = $move->side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1106 | $cell{ $move->from } = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1106 | ▶ | if ($move->off) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 34 | $home{$side}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 34 | $mark{"home $side"} = 'target'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1072 | ▶ | if ($move->swap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 191 | $cell{ $move->from } = $OTHER{$side}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 191 | $mark{ $move->from } = 'from'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1072 | $cell{ $move->to } = $side; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1072 | $mark{ $move->to } = 'target'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1106 | ▶ | $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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1106 | return (\%cell, \%home, \%mark); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 87574 | ▶ | sub _marked { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_marked: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 87574 | my ($self, $text, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 87574 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 87574 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 85362 | return $open . $text . $close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 87540 | ▶ | sub _house_top { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_house_top: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 87540 | my ($self, $h) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 87540 | ▶ | 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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 87540 | my $number = sprintf '%-2s ', $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 87540 | my $pad = 3 - length $sign; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 87540 | return $self->_paint($number, 'label') . $self->_paint($sign, 'sign') . (' ' x $pad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 87540 | ▶ | sub _house_piece { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_house_piece: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 87540 | my ($self, $who, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 87540 | ▶ | 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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 87540 | ▶ | my $inside = !defined $who ? ' ' : $painted ? $self->_glyph($who) : $self->_paint($self->_glyph($who), $who); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 87540 | return ' ' . $self->_marked($inside, $mark) . ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 11672 | ▶ | sub _border { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_border: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 11672 | my ($self, $left, $mid, $right) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 11672 | ▶ | my $g = sub { $self->_glyph($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 11672 | return $self->_paint($g->($left) . join($g->($mid), ($g->('h') x 6) x 10) . $g->($right), 'grid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 8754 | ▶ | sub _row_houses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_row_houses: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 8754 | my ($row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 8754 | ▶ | return $row == 0 ? (1 .. 10) : $row == 1 ? (reverse 11 .. 20) : (21 .. 30); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 5836 | ▶ | sub _home_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_home_line: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 5836 | my ($self, $side, $home, $mark) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 5836 | my @shown = map { $self->_paint($self->_glyph($side), $side) } 1 .. $home->{$side}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | $shown[-1] = $self->_marked($self->_glyph($side), 'target') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 5836 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 5836 | ▶ | return sprintf ' %s home: %s', $self->_paint(sprintf('%-5s', $side), $side), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | @shown ? join(' ', @shown) : $self->_paint('none', 'quiet'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 2918 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2918 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2918 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 2918 | my ($cell, $home, $mark) = $self->_cells_after($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 2918 | my %recent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 2918 | for my $entry (@{ $game->log }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 293934 | ▶ | next unless defined $entry->{move}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 290727 | my (undef, $to) = split /-/, $entry->{move}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 290727 | $recent{ $entry->{side} } = $to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2918 | for my $side (keys %recent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 5617 | my $to = $recent{$side}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 5617 | ▶ | next if $to eq 'off'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 5302 | ▶ | $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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 2918 | my $v = $self->_paint($self->_glyph('v'), 'grid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 8754 | ▶ | my $row_lines = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 8754 | my ($row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 8754 | my @houses = _row_houses($row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 8754 | my $top = $v . join($v, map { $self->_house_top($_) } @houses) . $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 8754 | my $low = $v . join($v, map { $self->_house_piece($cell->{$_}, $mark->{$_}) } @houses) . $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 8754 | return ($top, $low); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 2918 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 2918 | my ($r0a, $r0b) = $row_lines->(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2918 | my ($r1a, $r1b) = $row_lines->(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2918 | my ($r2a, $r2b) = $row_lines->(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 2918 | ▶ | my $g = sub { $self->_paint($self->_glyph($_[0]), 'grid') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 2918 | my $sp = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 2918 | $self->_home_line('dark', $home, $mark), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | $sp . $self->_border('tl', 'td', 'tr'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | $sp . $r0a, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | $sp . $r0b . $g->('into') . $g->('turn_a'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | $sp . $self->_border('lt', 'x', 'rt') . ' ' . $g->('turn_b'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ' ' . $g->('turn_d') . $g->('from') . $r1a . $g->('from') . $g->('turn_c'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | ' ' . $g->('turn_e') . ' ' . $r1b, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ' ' . $g->('turn_e') . ' ' . $self->_border('lt', 'x', 'rt'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | ' ' . $g->('turn_f') . $g->('into') . $r2a . $g->('into') . $self->_paint('off', 'grid'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | $sp . $r2b, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | $sp . $self->_border('bl', 'tu', 'br'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | $self->_home_line('light', $home, $mark), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 2884 | ▶ | sub _shield_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shield_lines: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 2884 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2884 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 2884 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 2884 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 2884 | for my $side (qw(light dark)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 5768 | my (@runs, $run); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 5768 | for my $h (1 .. 30) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 173040 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 148329 | ▶ | push @runs, $run if $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 148329 | undef $run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 5768 | ▶ | push @runs, $run if $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 5768 | my (@kept, @blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 5768 | for my $r (grep { @$_ >= 2 } @runs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 4606 | ▶ | push @kept, $variant->protect eq 'run' ? @$r : $variant->protect eq 'ends' ? ($r->[0], $r->[-1]) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 4606 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 5768 | ▶ | my @said = ((@kept ? 'protected ' . join(' ', @kept) : 'nothing protected'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | (@blocks ? 'blockades ' . join(' ', @blocks) : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 5768 | push @lines, ' ' . $self->_paint(sprintf('%-5s ', $side) . join('; ', @said), 'quiet'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 2884 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 2884 | ▶ | sub _sticks_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sticks_line: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 2884 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 2884 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 2884 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2866 | my $turn = $game->turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | return (sprintf(' %s threw %d %s %s', $self->_who($game->side), $game->throw, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | $self->sticks_text($game->sticks), $self->roll_words($game->roll, $turn->{extra})), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 2866 | ▶ | ($turn->{bound} ? ' ' . $self->_paint('This throw is for the piece on 26: it alone may move.', 'key') : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 2884 | ▶ | sub _result_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_line: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 2884 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 2884 | ▶ | my $result = $self->game->result or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 16 | ▶ | return ' ' . $self->_paint('The game ran its full length with no end. It is drawn.', 'bad') if $result->is_draw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 16 | my $winner = $result->winner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 16 | ▶ | return ' ' . $self->_paint(sprintf('%s won: %s resigned.', ucfirst $winner, $result->loser), 'good') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | if $result->how eq 'resign'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 16 | my $home = $result->home; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | return ' ' . $self->_paint(sprintf('%s won, all %d home to %d, in %d plies.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 16 | ucfirst $winner, $home->{$winner}, $home->{ $result->loser }, $result->plies), 'good'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2884 | ▶ | sub _event_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event_lines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2884 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2884 | my @recent = @{ $self->_events }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 2884 | ▶ | @recent = @recent[ -4 .. -1 ] if @recent > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2884 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1151 | ▶ | sub readout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readout: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1151 | my ($self, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1151 | my %entry = (side => $move->side, move => Game::Senet::Notation::format_move($move), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | back => $move->back, swap => $move->swap, walk => $move->walk, off => $move->off); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1151 | my @does = $self->_what_it_does(\%entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1151 | ▶ | return $self->_paint(Game::Senet::Notation::format_display($move, 0), 'key') . (@does ? ' ' . join(', ', @does) : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 2031 | ▶ | sub _legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legend: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 2031 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2031 | ▶ | my $k = sub { $self->_paint($_[0], 'key') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2031 | ▶ | return ' ' . join(' ', $k->('enter') . ' leave', $k->('n') . ' new game', $k->('u') . ' take back', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ($self->history->can_redo ? $k->('r') . ' play again' : ())) if $mode eq 'ended'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 2026 | ▶ | return ' ' . $self->_paint('...', 'quiet') if $mode eq 'wait'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 1088 | return ' ' . join(' ', $k->('arrows') . ' choose', $k->('enter') . ' move', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | $k->('u') . ' back', $k->('r') . ' again', $k->('?') . ' help', $k->('q') . ' leave'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2884 | ▶ | sub screen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
screen: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2884 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2884 | ▶ | $mode = 'plain' unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 2884 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 2884 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 2884 | ▶ | my @lines = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | ' ' . $self->_paint('Senet', 'title') . ' ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | . $self->_paint(join(', ', $variant->describe, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | ($self->mode eq 'bot' ? 'you are ' . $self->side . ', against level ' . $self->level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | : $self->mode eq 'hotseat' ? 'two players' : 'level ' . $self->level . ' against itself')), 'quiet'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 2884 | ▶ | if ($mode eq 'help') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | push @lines, map { " $_" } @{ $self->help_lines }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2884 | ▶ | my @moves = $mode eq 'pick' ? $self->candidates : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 2884 | my $at = $self->_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2884 | ▶ | $at = $#moves if $at > $#moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2884 | ▶ | my $move = @moves ? $moves[$at] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 2884 | push @lines, @{ $self->board_lines($move) }, $self->_shield_lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 2884 | push @lines, $self->_sticks_line, $self->_result_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 2884 | ▶ | push @lines, ' ' . $self->readout($move) if $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 2884 | push @lines, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 2884 | push @lines, $self->_event_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 2884 | ▶ | push @lines, ' ' . $self->_paint($self->_note, 'bad') if defined $self->_note; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 2884 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 2884 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 433 | ▶ | sub show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 433 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 433 | $self->_screen->show($self->screen($mode)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 433 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | sub help_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | 'A move is a piece. The sticks say how far it goes, so choosing the piece is', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 'the whole move. A roll of 1, 4 or 5 throws again.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | ' arrows, tab walk the pieces that can move', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | ' 1 to 7 go straight to one of them', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | ' enter, space move it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | ' u take back your last turn and every reply to it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | ' r play a turn taken back again', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | ' n a new game', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | ' q leave (asked twice)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | ' enter, q leave, once the game is over', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 'The board shows what the move would leave: [ ] the house the piece leaves,', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | '< > where it lands, ( ) the house a swapped piece goes back to, and { } the', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 'last move each side made.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 'Typing instead: a number from the list, or a move such as 12-15 or 26-off;', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 'and undo, redo, new, moves, record FILE, level N, help, quit.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 6 | ▶ | sub _enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_raw: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 6 | ▶ | return 1 if $self->_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 6 | ▶ | return 0 unless $self->_keyboard->enter_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 6 | ▶ | $self->_screen->hide_cursor->clear unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 145 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=15 SCAR=28.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 145 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 145 | my $leaving = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 145 | ▶ | $self->_cursor(0) if $self->_cursor > $self->candidates - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 145 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 155 | $self->show('pick'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 155 | my $key = $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 155 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 153 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 153 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 5 | ▶ | return 'quit' if $leaving; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 3 | $leaving = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 3 | $self->_note('Press q again to leave the game, or any other key to stay.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 148 | $leaving = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 148 | ▶ | 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 " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 140 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 140 | ▶ | next unless @moves; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 140 | return Game::Senet::Notation::format_move($moves[ $self->_cursor ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 8 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 7 | ▶ | return 'redo' if $key eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 7 | ▶ | return 'new' if $key eq 'n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 7 | ▶ | if ($key eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $self->show('help'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 7 | $self->steer($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 5 | ▶ | sub _ended_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ended_key: called CC=11 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 5 | $self->show('ended'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 5 | my $key = $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 5 | ▶ | return 'new' if $key eq 'n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 4 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 4 | ▶ | return 'redo' if $key eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 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 " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 87 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 87 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 87 | ▶ | $self->_screen->say(@lines) if @lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 87 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 38 | ▶ | sub _read_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_line: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 38 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 38 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 38 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 38 | $self->_say(@{ $self->screen('plain') }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 38 | ▶ | if (!$game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 38 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 38 | $self->_say(map { sprintf ' %s %s', $self->_paint($_ + 1, 'key'), $self->readout($moves[$_]) } 0 .. $#moves); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 38 | ▶ | my $line = $self->_keyboard->read_line( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | $game->is_over ? 'new, undo, or enter to leave> ' : $game->side . ' (' . $game->roll . ')> ', $out); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 38 | ▶ | print {$out} "\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 38 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 183 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=30 SCAR=48.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 183 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 183 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 183 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 183 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 183 | my ($word, $rest) = split ' ', $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 183 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 183 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 145 | ▶ | 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 "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $self->_say(map { " $_" } @{ $self->help_lines }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 145 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 1 | $self->seed(Digest::SHA::sha256($self->seed . 'next')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 1 | $self->_events([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 1 | $self->_told(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 144 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | $self->take_back; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 143 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | $self->play_again; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 143 | ▶ | if ($word eq 'moves') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | $self->_say(map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | ' ' . (defined $_->{move} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | ? Game::Senet::Notation::format_display({ %$_, from => (split /-/, $_->{move})[0], to => (split /-/, $_->{move})[1] }, $_->{again}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 2 | ▶ | : Game::Senet::Notation::format_forfeit($_->{roll}, $_->{again})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 1 | } @{ $game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 142 | ▶ | if ($word eq 'record') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | if (!defined $rest || !length $rest) { $self->_note('record wants the name of a file.') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $rest && length $rest
MC/DC0%0/2
defined $rest && length $rest
defined $rest
length $rest
Truth table0%0/3
A && B
A= defined $restB= length $rest
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | elsif ($self->save($rest)) { $self->_event(undef, "The game is written to $rest.") } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | else { $self->_note("I could not write '$rest'.") } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 142 | ▶ | if ($word eq 'level') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | my @levels = Game::Senet::Bot->levels($game->variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | $self->level($rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | $self->_event(undef, "The program now plays at level $rest."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | else { $self->_note('A level is a number from 1 to ' . $levels[-1] . '.') } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 142 | ▶ | if ($game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $self->_note('The game is over. Type new, undo or quit.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 142 | my $move = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 142 | ▶ | if ($line =~ /\A[1-7]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 4 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 4 | ▶ | if ($line > @moves) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | $self->_note('There are only ' . scalar(@moves) . ' moves to choose from.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 4 | $move = $moves[ $line - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 142 | ▶ | if ($game->play($move)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 142 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 142 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | my $error = $game->error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | $self->_note($error->code eq 'bad_move' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | ? "I do not know '$line'. A move is two houses, like 12-15 or 26-off, or its number in the list." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | : ucfirst($error->message) . '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 142 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 1 | ▶ | sub take_back { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
take_back: called CC=2 SCAR=7.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 1 | $self->_keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 1 | my $game = $self->history->undo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 1 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | $self->_note('There is nothing to take back.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 1 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | $self->_event(undef, 'Taken back.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | sub play_again { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_again: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | $self->_keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | my $game = $self->history->redo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | $self->_note('There is nothing to play again.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $self->_event(undef, 'Played again.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 1 | ▶ | sub _keep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keep: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 1 | ▶ | $self->history->record($self->game) if $self->mode ne 'watch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 1 | ▶ | sub swap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
swap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 1 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 1 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 1 | $self->_told(scalar @{ $game->log }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 1 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 1 | $self->_note(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 177 | ▶ | sub person_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
person_turn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 177 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 177 | $self->history->turn($self->game); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 177 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 1 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 1 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | ▶ | open my $fh, '>', $file or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 1 | print {$fh} $self->game->to_record; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 1 | ▶ | return close $fh ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 1046 | ▶ | sub _bot_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_move: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 1046 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 1046 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 1046 | my $bot = Game::Senet::Bot->new(level => $self->level); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 1046 | ▶ | my $move = $bot->choose($game) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 1046 | ▶ | if ($self->_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 133 | my @moves = $self->candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 133 | my ($at) = grep { $moves[$_] == $move } 0 .. $#moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 133 | ▶ | $self->_cursor($at // 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$at // 0
MC/DC0%0/1
$at // 0
$at
Truth table50%1/2
A
A= $at
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 133 | $self->show('pick'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 133 | $self->_wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 1046 | $game->play_or_die($move); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 1046 | $self->_cursor(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1046 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 1046 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 45 | ▶ | sub _turns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_turns: called CC=14 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 45 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 45 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 45 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 1234 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 1234 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 1234 | ▶ | if ($game->is_over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 5 | ▶ | my $line = $picking ? $self->_ended_key : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 5 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 5 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 1 | $self->_tell(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 1223 | ▶ | if (!$self->_person($game->side)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 1046 | $self->_bot_move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 1046 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 177 | $self->person_turn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 177 | ▶ | my $line = $picking ? $self->pick : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 177 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 176 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 45 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 45 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 45 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 45 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 45 | ▶ | Game::Terminal::Kit::Run::guard(sub { $self->_turns }, $self->_keyboard, $self->_screen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 45 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 45 | ▶ | $self->save($self->record) if defined $self->record; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 45 | my $result = $self->game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 45 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 44 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 5 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 5 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | senet - Senet, the race game of ancient Egypt, in a terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | senet [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | --mode HOW bot (the default): you against the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | hotseat: two people at one keyboard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | watch: the program against itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | --rules NAME kendall (the default) or skyruk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | --pieces N 5 (the default) or 7 a side | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | --level N how well the program plays, 1 upward; the top by default, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | and above the top plays the top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | --side WHICH light (the default) or dark: your side against the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | --first WHO light (the default) or dark: who throws first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | --seed HEX hexadecimal; the same seed throws the same sticks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | --pace SECONDS how long a lost turn and the program's move stay up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | --record FILE write the game to FILE when you leave | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | --replay FILE carry on from a game written by --record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | --ascii plain letters and lines, for a terminal with no Unicode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | --unicode line and shape characters, where they are not the default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | --no-colour no colour; nothing is lost without it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | --no-pick type moves instead of choosing them with the arrow keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | --version the version, and stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | --help this, and stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | In a terminal, the pieces that can move are walked with the arrow keys and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | board shows what each move would leave; press ? for the keys. Anywhere else, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | type a number from the list, a move such as 12-15 or 26-off, or help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 1 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 1 | my $top = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 1 | for my $name (Game::Senet::Variant->names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 2 | my @levels = Game::Senet::Bot->levels($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 2 | ▶ | $top = $levels[-1] if $levels[-1] > $top; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 1 | { name => 'mode', type => 'enum', choices => [qw(bot hotseat watch)], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | help => 'you against the program, two people, or the program against itself' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | { name => 'rules', type => 'enum', choices => [ Game::Senet::Variant->names ], help => 'the rules' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | { name => 'pieces', type => 'enum', choices => [qw(5 7)], help => 'pieces a side' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | { name => 'level', type => 'int', min => 1, max => $top, help => 'how well the program plays; the top by default' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | { name => 'side', type => 'enum', choices => [qw(light dark)], help => 'your side against the program' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | { name => 'first', type => 'enum', choices => [qw(light dark)], help => 'who throws first' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | { name => 'seed', type => 'str', help => 'hexadecimal; the same seed throws the same sticks' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 59 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=21 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 59 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 59 | my $saved = Getopt::Long::Configure(qw(default no_ignore_case no_auto_abbrev)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 59 | my %given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 59 | my $parsed = Getopt::Long::GetOptionsFromArray( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | \@argv, \%given, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 'mode=s', 'rules=s', 'pieces=i', 'level=i', 'side=s', 'first=s', 'seed=s', 'pace=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 'record=s', 'replay=s', 'ascii', 'unicode!', 'colour|color!', 'pick!', 'version', 'help', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 59 | Getopt::Long::Configure($saved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 59 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 3 | print STDERR _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 3 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 56 | ▶ | if ($given{help}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 2 | print _usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 54 | ▶ | if ($given{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 3 | print "senet $Game::Senet::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 51 | my %with; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 51 | $with{$_} = $given{$_} for grep { defined $given{$_} } qw(mode rules pieces level side first pace record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 51 | ▶ | $with{colour} = $given{colour} if defined $given{colour}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 51 | ▶ | $with{picking} = $given{pick} if defined $given{pick}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 51 | ▶ | $with{unicode} = $given{unicode} if defined $given{unicode}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 51 | ▶ | $with{unicode} = 0 if $given{ascii}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 51 | ▶ | if (defined $given{seed}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 41 | ▶ | if ($given{seed} !~ /\A(?:[0-9a-fA-F]{2})+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 2 | print STDERR "senet: a seed is hexadecimal, two characters a byte.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 39 | $with{seed} = pack 'H*', $given{seed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 49 | ▶ | if (defined $given{replay}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 3 | ▶ | open my $fh, '<', $given{replay} or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 1 | print STDERR "senet: I could not read '$given{replay}'.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 1 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 2 | my $text = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 2 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 2 | my ($game, $error) = Game::Senet->replay($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 2 | ▶ | if (!$game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 1 | my $detail = $error->detail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | print STDERR "senet: '$given{replay}' is not a game I can replay: ", $error->message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 1 | ▶ | (defined $detail->{line} ? " (line $detail->{line})" : defined $detail->{ply} ? ' (ply ' . ($detail->{ply} + 1) . ')' : ''), ".\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 1 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 1 | $with{game} = $game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 1 | $with{rules} = $game->variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 1 | ▶ | $with{seed} = $game->seed if defined $game->seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 47 | my $terminal = eval { $class->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 47 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 8 | (my $why = $@) =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 8 | $why =~ s/\AGame::Senet(?:::\w+)*: //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 8 | print STDERR "senet: $why.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 8 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 39 | return $terminal->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 54 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||