| 1 | package Game::Fanorona::Terminal; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 19 | ▶ | use Game::Terminal::Kit::History; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 19 | ▶ | use Game::Terminal::Kit::Line; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 19 | ▶ | use Game::Terminal::Kit::Log; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 19 | ▶ | use Game::Terminal::Kit::Run; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 19 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 19 | ▶ | use Game::Terminal::Kit::Steer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 19 | ▶ | use Game::Fanorona; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 19 | ▶ | use Game::Fanorona::Bot; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 19 | ▶ | use Game::Fanorona::Variant; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 19 | ▶ | use Game::Fanorona::Notation qw(parse_position move_points); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 19 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 19 | our (@COMMANDS, @KEYS, %DIRECTION, %GROUND, %INK, %GLYPH, %FRAME, %ENDING, @RULES, @LEVEL); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 19 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 19 | @COMMANDS = ( | |||||||||||||||||||||||||||||||||||||||||
| 29 | [ 'd2-e3A' => 'play a move: every point the stone stands on, A or W after a step that takes' ], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | [ 'moves' => 'the first step of every legal move, and what each would take' ], | ||||||||||||||||||||||||||||||||||||||||||
| 31 | [ 'hint' => 'what the program would play here' ], | ||||||||||||||||||||||||||||||||||||||||||
| 32 | [ 'board' => 'draw the board again' ], | ||||||||||||||||||||||||||||||||||||||||||
| 33 | [ 'level N' => 'how hard the program plays, 1 to 5' ], | ||||||||||||||||||||||||||||||||||||||||||
| 34 | [ 'side WHO' => 'white, black, both or neither: which side is yours' ], | ||||||||||||||||||||||||||||||||||||||||||
| 35 | [ 'new' => 'start another game; new telo or new dimy for a smaller board' ], | ||||||||||||||||||||||||||||||||||||||||||
| 36 | [ 'save FILE' => 'write the game to a file' ], | ||||||||||||||||||||||||||||||||||||||||||
| 37 | [ 'load FILE' => 'read a game back from a file' ], | ||||||||||||||||||||||||||||||||||||||||||
| 38 | [ 'undo' => 'take back your last move, and the reply to it' ], | ||||||||||||||||||||||||||||||||||||||||||
| 39 | [ 'redo' => 'play again what undo took back' ], | ||||||||||||||||||||||||||||||||||||||||||
| 40 | [ 'draw' => 'offer a draw; accept and decline answer one' ], | ||||||||||||||||||||||||||||||||||||||||||
| 41 | [ 'resign' => 'give the game up' ], | ||||||||||||||||||||||||||||||||||||||||||
| 42 | [ 'rules' => 'the rules of the game' ], | ||||||||||||||||||||||||||||||||||||||||||
| 43 | [ 'help' => 'this list' ], | ||||||||||||||||||||||||||||||||||||||||||
| 44 | [ 'quit' => 'stop playing' ], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | @KEYS = ( | |||||||||||||||||||||||||||||||||||||||||
| 48 | [ 'arrows' => 'walk the cursor over the stones that can move; then over the points' ], | ||||||||||||||||||||||||||||||||||||||||||
| 49 | [ '' => 'the stone picked up may step to, diagonals too: up, then right' ], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | [ 'enter' => 'pick the stone up; step to the point the cursor is on; and with' ], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | [ '' => 'the cursor on no point, play the move as it stands' ], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | [ 'y b n' => 'step at once: up-left, down-left, down-right' ], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | [ '7 9 1 3' => 'step at once on a numeric pad: the four diagonals, 9 for up-right' ], | ||||||||||||||||||||||||||||||||||||||||||
| 54 | [ '8 4 6 2' => 'and up, left, right, down' ], | ||||||||||||||||||||||||||||||||||||||||||
| 55 | [ 'space' => 'whatever enter would do' ], | ||||||||||||||||||||||||||||||||||||||||||
| 56 | [ 'tab' => 'the next stone that can move, in the order they are drawn' ], | ||||||||||||||||||||||||||||||||||||||||||
| 57 | [ 'a w' => 'when a step can take two ways: the row ahead, or the row behind' ], | ||||||||||||||||||||||||||||||||||||||||||
| 58 | [ 'backspace' => 'take the cursor off a point; then take back one step' ], | ||||||||||||||||||||||||||||||||||||||||||
| 59 | [ 'escape' => 'put the stone down where it started' ], | ||||||||||||||||||||||||||||||||||||||||||
| 60 | [ 'h' => 'show what the program would play' ], | ||||||||||||||||||||||||||||||||||||||||||
| 61 | [ 'u' => 'take back your last move, and the reply to it' ], | ||||||||||||||||||||||||||||||||||||||||||
| 62 | [ 'r' => 'play again what u took back' ], | ||||||||||||||||||||||||||||||||||||||||||
| 63 | [ 'R' => 'the rules' ], | ||||||||||||||||||||||||||||||||||||||||||
| 64 | [ ':' => 'type a command' ], | ||||||||||||||||||||||||||||||||||||||||||
| 65 | [ 'q' => 'stop playing' ], | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 19 | %DIRECTION = ( | |||||||||||||||||||||||||||||||||||||||||
| 69 | up => [ 0, 1 ], down => [ 0, -1 ], left => [ -1, 0 ], right => [ 1, 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 70 | y => [ -1, 1 ], b => [ -1, -1 ], n => [ 1, -1 ], | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 => [ 0, 1 ], 2 => [ 0, -1 ], 4 => [ -1, 0 ], 6 => [ 1, 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 => [ -1, 1 ], 9 => [ 1, 1 ], 1 => [ -1, -1 ], 3 => [ 1, -1 ], | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 19 | %GROUND = ( | |||||||||||||||||||||||||||||||||||||||||
| 76 | board => '48;5;137', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | cursor => '48;5;33', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | moving => '48;5;28', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | reach => '48;5;37', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | taken => '48;5;160', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | trail => '48;5;130', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | approach => '48;5;160', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | withdrawal => '48;5;91', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 19 | %INK = ( | |||||||||||||||||||||||||||||||||||||||||
| 87 | white => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 88 | black => '1;38;5;16', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | line => '38;5;94', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | cursor => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 91 | moving => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | reach => '1;38;5;16', | ||||||||||||||||||||||||||||||||||||||||||
| 93 | taken => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | trail => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | approach => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | withdrawal => '1;38;5;231', | ||||||||||||||||||||||||||||||||||||||||||
| 97 | title => '1;38;5;220', | ||||||||||||||||||||||||||||||||||||||||||
| 98 | good => '1;38;5;34', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | bad => '1;38;5;160', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | quiet => '38;5;245', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | key => '1;38;5;33', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | warn => '1;38;5;208', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 19 | %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||
| 106 | wide => { white => "\x{25CB}", black => "\x{25CF}", empty => '+', taken => "\x{2715}" }, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ascii => { white => 'O', black => 'X', empty => '+', taken => '*' }, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 19 | %FRAME = ( | |||||||||||||||||||||||||||||||||||||||||
| 111 | cursor => [ '[', ']' ], | ||||||||||||||||||||||||||||||||||||||||||
| 112 | moving => [ '<', '>' ], | ||||||||||||||||||||||||||||||||||||||||||
| 113 | reach => [ '(', ')' ], | ||||||||||||||||||||||||||||||||||||||||||
| 114 | taken => [ '{', '}' ], | ||||||||||||||||||||||||||||||||||||||||||
| 115 | trail => [ ':', ':' ], | ||||||||||||||||||||||||||||||||||||||||||
| 116 | approach => [ '{', '}' ], | ||||||||||||||||||||||||||||||||||||||||||
| 117 | withdrawal => [ '{', '}' ], | ||||||||||||||||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 19 | %ENDING = ( | |||||||||||||||||||||||||||||||||||||||||
| 121 | stones => '%2$s has no stone left. %1$s wins.', | ||||||||||||||||||||||||||||||||||||||||||
| 122 | no_moves => '%2$s has no move left, and so has lost. %1$s wins.', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | resign => '%2$s resigns. %1$s wins.', | ||||||||||||||||||||||||||||||||||||||||||
| 124 | repetition => 'The same position has come round once too often. The game is drawn.', | ||||||||||||||||||||||||||||||||||||||||||
| 125 | quiet => 'Nothing has been taken for %3$d moves. The game is drawn.', | ||||||||||||||||||||||||||||||||||||||||||
| 126 | ply_cap => 'The game has run its full length with no end. It is drawn.', | ||||||||||||||||||||||||||||||||||||||||||
| 127 | agreement => 'A draw, by agreement.', | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 19 | @LEVEL = ( | |||||||||||||||||||||||||||||||||||||||||
| 131 | 'takes the most it can and looks no further', | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 'looks a little way ahead', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 'looks ahead, and misses things', | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 'hard to beat', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 'the strongest here', | ||||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 19 | @RULES = ( | |||||||||||||||||||||||||||||||||||||||||
| 139 | 'Fanorona is the game of Madagascar. The points are joined by lines, and a', | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 'stone steps one point along a line. Every point has the lines up, down and', | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 'sideways; only the points where a diagonal is drawn have those as well.', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 'TAKING BY APPROACH. Step a stone up to an enemy stone, so that the enemy is', | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 'on the next point of the same line, and it is taken, with every enemy stone', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 'standing in an unbroken row behind it.', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 'TAKING BY WITHDRAWAL. Step a stone straight away from an enemy stone it stood', | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 'beside, along the line that joins them, and the same row is taken.', | ||||||||||||||||||||||||||||||||||||||||||
| 149 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 'A step that could take both ways takes one way only, and the mover says which.', | ||||||||||||||||||||||||||||||||||||||||||
| 151 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 'If any stone can take, the move must take. Which stone, and which way, is the', | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 'mover\'s choice. After taking, the same stone may take again, and again: each', | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 'further step must take, must not run in the direction of the step before it,', | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 'and must not come back to a point the stone has stood on in this move. The', | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 'mover may stop after any step that has taken.', | ||||||||||||||||||||||||||||||||||||||||||
| 157 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 'A step that takes nothing is allowed only when nothing can be taken.', | ||||||||||||||||||||||||||||||||||||||||||
| 159 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 'White moves first. A side with no stone left has lost, and so has a side that', | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 'cannot move. The game is drawn when the same position comes round for the', | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 'third time, when %d moves running take nothing, or when both sides agree.', | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 19 | has game => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 19 | has [qw/in out/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 19 | has [qw/interactive colour unicode picking/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 19 | has human => (is => 'rw', default => 'white'); | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 19 | has level => (is => 'rw', default => 3); | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 19 | has variant => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 19 | has width => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 19 | has pause => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 19 | has menu => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 19 | has [qw/_keyboard _screen _log _frame/] => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 19 | has focus => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 19 | has chosen => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 109 | ▶ | has prefix => (is => 'rw', default => sub { [] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 19 | has last => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 19 | has history => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 19 | has _ask => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 19 | has _target => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 19 | has _complaint => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 19 | has _choice => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 19 | has _cramped => (is => 'rw', default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 19 | has _redraw => (is => 'rw', default => 1); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 19 | my %WORD = (w => 'white', b => 'black'); | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1614 | ▶ | my $other = sub { $_[0] eq 'white' ? 'black' : 'white' }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 952 | ▶ | my $coordinates = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 952 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 952 | return (ord(substr $name, 0, 1) - 97, substr($name, 1) - 1); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1510 | ▶ | my $stones_of = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1510 | my ($position) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 1510 | ▶ | my $parsed = parse_position($position) or return {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1510 | my $stones = $parsed->{stones}; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 1510 | return { map { $_ => $WORD{ $stones->{$_} } } keys %{$stones} }; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 398 | ▶ | my $drawn = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 398 | my (@names) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 398 | my %place = map { $_ => [ $coordinates->($_) ] } @names; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 398 | ▶ | return sort { $place{$b}[1] <=> $place{$a}[1] || $place{$a}[0] <=> $place{$b}[0] } @names; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$place{$b}[1] <=> $place{$a}[1] || $place{$a}[0] <=> $place{$b}[0]
MC/DC0%0/2
$place{$b}[1] <=> $place{$a}[1] || $place{$a}[0] <=> $place{$b}[0]
$place{$b}[1] <=> $place{$a}[1]
$place{$a}[0] <=> $place{$b}[0]
Truth table66%2/3
A || B
A= $place{$b}[1] <=> $place{$a}[1]B= $place{$a}[0] <=> $place{$b}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 150 | ▶ | my $plain = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 150 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 150 | $text =~ s/\e\[[0-9;?]*[A-Za-z]//g; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 150 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 181 | ▶ | my $count = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 181 | my ($n) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 181 | ▶ | return $n == 1 ? '1 stone' : "$n stones"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 109 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=24 SCAR=32.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 109 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 109 | ▶ | $self->in(\*STDIN) unless $self->in; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 109 | ▶ | $self->out(\*STDOUT) unless $self->out; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 109 | ▶ | $self->interactive(-t $self->in ? 1 : 0) unless defined $self->interactive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 109 | ▶ | $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()
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 109 | ▶ | $self->unicode($self->colour ? 1 : 0) unless defined $self->unicode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 109 | ▶ | $self->_keyboard(Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | in => $self->in, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | ($self->keysource ? (keysource => $self->keysource) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 253 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 109 | ▶ | $self->_screen(Game::Terminal::Kit::Screen->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | out => $self->out, | ||||||||||||||||||||||||||||||||||||||||||
| 256 | interactive => $self->interactive, | ||||||||||||||||||||||||||||||||||||||||||
| 257 | colour => $self->colour, | ||||||||||||||||||||||||||||||||||||||||||
| 258 | ascii => $self->unicode ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | (defined $self->width ? (columns => $self->width) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 260 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 109 | $self->_log(Game::Terminal::Kit::Log->new(keep => 8)); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 109 | ▶ | $self->picking($self->interactive ? 1 : 0) unless defined $self->picking; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 109 | ▶ | $self->picking(0) unless $self->_keys_available; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 109 | ▶ | $self->pause($self->interactive && !$self->keysource ? 1 : 0) unless defined $self->pause; | ||||||||||||||||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 109 | ▶ | $self->menu(0) unless defined $self->menu; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 109 | ▶ | Carp::croak("Game::Fanorona::Terminal: side is white, black, both or neither, not '" . $self->human . "'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | unless $self->human =~ /\A(?:white|black|both|neither)\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 107 | ▶ | Carp::croak('Game::Fanorona::Terminal: level is 1 to ' . scalar(@LEVEL)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | unless $self->level =~ /\A[1-5]\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 105 | ▶ | $self->game($self->_fresh_game) unless $self->game; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | $self->history(Game::Terminal::Kit::History->new( | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 424 | ▶ | save => sub { $_[0]->as_text }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 18 | ▶ | load => sub { (Game::Fanorona->from_text($_[0]))[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 103 | ▶ | )) unless $self->history; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 103 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 103 | $self->_screen->utf8->flush_on; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 103 | return; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 110 | ▶ | sub _fresh_game { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fresh_game: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 110 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 110 | ▶ | return Game::Fanorona->new(defined $self->variant ? (variant => $self->variant) : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 44 | ▶ | sub budget { (Game::Fanorona::Bot->levels)[ $_[0]->level - 1 ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
budget: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 91 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 91 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 91 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 91 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 91 | ▶ | $self->_say($self->_paint('Fanorona.', 'title') . ' Type help for the commands.') unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | Game::Terminal::Kit::Run::guard( | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 91 | ▶ | sub { $self->_turns if !$self->menu || !$self->raw || $self->_ask_how_to_play }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
Condition83%5/6
not $self->menu && $self->raw or $self->_ask_how_to_play
$self->menu && $self->raw
MC/DC66%2/3
not $self->menu && $self->raw or $self->_ask_how_to_play
$self->menu
$self->raw
$self->_ask_how_to_play
Truth table75%3/4
not(A && B) or C
A= $self->menuB= $self->rawC= $self->_ask_how_to_play
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 91 | $self->_keyboard, $self->_screen, | |||||||||||||||||||||||||||||||||||||||||
| 300 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 91 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 90 | ▶ | sub _turns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_turns: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 90 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 90 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 307 | 271 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 271 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 271 | ▶ | if ($game->over) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 22 | ▶ | $self->person_turn unless $self->human eq 'neither'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 22 | ▶ | my $line = $picking ? $self->_pick_ended : $self->_read_ended; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 22 | ▶ | last unless defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 8 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 249 | ▶ | if ($self->_bot_plays($game->turn)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 43 | $self->_bot_move; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 43 | next; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 206 | $self->person_turn; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 206 | ▶ | $self->render if $self->_redraw && !$picking; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->_redraw and not $picking
MC/DC100%2/2
$self->_redraw and not $picking
$self->_redraw
not $picking
Truth table100%3/3
A and not(B)
A= $self->_redrawB= not $picking
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 206 | ▶ | my $line = $picking ? $self->pick : $self->_read_line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 206 | ▶ | unless (defined $line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 26 | ▶ | $self->_say('Bye.') unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 26 | last; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 180 | ▶ | last if $self->command($line); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 90 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 222 | ▶ | sub person_turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
person_turn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 222 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 222 | $self->history->turn($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 222 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 18 | ▶ | sub _read_ended { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_ended: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 18 | ▶ | $self->render if $self->_redraw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 18 | return $self->_read_line('new or quit> '); | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | ▶ | sub _pick_ended { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pick_ended: called CC=12 SCAR=31.2
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 350 | 4 | $self->show('ended'); | |||||||||||||||||||||||||||||||||||||||||
| 351 | 4 | my $key = $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 4 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 4 | ▶ | return 'new' if $key eq 'n' || $key eq 'enter'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "n" or $key eq "enter"
MC/DC50%1/2
$key eq "n" or $key eq "enter"
$key eq "n"
$key eq "enter"
Truth table66%2/3
A or B
A= $key eq "n"B= $key eq "enter"
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | ▶ | return 'undo' if $key eq 'u'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | return 'redo' if $key eq 'r'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | return 'quit' if $key eq 'q' || $key eq 'escape'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "q" or $key eq "escape"
MC/DC0%0/2
$key eq "q" or $key eq "escape"
$key eq "q"
$key eq "escape"
Truth table33%1/3
A or B
A= $key eq "q"B= $key eq "escape"
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | return 'rules' if $key eq 'R'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | return $self->_read_line(': ') if $key eq ':'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 249 | ▶ | sub _bot_plays { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_plays: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 249 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 249 | ▶ | return 0 if $self->human eq 'both'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 83 | ▶ | return 1 if $self->human eq 'neither'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 53 | ▶ | return $side eq $self->human ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 43 | ▶ | sub _bot_move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_move: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 43 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 43 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 43 | my $side = $game->turn; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 43 | ▶ | $self->show('thinking') if $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 43 | my $before = $stones_of->($game->position); | |||||||||||||||||||||||||||||||||||||||||
| 375 | 43 | my $thought = Game::Fanorona::Bot->play($game, level => $self->budget); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 43 | ▶ | return undef unless $thought; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 43 | $self->_played($side, $before); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 43 | ▶ | if ($self->human eq 'neither') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 30 | ▶ | $self->render unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 30 | ▶ | select undef, undef, undef, 0.4 if $self->pause; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 43 | return $thought->{move}; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 115 | ▶ | sub _played { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_played: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 115 | my ($self, $side, $before) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 115 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 115 | my $move = ($game->moves)[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 115 | my $after = $stones_of->($game->position); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 115 | ▶ | my @taken = $drawn->(grep { !$after->{$_} && $before->{$_} ne $side } keys %{$before}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!$after->{$_} && $before->{$_} ne $side
MC/DC100%2/2
!$after->{$_} && $before->{$_} ne $side
!$after->{$_}
$before->{$_} ne $side
Truth table100%3/3
not(A) && B
A= !$after->{$_}B= $before->{$_} ne $side
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 115 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 115 | my @points = move_points($move, cols => $variant->cols, rows => $variant->rows); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 115 | $self->last({ side => $side, move => $move, points => \@points, taken => \@taken }); | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 115 | my $line = ucfirst($side) . ' played ' . $self->_paint($move, 'key'); | |||||||||||||||||||||||||||||||||||||||||
| 396 | 115 | ▶ | $line .= ', taking ' . $count->(scalar @taken) if @taken; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 115 | $line .= '.'; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 115 | ▶ | if ($self->raw) { $self->_log->forget->record($line) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 81 | else { $self->_say($line) } | |||||||||||||||||||||||||||||||||||||||||
| 400 | 115 | $self->_redraw(1); | |||||||||||||||||||||||||||||||||||||||||
| 401 | 115 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 871 | ▶ | sub raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 871 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 871 | return $self->_keyboard->raw; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 387 | ▶ | sub notice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notice: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 387 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 387 | return [ $self->_log->lines ]; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 109 | ▶ | sub _keys_available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys_available: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 109 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 416 | 109 | return $self->_keyboard->keys_available; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 48 | ▶ | sub _enter_raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enter_raw: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 48 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 48 | ▶ | return $self if $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 48 | ▶ | return undef unless $self->_keyboard->enter_raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 48 | ▶ | $self->_screen->hide_cursor unless $self->keysource; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 48 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub _leave_raw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_leave_raw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $self->_keyboard->leave_raw; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $self->_screen->restore; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 263 | ▶ | sub _read_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 263 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 263 | return $self->_keyboard->read_key; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 40 | ▶ | sub steer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
steer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 40 | my ($self, $from, $key, $among) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 40 | ▶ | my $way = $DIRECTION{$key} or return $from; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 38 | my @names = ($from, grep { $_ ne $from } @{$among}); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 38 | my @points = map { [ $coordinates->($_) ] } @names; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 38 | my $to = Game::Terminal::Kit::Steer::nearest(\@points, 0, @{$way}, cone => 1); | |||||||||||||||||||||||||||||||||||||||||
| 445 | 38 | ▶ | return defined $to ? $names[$to] : $from; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 252 | ▶ | sub lit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 252 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 252 | return [ $drawn->($self->game->starts) ]; | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 521 | ▶ | sub so_far { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
so_far: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 521 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 521 | my $prefix = $self->prefix; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 521 | ▶ | return '' unless defined $self->chosen && @{$prefix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->chosen and @{$prefix;}
MC/DC100%2/2
defined $self->chosen and @{$prefix;}
defined $self->chosen
@{$prefix;}
Truth table100%3/3
A and B
A= defined $self->chosenB= @{$prefix;}
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 319 | return $self->chosen . join '', map { substr $_->{string}, 2 } @{$prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 206 | ▶ | sub _standing { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_standing: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 206 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 206 | my $prefix = $self->prefix; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 206 | ▶ | return @{$prefix} ? $prefix->[-1]{to} : $self->chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 364 | ▶ | sub _offers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_offers: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 364 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 364 | my $found = $self->game->continuations($self->so_far); | |||||||||||||||||||||||||||||||||||||||||
| 469 | 364 | ▶ | return { complete => 0, stop => 0, steps => [] } unless $found; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 364 | return $found; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 27 | ▶ | sub playable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
playable: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 27 | ▶ | return 0 unless @{ $self->prefix }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 25 | my $offers = $self->_offers; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 25 | ▶ | return $offers->{complete} || $offers->{stop} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$offers->{"complete"} or $offers->{"stop"}
MC/DC0%0/2
$offers->{"complete"} or $offers->{"stop"}
$offers->{"complete"}
$offers->{"stop"}
Truth table66%2/3
A or B
A= $offers->{"complete"}B= $offers->{"stop"}
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 217 | ▶ | sub _put_down { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_put_down: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 217 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 217 | $self->chosen(undef); | |||||||||||||||||||||||||||||||||||||||||
| 483 | 217 | $self->prefix([]); | |||||||||||||||||||||||||||||||||||||||||
| 484 | 217 | $self->_ask(undef); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 217 | $self->_target(undef); | |||||||||||||||||||||||||||||||||||||||||
| 486 | 217 | $self->_complaint(undef); | |||||||||||||||||||||||||||||||||||||||||
| 487 | 217 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 26 | ▶ | sub _beyond { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_beyond: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 26 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 26 | my $way = $DIRECTION{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 26 | my ($file, $rank) = $coordinates->($self->_standing); | |||||||||||||||||||||||||||||||||||||||||
| 494 | 26 | ($file, $rank) = ($file + $way->[0], $rank + $way->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 495 | 26 | ▶ | return ($file < 0 || $file > 25 || $rank < 0) ? '' : chr(97 + $file) . ($rank + 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$file < 0 or $file > 25 or $rank < 0
$file < 0 or $file > 25
MC/DC0%0/3
$file < 0 or $file > 25 or $rank < 0
$file < 0
$file > 25
$rank < 0
Truth table25%1/4
A or B or C
A= $file < 0B= $file > 25C= $rank < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 25 | ▶ | sub _advance { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_advance: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 25 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 25 | return $self->_step_to($self->_beyond($key)); | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 19 | ▶ | sub _aim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_aim: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 19 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 19 | my $standing = $self->_standing; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 19 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 19 | my @lit = $drawn->(grep { !$seen{$_}++ } map { $_->{to} } grep { $_->{from} eq $standing } @{ $self->_offers->{steps} }); | |||||||||||||||||||||||||||||||||||||||||
| 508 | 19 | ▶ | my $from = defined $self->_target ? $self->_target : $standing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 19 | my $to = $self->steer($from, $key, \@lit); | |||||||||||||||||||||||||||||||||||||||||
| 510 | 19 | ▶ | if ($to eq $from) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 2 | ▶ | return 1 if defined $self->_target; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | return $self->_step_to($self->_beyond($key)); | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 17 | $self->_target($to); | |||||||||||||||||||||||||||||||||||||||||
| 515 | 17 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 35 | ▶ | sub _step_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_step_to: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 35 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 35 | my $standing = $self->_standing; | |||||||||||||||||||||||||||||||||||||||||
| 521 | 35 | $self->_target(undef); | |||||||||||||||||||||||||||||||||||||||||
| 522 | 35 | ▶ | my @there = grep { $_->{from} eq $standing && $_->{to} eq $target } @{ $self->_offers->{steps} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->{'from'} eq $standing && $_->{'to'} eq $target
MC/DC100%2/2
$_->{'from'} eq $standing && $_->{'to'} eq $target
$_->{'from'} eq $standing
$_->{'to'} eq $target
Truth table100%3/3
A && B
A= $_->{'from'} eq $standingB= $_->{'to'} eq $target
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 35 | ▶ | if (!@there) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 7 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 7 | my $said = 'that point is not on the board'; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 7 | ▶ | if ($self->_offers->{complete}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | $said = 'the move is complete, and enter plays it'; | |||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | elsif (length $target) { | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 6 | ▶ | my $tried = (length $self->so_far ? $self->so_far : $standing) . "-$target"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 6 | $game->continuations($tried); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 6 | my $error = $game->error; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 6 | ▶ | if ($error && $error->code eq 'paika_in_chain') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$error and $error->code eq "paika_in_chain"
MC/DC50%1/2
$error and $error->code eq "paika_in_chain"
$error
$error->code eq "paika_in_chain"
Truth table66%2/3
A and B
A= $errorB= $error->code eq "paika_in_chain"
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 4 | $game->continuations($tried . 'A'); | |||||||||||||||||||||||||||||||||||||||||
| 535 | 4 | my $closer = $game->error; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 4 | ▶ | $error = $closer if $closer && $closer->code ne 'takes_nothing'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$closer and $closer->code ne "takes_nothing"
MC/DC50%1/2
$closer and $closer->code ne "takes_nothing"
$closer
$closer->code ne "takes_nothing"
Truth table66%2/3
A and B
A= $closerB= $closer->code ne "takes_nothing"
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 6 | ▶ | $said = $error->message if $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 7 | $self->_complaint(ucfirst($said) . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 541 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 28 | ▶ | if (@there > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 17 | $self->_ask([ @there ]); | |||||||||||||||||||||||||||||||||||||||||
| 545 | 17 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 11 | $self->prefix([ @{ $self->prefix }, $there[0] ]); | |||||||||||||||||||||||||||||||||||||||||
| 548 | 11 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 20 | ▶ | sub _answer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_answer: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 20 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 20 | my $ask = $self->_ask; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 20 | ▶ | if ($key eq 'escape' || $key eq 'backspace') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "escape" or $key eq "backspace"
MC/DC50%1/2
$key eq "escape" or $key eq "backspace"
$key eq "escape"
$key eq "backspace"
Truth table66%2/3
A or B
A= $key eq "escape"B= $key eq "backspace"
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | $self->_ask(undef); | |||||||||||||||||||||||||||||||||||||||||
| 556 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | 19 | ▶ | my $how = $key eq 'a' ? 'approach' : $key eq 'w' ? 'withdrawal' : return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 14 | my ($step) = grep { $_->{how} eq $how } @{$ask}; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 14 | ▶ | return 0 unless $step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 14 | $self->prefix([ @{ $self->prefix }, $step ]); | |||||||||||||||||||||||||||||||||||||||||
| 562 | 14 | $self->_ask(undef); | |||||||||||||||||||||||||||||||||||||||||
| 563 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 93 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=47 SCAR=38.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 93 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 568 | 93 | ▶ | return undef unless $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | 93 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 93 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 572 | 249 | my $lit = $self->lit; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 249 | ▶ | return undef unless @{$lit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 249 | ▶ | $self->focus($lit->[0]) unless defined $self->focus && grep { $_ eq $self->focus } @{$lit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->focus and grep {$_ eq $self->focus;} @{$lit;}
MC/DC50%1/2
defined $self->focus and grep {$_ eq $self->focus;} @{$lit;}
defined $self->focus
grep {$_ eq $self->focus;} @{$lit;}
Truth table66%2/3
A and B
A= defined $self->focusB= grep {$_ eq $self->focus;} @{$lit;}
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 249 | ▶ | my $mode = $self->_ask ? 'ask' : defined $self->chosen ? 'where' : 'which'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 249 | $self->show($mode); | |||||||||||||||||||||||||||||||||||||||||
| 578 | 249 | my $key = $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 579 | 249 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 247 | $self->_complaint(undef); | |||||||||||||||||||||||||||||||||||||||||
| 581 | 247 | ▶ | if ($self->_cramped) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 5 | ▶ | return 'quit' if $key eq 'q'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 242 | ▶ | if ($mode eq 'ask') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 20 | $self->_answer($key); | |||||||||||||||||||||||||||||||||||||||||
| 588 | 20 | next; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 222 | ▶ | if ($DIRECTION{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 55 | ▶ | if ($mode eq 'which') { $self->focus($self->steer($self->focus, $key, $lit)) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 19 | elsif ($key =~ /\A(?:up|down|left|right)\z/) { $self->_aim($key) } | |||||||||||||||||||||||||||||||||||||||||
| 593 | 25 | else { $self->_advance($key) } | |||||||||||||||||||||||||||||||||||||||||
| 594 | 55 | next; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | 167 | ▶ | if ($mode eq 'which' && ($key eq 'tab' || $key eq 'back_tab')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$mode eq "which" and $key eq "tab" || $key eq "back_tab"
$key eq "tab" or $key eq "back_tab"
MC/DC100%3/3
$mode eq "which" and $key eq "tab" || $key eq "back_tab"
$mode eq "which"
$key eq "tab"
$key eq "back_tab"
Truth table100%4/4
A and B or C
A= $mode eq "which"B= $key eq "tab"C= $key eq "back_tab"
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 6 | my ($at) = grep { $lit->[$_] eq $self->focus } 0 .. $#{$lit}; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 6 | ▶ | $self->focus($lit->[ ($at + ($key eq 'tab' ? 1 : -1)) % @{$lit} ]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 161 | ▶ | if ($mode eq 'which' && $key eq 'home') { $self->focus($lit->[0]); next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mode eq "which" and $key eq "home"
MC/DC100%2/2
$mode eq "which" and $key eq "home"
$mode eq "which"
$key eq "home"
Truth table100%3/3
A and B
A= $mode eq "which"B= $key eq "home"
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 160 | ▶ | if ($mode eq 'which' && $key eq 'end') { $self->focus($lit->[-1]); next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mode eq "which" and $key eq "end"
MC/DC100%2/2
$mode eq "which" and $key eq "end"
$mode eq "which"
$key eq "end"
Truth table100%3/3
A and B
A= $mode eq "which"B= $key eq "end"
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 159 | ▶ | 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 " "
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 64 | ▶ | if ($mode eq 'which') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 28 | $self->chosen($self->focus); | |||||||||||||||||||||||||||||||||||||||||
| 607 | 28 | $self->prefix([]); | |||||||||||||||||||||||||||||||||||||||||
| 608 | 28 | next; | |||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||
| 610 | 36 | ▶ | if (defined $self->_target) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 9 | $self->_step_to($self->_target); | |||||||||||||||||||||||||||||||||||||||||
| 612 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | 27 | ▶ | next unless $self->playable; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | 25 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 616 | 25 | my $side = $game->turn; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 25 | my $before = $stones_of->($game->position); | |||||||||||||||||||||||||||||||||||||||||
| 618 | 25 | ▶ | unless ($game->play($self->so_far)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | $self->_complaint(ucfirst($game->error->message) . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 25 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 623 | 25 | $self->focus(undef); | |||||||||||||||||||||||||||||||||||||||||
| 624 | 25 | $self->_played($side, $before); | |||||||||||||||||||||||||||||||||||||||||
| 625 | 25 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 95 | ▶ | if ($key eq 'backspace') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 7 | ▶ | if (defined $self->_target) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | $self->_target(undef); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 6 | my @steps = @{ $self->prefix }; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 6 | ▶ | if (@steps) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 4 | pop @steps; | |||||||||||||||||||||||||||||||||||||||||
| 635 | 4 | $self->prefix(\@steps); | |||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||
| 637 | elsif ($mode eq 'where') { | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 2 | $self->focus($self->chosen); | |||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 88 | ▶ | if ($key eq 'escape') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | 3 | ▶ | $self->focus($self->chosen) if defined $self->chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | 3 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 646 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | 85 | ▶ | if ($key eq 'h') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 649 | 17 | my $thought = Game::Fanorona::Bot->hint($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 650 | 17 | ▶ | if ($thought && @{ $thought->{steps} }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$thought and @{$thought->{"steps"};}
MC/DC0%0/2
$thought and @{$thought->{"steps"};}
$thought
@{$thought->{"steps"};}
Truth table33%1/3
A and B
A= $thoughtB= @{$thought->{"steps"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 17 | $self->chosen($thought->{steps}[0]{from}); | |||||||||||||||||||||||||||||||||||||||||
| 652 | 17 | $self->prefix([ @{ $thought->{steps} } ]); | |||||||||||||||||||||||||||||||||||||||||
| 653 | 17 | $self->_complaint('The program would play ' . $self->_paint($thought->{move}, 'key') | |||||||||||||||||||||||||||||||||||||||||
| 654 | . '. Enter plays it; escape puts the stone back.'); | ||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 17 | next; | |||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||
| 658 | 68 | ▶ | if ($key eq '?') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | $self->show('help'); | |||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | 67 | ▶ | if ($key eq 'u' || $key eq 'r') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "u" or $key eq "r"
MC/DC100%2/2
$key eq "u" or $key eq "r"
$key eq "u"
$key eq "r"
Truth table100%3/3
A or B
A= $key eq "u"B= $key eq "r"
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | 16 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 16 | ▶ | return $key eq 'u' ? 'undo' : 'redo'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | 51 | ▶ | if ($key eq 'R') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | $self->show('rules'); | |||||||||||||||||||||||||||||||||||||||||
| 669 | 1 | $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 50 | ▶ | if ($key eq ':') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | 7 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 7 | return $self->_read_line(': '); | |||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 43 | ▶ | if ($key eq 'q') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 42 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 42 | return 'quit'; | |||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | ▶ | next if $key eq 'unknown'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | $self->_complaint('That key does nothing here. Press ? for the ones that do.'); | |||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 399 | ▶ | sub marks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
marks: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 399 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 687 | 399 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 399 | my $stones = $stones_of->($game->position); | |||||||||||||||||||||||||||||||||||||||||
| 689 | 399 | my (%mark, %sign); | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 399 | ▶ | unless ($mode eq 'where' || $mode eq 'ask') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mode eq "where" or $mode eq "ask"
MC/DC100%2/2
$mode eq "where" or $mode eq "ask"
$mode eq "where"
$mode eq "ask"
Truth table100%3/3
A or B
A= $mode eq "where"B= $mode eq "ask"
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | 273 | ▶ | if (my $last = $self->last) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | 128 | $mark{$_} = 'trail' for @{ $last->{points} }, @{ $last->{taken} }; | |||||||||||||||||||||||||||||||||||||||||
| 694 | 128 | $sign{$_} = 'taken' for @{ $last->{taken} }; | |||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 273 | ▶ | return (\%mark, $stones, \%sign) unless $mode eq 'which' && defined $self->focus; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode eq "which" and defined $self->focus
MC/DC50%1/2
$mode eq "which" and defined $self->focus
$mode eq "which"
defined $self->focus
Truth table66%2/3
A and B
A= $mode eq "which"B= defined $self->focus
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 123 | my $focus = $self->focus; | |||||||||||||||||||||||||||||||||||||||||
| 698 | 123 | for my $step (grep { $_->{from} eq $focus } @{ $self->_offers->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||
| 699 | 242 | $mark{ $step->{to} } = 'reach'; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 242 | delete $sign{ $step->{to} }; | |||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 123 | $mark{$focus} = 'cursor'; | |||||||||||||||||||||||||||||||||||||||||
| 703 | 123 | return (\%mark, $stones, \%sign); | |||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 126 | my $prefix = $self->prefix; | |||||||||||||||||||||||||||||||||||||||||
| 707 | 126 | ▶ | if (@{$prefix}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | 61 | my $after = $game->preview($self->so_far); | |||||||||||||||||||||||||||||||||||||||||
| 709 | 61 | ▶ | $stones = $stones_of->($after) if defined $after; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | 61 | for my $step (@{$prefix}) { | |||||||||||||||||||||||||||||||||||||||||
| 711 | 70 | $mark{ $step->{from} } = 'trail'; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 70 | for my $name (@{ $step->{takes} }) { | |||||||||||||||||||||||||||||||||||||||||
| 713 | 91 | $mark{$name} = 'taken'; | |||||||||||||||||||||||||||||||||||||||||
| 714 | 91 | $sign{$name} = 'taken'; | |||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 126 | my $standing = $self->_standing; | |||||||||||||||||||||||||||||||||||||||||
| 719 | 126 | ▶ | if ($mode eq 'ask') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | 22 | my $ask = $self->_ask; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 22 | $mark{ $ask->[0]{to} } = 'reach'; | |||||||||||||||||||||||||||||||||||||||||
| 722 | 22 | delete $sign{ $ask->[0]{to} }; | |||||||||||||||||||||||||||||||||||||||||
| 723 | 22 | for my $step (@{$ask}) { | |||||||||||||||||||||||||||||||||||||||||
| 724 | 44 | ▶ | my $how = $step->{how} eq 'approach' ? 'approach' : 'withdrawal'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 44 | for my $name (@{ $step->{takes} }) { | |||||||||||||||||||||||||||||||||||||||||
| 726 | 44 | $mark{$name} = $how; | |||||||||||||||||||||||||||||||||||||||||
| 727 | 44 | $sign{$name} = substr $how, 0, 1; | |||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 104 | for my $step (grep { $_->{from} eq $standing } @{ $self->_offers->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||
| 733 | 169 | $mark{ $step->{to} } = 'reach'; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 169 | delete $sign{ $step->{to} }; | |||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 104 | ▶ | $mark{ $self->_target } = 'cursor' if defined $self->_target; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 126 | $mark{$standing} = 'moving'; | |||||||||||||||||||||||||||||||||||||||||
| 739 | 126 | delete $sign{$standing}; | |||||||||||||||||||||||||||||||||||||||||
| 740 | 126 | return (\%mark, $stones, \%sign); | |||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 1795 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 1795 | my ($self, $text, $ink) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 745 | 1795 | return $self->_screen->paint($text, $INK{$ink}); | |||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 66813 | ▶ | sub _paint_on { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint_on: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | 66813 | my ($self, $text, $ink, $ground) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 750 | 66813 | return $self->_screen->paint($text, "$GROUND{$ground};$INK{$ink}"); | |||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | 17968 | ▶ | sub _glyph { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glyph: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 17968 | my ($self, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 755 | 17968 | ▶ | return $GLYPH{ $self->unicode ? 'wide' : 'ascii' }{$what}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 16803 | ▶ | sub _cell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | 16803 | my ($self, $stone, $mark, $sign, $first, $final) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 16803 | ▶ | my $glyph = $self->_glyph(defined $sign ? $sign : $stone ? $stone : 'empty'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 16803 | ▶ | $glyph = $sign unless defined $glyph; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | 16803 | ▶ | if (!$mark) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 15598 | ▶ | return $self->_paint_on($first ? ' ' : '-', 'line', 'board') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | . $self->_paint_on($glyph, $stone ? $stone : 'line', 'board') | ||||||||||||||||||||||||||||||||||||||||||
| 765 | . $self->_paint_on($final ? ' ' : '-', 'line', 'board'); | ||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||
| 767 | 1205 | my ($open, $close) = @{ $FRAME{$mark} }; | |||||||||||||||||||||||||||||||||||||||||
| 768 | 1205 | ▶ | return $self->_paint_on($open, $mark, $mark) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $sign or not $stone
MC/DC100%2/2
defined $sign or not $stone
defined $sign
not $stone
Truth table100%3/3
A or not(B)
A= defined $signB= not $stone
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | . $self->_paint_on($glyph, (defined $sign || !$stone) ? $mark : $stone, $mark) | ||||||||||||||||||||||||||||||||||||||||||
| 770 | . $self->_paint_on($close, $mark, $mark); | ||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | 798 | ▶ | sub _baseline { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_baseline: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 798 | my ($self, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 775 | 798 | my $start = $stones_of->($self->game->variant->start); | |||||||||||||||||||||||||||||||||||||||||
| 776 | 798 | return scalar grep { $_ eq $side } values %{$start}; | |||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 399 | ▶ | sub _panel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_panel: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | 399 | my ($self, $stones) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 781 | 399 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 782 | 399 | my %left = (white => 0, black => 0); | |||||||||||||||||||||||||||||||||||||||||
| 783 | 399 | $left{$_}++ for values %{$stones}; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 399 | my $rows = $game->variant->rows; | |||||||||||||||||||||||||||||||||||||||||
| 785 | 399 | my %panel; | |||||||||||||||||||||||||||||||||||||||||
| 786 | 399 | for my $side (qw(black white)) { | |||||||||||||||||||||||||||||||||||||||||
| 787 | 798 | my $taken = $self->_baseline($other->($side)) - $left{ $other->($side) }; | |||||||||||||||||||||||||||||||||||||||||
| 788 | 798 | ▶ | $taken = 0 if $taken < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | $panel{ $side eq 'black' ? 0 : 2 * ($rows - 1) } = sprintf '%s %s %2d left taken %d', | ||||||||||||||||||||||||||||||||||||||||||
| 790 | 798 | ▶ | ucfirst $side, $self->_paint($self->_glyph($side), 'key'), $left{$side}, $taken; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||
| 792 | 399 | my ($quiet, $limit) = ($game->quiet, $game->quiet_limit); | |||||||||||||||||||||||||||||||||||||||||
| 793 | 399 | ▶ | $panel{ $rows - 1 } = $self->_paint("Nothing taken for $quiet of $limit", 'warn') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$limit > 0 and $quiet * 2 > $limit and not $game->over
$limit > 0 and $quiet * 2 > $limit
MC/DC100%3/3
$limit > 0 and $quiet * 2 > $limit and not $game->over
$limit > 0
$quiet * 2 > $limit
not $game->over
Truth table100%4/4
A and B and not(C)
A= $limit > 0B= $quiet * 2 > $limitC= not $game->over
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | if $limit > 0 && $quiet * 2 > $limit && !$game->over; | ||||||||||||||||||||||||||||||||||||||||||
| 795 | 399 | return \%panel; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 399 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 399 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 800 | 399 | ▶ | my ($mark, $stones, $sign) = $self->marks(defined $mode ? $mode : 'plain'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 399 | my $variant = $self->game->variant; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 399 | my ($cols, $rows) = ($variant->cols, $variant->rows); | |||||||||||||||||||||||||||||||||||||||||
| 803 | 399 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 804 | 399 | for my $rank (reverse 0 .. $rows - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 805 | 1931 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 1931 | for my $file (0 .. $cols - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 807 | 16803 | my $name = chr(97 + $file) . ($rank + 1); | |||||||||||||||||||||||||||||||||||||||||
| 808 | 16803 | $line .= $self->_cell($stones->{$name}, $mark->{$name}, $sign->{$name}, $file == 0, $file == $cols - 1); | |||||||||||||||||||||||||||||||||||||||||
| 809 | 16803 | ▶ | $line .= $self->_paint_on('-', 'line', 'board') if $file < $cols - 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 1931 | push @lines, ($rank + 1) . ' ' . $line; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 1931 | ▶ | next unless $rank; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 813 | 1532 | my $link = ''; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 1532 | for my $file (0 .. $cols - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 815 | 13404 | $link .= ' | '; | |||||||||||||||||||||||||||||||||||||||||
| 816 | 13404 | ▶ | $link .= (($file + $rank - 1) % 2 ? '\\' : '/') if $file < $cols - 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 1532 | push @lines, ' ' . $self->_paint_on($link, 'line', 'board'); | |||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 399 | push @lines, ' ' . join ' ', map { ' ' . chr(97 + $_) . ' ' } 0 .. $cols - 1; | |||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | 399 | my $panel = $self->_panel($stones); | |||||||||||||||||||||||||||||||||||||||||
| 823 | 399 | $lines[$_] .= ' ' . $panel->{$_} for keys %{$panel}; | |||||||||||||||||||||||||||||||||||||||||
| 824 | 399 | ▶ | unless ($self->colour) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | 397 | s{\s+\z}{} for @lines; | |||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | 399 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 392 | ▶ | sub _columns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_columns: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 392 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 392 | ▶ | return $self->width if defined $self->width; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 377 | ▶ | return undef unless $self->interactive && !$self->keysource; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->interactive and not $self->keysource
MC/DC0%0/2
$self->interactive and not $self->keysource
$self->interactive
not $self->keysource
Truth table66%2/3
A and not(B)
A= $self->interactiveB= not $self->keysource
| |||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | my ($wide) = $self->_screen->measured; | |||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | return $wide; | |||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | 392 | ▶ | sub _too_narrow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_too_narrow: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | 392 | my ($self, $lines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 840 | 392 | $self->_cramped(0); | |||||||||||||||||||||||||||||||||||||||||
| 841 | 392 | my $have = $self->_columns; | |||||||||||||||||||||||||||||||||||||||||
| 842 | 392 | ▶ | return undef unless defined $have && $have > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $have and $have > 0
MC/DC50%1/2
defined $have and $have > 0
defined $have
$have > 0
Truth table66%2/3
A and B
A= defined $haveB= $have > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | 15 | my ($need) = sort { $b <=> $a } map { length $plain->($_) } @{$lines}; | |||||||||||||||||||||||||||||||||||||||||
| 844 | 15 | ▶ | return undef if $have >= $need; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | 8 | $self->_cramped(1); | |||||||||||||||||||||||||||||||||||||||||
| 846 | 8 | return "This window is $have columns wide and the board needs $need. Widen it and press a key, or q to stop."; | |||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 386 | ▶ | sub _status_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_status_lines: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | 386 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 851 | 386 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 852 | 386 | ▶ | if (my $result = $game->result) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 853 | 19 | my $winner = $result->winner; | |||||||||||||||||||||||||||||||||||||||||
| 854 | 19 | ▶ | my @with = ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 855 | ucfirst(defined $winner ? $winner : ''), ucfirst(defined $winner ? $other->($winner) : ''), | ||||||||||||||||||||||||||||||||||||||||||
| 856 | $game->quiet_limit, | ||||||||||||||||||||||||||||||||||||||||||
| 857 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 858 | 19 | (my $line = $ENDING{ $result->how }) =~ s/%([123])\$[sd]/$with[ $1 - 1 ]/g; | |||||||||||||||||||||||||||||||||||||||||
| 859 | 19 | return [ $self->_paint($line, 'good') ]; | |||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 367 | my $side = $game->turn; | |||||||||||||||||||||||||||||||||||||||||
| 862 | 367 | my @lines = (sprintf 'Move %d. %s to play, %s.', $game->ply + 1, ucfirst $side, $self->_glyph($side)); | |||||||||||||||||||||||||||||||||||||||||
| 863 | 367 | my $offer = $game->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 864 | 367 | ▶ | push @lines, $self->_paint(ucfirst($offer) . ' has offered a draw: accept or decline.', 'warn') if defined $offer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | 367 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 126 | ▶ | sub _preview_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_preview_lines: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | 126 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 870 | 126 | my $prefix = $self->prefix; | |||||||||||||||||||||||||||||||||||||||||
| 871 | 126 | ▶ | my @aimed = defined $self->_target ? ('Enter steps to ' . $self->_paint($self->_target, 'key') . '.') : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 872 | 126 | ▶ | return [ 'Choose where the stone at ' . $self->chosen . ' goes.', @aimed ] unless @{$prefix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | 61 | my $taken = 0; | |||||||||||||||||||||||||||||||||||||||||
| 874 | 61 | $taken += @{ $_->{takes} } for @{$prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 875 | 61 | my $line = 'So far ' . $self->_paint($self->so_far, 'key'); | |||||||||||||||||||||||||||||||||||||||||
| 876 | 61 | ▶ | $line .= ', taking ' . $count->($taken) if $taken; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 877 | 61 | return [ "$line.", @aimed ]; | |||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | 269 | ▶ | sub _legend { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legend: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | 269 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 882 | 269 | my $text; | |||||||||||||||||||||||||||||||||||||||||
| 883 | 269 | ▶ | if ($mode eq 'which') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 884 | 118 | $text = 'arrows choose a stone enter pick it up h hint ? help : command q quit'; | |||||||||||||||||||||||||||||||||||||||||
| 885 | } | ||||||||||||||||||||||||||||||||||||||||||
| 886 | elsif ($mode eq 'where') { | ||||||||||||||||||||||||||||||||||||||||||
| 887 | $text = defined $self->_target | ||||||||||||||||||||||||||||||||||||||||||
| 888 | ? 'enter step there arrows choose another point backspace not there esc start again' | ||||||||||||||||||||||||||||||||||||||||||
| 889 | 86 | ▶ | : @{ $self->prefix } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | 104 | ▶ | ? ($self->_offers->{complete} ? '' : 'arrows choose the next step ') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | . 'enter play it backspace one step back esc start again' | ||||||||||||||||||||||||||||||||||||||||||
| 892 | : 'arrows choose where it goes, enter steps there y b n 7 9 1 3 step at once esc put it down'; | ||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||
| 894 | elsif ($mode eq 'ask') { | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 22 | my $ask = $self->_ask; | |||||||||||||||||||||||||||||||||||||||||
| 896 | 22 | my %takes = map { $_->{how} => scalar @{ $_->{takes} } } @{$ask}; | |||||||||||||||||||||||||||||||||||||||||
| 897 | $text = 'a take ' . $count->($takes{approach}) . ' ahead w take ' . $count->($takes{withdrawal}) | ||||||||||||||||||||||||||||||||||||||||||
| 898 | 22 | . ' behind esc neither'; | |||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||
| 900 | 4 | elsif ($mode eq 'ended') { $text = 'n new game u undo r redo R rules : command q quit' } | |||||||||||||||||||||||||||||||||||||||||
| 901 | 9 | elsif ($mode eq 'thinking') { $text = 'The program is thinking.' } | |||||||||||||||||||||||||||||||||||||||||
| 902 | 8 | elsif ($mode eq 'menu') { $text = 'up and down choose a line left and right change it enter play q quit' } | |||||||||||||||||||||||||||||||||||||||||
| 903 | 4 | else { $text = 'Any key goes back.' } | |||||||||||||||||||||||||||||||||||||||||
| 904 | 269 | return $self->_paint($text, 'quiet'); | |||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | 118 | ▶ | sub _history_legend { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_history_legend: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 908 | 118 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 909 | 118 | my $history = $self->history; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 118 | ▶ | my @keys = (($history->can_undo ? ('u undo') : ()), ($history->can_redo ? ('r redo') : ())); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | 118 | ▶ | return @keys ? $self->_paint(join(' ', @keys), 'quiet') : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | 3 | ▶ | sub _help_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_help_lines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 915 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 916 | 3 | my @lines = ('The keys:', ''); | |||||||||||||||||||||||||||||||||||||||||
| 917 | 3 | push @lines, ' ' . $self->_paint(sprintf('%-11s', $_->[0]), 'key') . ' ' . $_->[1] for @KEYS; | |||||||||||||||||||||||||||||||||||||||||
| 918 | 3 | push @lines, '', 'The commands, typed after a colon or at the prompt:', ''; | |||||||||||||||||||||||||||||||||||||||||
| 919 | 3 | push @lines, ' ' . $self->_paint(sprintf('%-11s', $_->[0]), 'key') . ' ' . $_->[1] for @COMMANDS; | |||||||||||||||||||||||||||||||||||||||||
| 920 | 3 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | 3 | ▶ | sub _rules_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rules_lines: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 924 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 925 | 3 | my $limit = $self->game->quiet_limit; | |||||||||||||||||||||||||||||||||||||||||
| 926 | 3 | ▶ | return [ map { /%d/ ? sprintf($_, $limit) : $_ } @RULES ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||
| 929 | 8 | ▶ | sub _menu_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_menu_lines: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 930 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 931 | 8 | my $choice = $self->_choice; | |||||||||||||||||||||||||||||||||||||||||
| 932 | 8 | my @lines = ('How shall we play?', ''); | |||||||||||||||||||||||||||||||||||||||||
| 933 | 8 | for my $n (0 .. $#{ $choice->{rows} }) { | |||||||||||||||||||||||||||||||||||||||||
| 934 | 24 | my ($name, $values) = @{ $choice->{rows}[$n] }; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 24 | my $value = $values->[ $choice->{at}{$name} ]; | |||||||||||||||||||||||||||||||||||||||||
| 936 | 24 | my $shown = sprintf '%-8s < %s >', $name, $value; | |||||||||||||||||||||||||||||||||||||||||
| 937 | 24 | ▶ | $shown .= ' ' . $LEVEL[ $value - 1 ] if $name eq 'level'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 938 | 24 | ▶ | push @lines, ($n == $choice->{row} ? '> ' : ' ') . ($n == $choice->{row} ? $self->_paint($shown, 'key') : $shown); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||
| 940 | 8 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | 2 | ▶ | sub _ask_how_to_play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ask_how_to_play: called CC=13 SCAR=25.9
| |||||||||||||||||||||||||||||||||||||||||||
| 944 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 945 | 2 | my @names = Game::Fanorona::Variant->names; | |||||||||||||||||||||||||||||||||||||||||
| 946 | 2 | my @rows = ( | |||||||||||||||||||||||||||||||||||||||||
| 947 | [ side => [qw(white black both neither)] ], | ||||||||||||||||||||||||||||||||||||||||||
| 948 | [ level => [ 1 .. scalar @LEVEL ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 949 | [ variant => \@names ], | ||||||||||||||||||||||||||||||||||||||||||
| 950 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 951 | 2 | my %now = (side => $self->human, level => $self->level, variant => $self->game->variant->name); | |||||||||||||||||||||||||||||||||||||||||
| 952 | 2 | my %at; | |||||||||||||||||||||||||||||||||||||||||
| 953 | 2 | for my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||
| 954 | 6 | my ($name, $values) = @{$row}; | |||||||||||||||||||||||||||||||||||||||||
| 955 | 6 | ($at{$name}) = grep { $values->[$_] eq $now{$name} } 0 .. $#{$values}; | |||||||||||||||||||||||||||||||||||||||||
| 956 | 6 | ▶ | $at{$name} = 0 unless defined $at{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||
| 958 | 2 | $self->_choice({ rows => \@rows, at => \%at, row => 0 }); | |||||||||||||||||||||||||||||||||||||||||
| 959 | 2 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 960 | 8 | $self->show('menu'); | |||||||||||||||||||||||||||||||||||||||||
| 961 | 8 | my $key = $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 962 | 8 | ▶ | return 0 if !defined $key || $key =~ /\A(?:eof|interrupt|q|escape)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $key or $key =~ /\A(?:eof|interrupt|q|escape)\z/u
MC/DC50%1/2
not defined $key or $key =~ /\A(?:eof|interrupt|q|escape)\z/u
not defined $key
$key =~ /\A(?:eof|interrupt|q|escape)\z/u
Truth table66%2/3
not(A) or B
A= not defined $keyB= $key =~ /\A(?:eof|interrupt|q|escape)\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 963 | 7 | my $choice = $self->_choice; | |||||||||||||||||||||||||||||||||||||||||
| 964 | 7 | my ($name, $values) = @{ $rows[ $choice->{row} ] }; | |||||||||||||||||||||||||||||||||||||||||
| 965 | 0 | ▶ | if ($key eq 'up') { $choice->{row} = ($choice->{row} - 1) % @rows } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 966 | 2 | ▶ | elsif ($key eq 'down' || $key eq 'tab') { $choice->{row} = ($choice->{row} + 1) % @rows } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$key eq "down" or $key eq "tab"
MC/DC50%1/2
$key eq "down" or $key eq "tab"
$key eq "down"
$key eq "tab"
Truth table66%2/3
A or B
A= $key eq "down"B= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||
| 967 | 1 | elsif ($key eq 'left') { $at{$name} = ($at{$name} - 1) % @{$values} } | |||||||||||||||||||||||||||||||||||||||||
| 968 | 3 | ▶ | elsif ($key eq 'right' || $key eq ' ') { $at{$name} = ($at{$name} + 1) % @{$values} } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$key eq "right" or $key eq " "
MC/DC50%1/2
$key eq "right" or $key eq " "
$key eq "right"
$key eq " "
Truth table66%2/3
A or B
A= $key eq "right"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||
| 969 | 1 | elsif ($key eq 'enter') { last } | |||||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||||
| 971 | 1 | $self->human($rows[0][1][ $at{side} ]); | |||||||||||||||||||||||||||||||||||||||||
| 972 | 1 | $self->level($rows[1][1][ $at{level} ]); | |||||||||||||||||||||||||||||||||||||||||
| 973 | 1 | my $variant = $rows[2][1][ $at{variant} ]; | |||||||||||||||||||||||||||||||||||||||||
| 974 | 1 | ▶ | if ($variant ne $now{variant}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 975 | 1 | $self->variant($variant); | |||||||||||||||||||||||||||||||||||||||||
| 976 | 1 | $self->game($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||
| 977 | 1 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||
| 979 | 1 | $self->_choice(undef); | |||||||||||||||||||||||||||||||||||||||||
| 980 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||
| 983 | 275 | ▶ | sub screen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
screen: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 984 | 275 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 985 | 275 | ▶ | $mode = 'plain' unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 986 | 275 | my @lines = ($self->_paint('Fanorona', 'title'), ''); | |||||||||||||||||||||||||||||||||||||||||
| 987 | 275 | ▶ | if ($mode eq 'help') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 988 | 1 | push @lines, @{ $self->_help_lines }, '', $self->_legend('help'); | |||||||||||||||||||||||||||||||||||||||||
| 989 | 1 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||
| 991 | 274 | ▶ | if ($mode eq 'rules') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 992 | 1 | push @lines, @{ $self->_rules_lines }, '', $self->_legend('rules'); | |||||||||||||||||||||||||||||||||||||||||
| 993 | 1 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||
| 995 | 273 | ▶ | if ($mode eq 'menu') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 996 | 8 | push @lines, @{ $self->_menu_lines }, '', $self->_legend('menu'); | |||||||||||||||||||||||||||||||||||||||||
| 997 | 8 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||
| 999 | 265 | my $board = $self->board_lines($mode); | |||||||||||||||||||||||||||||||||||||||||
| 1000 | 265 | ▶ | if (defined(my $narrow = $self->_too_narrow($board))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1001 | 6 | push @lines, $narrow; | |||||||||||||||||||||||||||||||||||||||||
| 1002 | 6 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | 259 | my @said = @{ $self->notice }; | |||||||||||||||||||||||||||||||||||||||||
| 1005 | 259 | ▶ | push @said, $self->_paint($self->_complaint, 'warn') if defined $self->_complaint; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 259 | ▶ | push @lines, @said, '' if @said; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1007 | 259 | push @lines, @{$board}, ''; | |||||||||||||||||||||||||||||||||||||||||
| 1008 | 259 | push @lines, @{ $self->_status_lines }; | |||||||||||||||||||||||||||||||||||||||||
| 1009 | 259 | ▶ | push @lines, @{ $self->_preview_lines } if $mode eq 'where' || $mode eq 'ask'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mode eq "where" or $mode eq "ask"
MC/DC100%2/2
$mode eq "where" or $mode eq "ask"
$mode eq "where"
$mode eq "ask"
Truth table100%3/3
A or B
A= $mode eq "where"B= $mode eq "ask"
| |||||||||||||||||||||||||||||||||||||||||||
| 1010 | 259 | push @lines, '', $self->_legend($mode); | |||||||||||||||||||||||||||||||||||||||||
| 1011 | 259 | ▶ | push @lines, $self->_history_legend if $mode eq 'which'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1012 | 259 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||
| 1015 | 272 | ▶ | sub show { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1016 | 272 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1017 | 272 | my $lines = $self->screen($mode); | |||||||||||||||||||||||||||||||||||||||||
| 1018 | 272 | $self->_frame($lines); | |||||||||||||||||||||||||||||||||||||||||
| 1019 | 272 | $self->_screen->show($lines); | |||||||||||||||||||||||||||||||||||||||||
| 1020 | 272 | $self->_redraw(0); | |||||||||||||||||||||||||||||||||||||||||
| 1021 | 272 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||
| 1024 | 127 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1025 | 127 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1026 | 127 | my $board = $self->board_lines('plain'); | |||||||||||||||||||||||||||||||||||||||||
| 1027 | 127 | my $narrow = $self->_too_narrow($board); | |||||||||||||||||||||||||||||||||||||||||
| 1028 | 127 | $self->_cramped(0); | |||||||||||||||||||||||||||||||||||||||||
| 1029 | 127 | $self->_say($_) for @{ $self->notice }; | |||||||||||||||||||||||||||||||||||||||||
| 1030 | 127 | ▶ | $self->_say($_) for defined $narrow ? ($narrow) : (@{$board}, ''), @{ $self->_status_lines }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1031 | 127 | $self->_redraw(0); | |||||||||||||||||||||||||||||||||||||||||
| 1032 | 127 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 1669 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1036 | 1669 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1037 | 1669 | $self->_screen->say($line); | |||||||||||||||||||||||||||||||||||||||||
| 1038 | 1669 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||
| 1041 | 59 | ▶ | sub _remark { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remark: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1042 | 59 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1043 | 59 | ▶ | if ($self->raw) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1044 | 24 | $self->_log->record($_) for @lines; | |||||||||||||||||||||||||||||||||||||||||
| 1045 | 24 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | 35 | $self->_say($_) for @lines; | |||||||||||||||||||||||||||||||||||||||||
| 1048 | 35 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||
| 1051 | 138 | ▶ | sub _read_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_line: called CC=10 SCAR=23.3
| |||||||||||||||||||||||||||||||||||||||||||
| 1052 | 138 | my ($self, $prompt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1053 | 138 | my $out = $self->out; | |||||||||||||||||||||||||||||||||||||||||
| 1054 | 138 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1055 | 138 | ▶ | my $ask = defined $prompt ? $prompt : ($game->turn || 'game over') . '> '; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$game->turn || 'game over'
MC/DC0%0/1
$game->turn || 'game over'
$game->turn
Truth table50%1/2
A
A= $game->turn
| |||||||||||||||||||||||||||||||||||||||||||
| 1056 | 138 | ▶ | if ($self->raw) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1057 | 7 | ▶ | my $typed = Game::Terminal::Kit::Line->new(prompt => $ask, head => $self->_frame || []); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_frame || []
MC/DC0%0/1
$self->_frame || []
$self->_frame
Truth table50%1/2
A
A= $self->_frame
| |||||||||||||||||||||||||||||||||||||||||||
| 1058 | 7 | my ($event, $text) = $typed->run($self->_keyboard, $self->_screen); | |||||||||||||||||||||||||||||||||||||||||
| 1059 | 7 | ▶ | return $event eq 'chosen' ? $text : $event eq 'back' ? '' : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | 131 | print {$out} $ask; | |||||||||||||||||||||||||||||||||||||||||
| 1062 | 131 | my $line = readline $self->in; | |||||||||||||||||||||||||||||||||||||||||
| 1063 | 131 | ▶ | unless (defined $line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1064 | 38 | ▶ | print {$out} "\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1065 | 38 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 1066 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | 93 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 1068 | 93 | $line =~ s/\r\z//; | |||||||||||||||||||||||||||||||||||||||||
| 1069 | 93 | ▶ | print {$out} "$line\n" unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1070 | 93 | return $line; | |||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||
| 1073 | 19 | my %DO; | |||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||
| 1075 | 190 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1076 | 190 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1077 | 190 | ▶ | $line = '' unless defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | 190 | $line =~ s/\A\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 1079 | 190 | $line =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 1080 | 190 | ▶ | return 0 unless length $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1081 | 163 | my ($word, $rest) = split /\s+/, $line, 2; | |||||||||||||||||||||||||||||||||||||||||
| 1082 | 163 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||
| 1083 | 163 | ▶ | return 1 if $word eq 'quit' || $word eq 'exit' || $word eq 'q'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$word eq "quit" or $word eq "exit" or $word eq "q"
$word eq "quit" or $word eq "exit"
MC/DC33%1/3
$word eq "quit" or $word eq "exit" or $word eq "q"
$word eq "quit"
$word eq "exit"
$word eq "q"
Truth table50%2/4
A or B or C
A= $word eq "quit"B= $word eq "exit"C= $word eq "q"
| |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 113 | ▶ | $self->_redraw(1) if $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1085 | 113 | ▶ | if (my $do = $DO{$word}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1086 | 63 | my $was = $self->game->over; | |||||||||||||||||||||||||||||||||||||||||
| 1087 | 63 | ▶ | $self->$do(defined $rest ? $rest : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | 63 | ▶ | $self->_redraw(1) if $self->game->over != $was; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 63 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1090 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | 50 | $self->_play_text($line); | |||||||||||||||||||||||||||||||||||||||||
| 1092 | 50 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||
| 1095 | 50 | ▶ | sub _play_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_play_text: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1096 | 50 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1097 | 50 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1098 | 50 | ▶ | if ($game->over) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1 | $self->_remark('The game is over. new starts another.'); | |||||||||||||||||||||||||||||||||||||||||
| 1100 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | 49 | my $side = $game->turn; | |||||||||||||||||||||||||||||||||||||||||
| 1103 | 49 | my $before = $stones_of->($game->position); | |||||||||||||||||||||||||||||||||||||||||
| 1104 | 49 | ▶ | unless ($game->play($text)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1105 | 2 | $self->_remark("$text: " . $game->error->message . '. help lists the commands.'); | |||||||||||||||||||||||||||||||||||||||||
| 1106 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | 47 | $self->_played($side, $before); | |||||||||||||||||||||||||||||||||||||||||
| 1109 | 47 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||
| 1112 | 8 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1113 | 8 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1114 | 8 | ▶ | unless (defined $file && length $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and length $file
MC/DC50%1/2
defined $file and length $file
defined $file
length $file
Truth table66%2/3
A and B
A= defined $fileB= length $file
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1 | $self->_remark('load takes the name of a file.'); | |||||||||||||||||||||||||||||||||||||||||
| 1116 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | 7 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 1119 | 7 | ▶ | unless (open $fh, '<', $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1120 | 2 | $self->_remark("Cannot read $file: $!."); | |||||||||||||||||||||||||||||||||||||||||
| 1121 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | 5 | my $text = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||
| 1124 | 5 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 1125 | 5 | ▶ | my ($game, $why, $line) = Game::Fanorona->from_text(defined $text ? $text : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1126 | 5 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 2 | ▶ | $self->_remark("$file is not a game of fanorona: $why, line " . (defined $line ? $line : '?') . '.'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1128 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | 3 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||
| 1131 | 3 | $self->history->start($game); | |||||||||||||||||||||||||||||||||||||||||
| 1132 | 3 | my @moves = $game->moves; | |||||||||||||||||||||||||||||||||||||||||
| 1133 | 3 | $self->_remark("Loaded $file: " . scalar(@moves) . ' moves.'); | |||||||||||||||||||||||||||||||||||||||||
| 1134 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||
| 1137 | 9 | ▶ | sub _mine { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mine: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1138 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1139 | 9 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1140 | 9 | ▶ | return undef if $self->human eq 'neither' || $game->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->human eq "neither" or $game->over
MC/DC50%1/2
$self->human eq "neither" or $game->over
$self->human eq "neither"
$game->over
Truth table66%2/3
A or B
A= $self->human eq "neither"B= $game->over
| |||||||||||||||||||||||||||||||||||||||||||
| 1141 | 7 | ▶ | return $self->human eq 'both' ? $game->turn : $self->human; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | 25 | ▶ | sub swap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
swap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1145 | 25 | my ($self, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1146 | 25 | $self->game($game); | |||||||||||||||||||||||||||||||||||||||||
| 1147 | 25 | $self->last(undef); | |||||||||||||||||||||||||||||||||||||||||
| 1148 | 25 | $self->_log->forget; | |||||||||||||||||||||||||||||||||||||||||
| 1149 | 25 | $self->focus(undef); | |||||||||||||||||||||||||||||||||||||||||
| 1150 | 25 | $self->_put_down; | |||||||||||||||||||||||||||||||||||||||||
| 1151 | 25 | $self->_redraw(1); | |||||||||||||||||||||||||||||||||||||||||
| 1152 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||
| 1155 | 16 | ▶ | sub take_back { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
take_back: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1156 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1157 | 16 | ▶ | my $game = $self->human eq 'neither' ? undef : $self->history->undo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1158 | 16 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1159 | 3 | $self->_remark('There is nothing to take back.'); | |||||||||||||||||||||||||||||||||||||||||
| 1160 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | 13 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||
| 1163 | 13 | $self->last($self->_recall); | |||||||||||||||||||||||||||||||||||||||||
| 1164 | 13 | $self->_remark('Taken back.'); | |||||||||||||||||||||||||||||||||||||||||
| 1165 | 13 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||
| 1168 | 7 | ▶ | sub play_again { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_again: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1169 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1170 | 7 | ▶ | my $game = $self->human eq 'neither' ? undef : $self->history->redo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1171 | 7 | ▶ | unless ($game) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1172 | 2 | $self->_remark('There is nothing to play again.'); | |||||||||||||||||||||||||||||||||||||||||
| 1173 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | 5 | $self->swap($game); | |||||||||||||||||||||||||||||||||||||||||
| 1176 | 5 | $self->last($self->_recall); | |||||||||||||||||||||||||||||||||||||||||
| 1177 | 5 | $self->_remark('Played again.'); | |||||||||||||||||||||||||||||||||||||||||
| 1178 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||
| 1181 | 18 | ▶ | sub _recall { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_recall: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1182 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1183 | 18 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1184 | 18 | my @moves = $game->moves; | |||||||||||||||||||||||||||||||||||||||||
| 1185 | 18 | ▶ | return undef unless @moves; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1186 | 10 | my $move = pop @moves; | |||||||||||||||||||||||||||||||||||||||||
| 1187 | 10 | my ($earlier) = Game::Fanorona->replay(\@moves, variant => $game->variant); | |||||||||||||||||||||||||||||||||||||||||
| 1188 | 10 | my $side = $earlier->turn; | |||||||||||||||||||||||||||||||||||||||||
| 1189 | 10 | my $before = $stones_of->($earlier->position); | |||||||||||||||||||||||||||||||||||||||||
| 1190 | 10 | my $after = $stones_of->($game->position); | |||||||||||||||||||||||||||||||||||||||||
| 1191 | 10 | ▶ | my @taken = $drawn->(grep { !$after->{$_} && $before->{$_} ne $side } keys %{$before}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!$after->{$_} && $before->{$_} ne $side
MC/DC100%2/2
!$after->{$_} && $before->{$_} ne $side
!$after->{$_}
$before->{$_} ne $side
Truth table100%3/3
not(A) && B
A= !$after->{$_}B= $before->{$_} ne $side
| |||||||||||||||||||||||||||||||||||||||||||
| 1192 | 10 | my $variant = $game->variant; | |||||||||||||||||||||||||||||||||||||||||
| 1193 | 10 | my @points = move_points($move, cols => $variant->cols, rows => $variant->rows); | |||||||||||||||||||||||||||||||||||||||||
| 1194 | 10 | return { side => $side, move => $move, points => \@points, taken => \@taken }; | |||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||
| 1197 | %DO = ( | ||||||||||||||||||||||||||||||||||||||||||
| 1198 | 1 | ▶ | help => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||
| 1199 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1200 | 1 | ▶ | if ($self->raw) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | $self->show('help'); | |||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | 1 | $self->_say($_) for @{ $self->_help_lines }; | |||||||||||||||||||||||||||||||||||||||||
| 1206 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1207 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | 2 | ▶ | rules => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||
| 1209 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1210 | 2 | ▶ | if ($self->raw) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1211 | 0 | $self->show('rules'); | |||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | $self->_read_key; | |||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | 2 | $self->_say($_) for @{ $self->_rules_lines }; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1217 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1218 | 2 | ▶ | board => sub { $_[0]->_redraw(1); return }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1219 | 15 | ▶ | undo => sub { $_[0]->take_back; return }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1220 | 7 | ▶ | redo => sub { $_[0]->play_again; return }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1221 | 2 | ▶ | moves => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 1222 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1223 | 2 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1224 | 2 | my @steps = $game->steps; | |||||||||||||||||||||||||||||||||||||||||
| 1225 | 2 | ▶ | return $self->_remark('The game is over.') unless @steps; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1226 | 2 | ▶ | return $self->_remark('The stones that can move are the ones the cursor walks.') if $self->raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1227 | 2 | my %from; | |||||||||||||||||||||||||||||||||||||||||
| 1228 | 2 | push @{ $from{ $_->{from} } }, $_ for @steps; | |||||||||||||||||||||||||||||||||||||||||
| 1229 | 2 | for my $name ($drawn->(keys %from)) { | |||||||||||||||||||||||||||||||||||||||||
| 1230 | $self->_say(" $name " . join ' ', map { | ||||||||||||||||||||||||||||||||||||||||||
| 1231 | 10 | ▶ | $_->{string} . (@{ $_->{takes} } ? ' takes ' . scalar @{ $_->{takes} } : '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1232 | 9 | } @{ $from{$name} }); | |||||||||||||||||||||||||||||||||||||||||
| 1233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | $self->_say('A stone that has taken may take again: type the whole move, as d2-e3A-e4W.') | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | 2 | ▶ | if grep { @{ $_->{takes} } } @steps; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1236 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1237 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1238 | 2 | ▶ | hint => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1239 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1240 | 2 | my $thought = Game::Fanorona::Bot->hint($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 1241 | 2 | ▶ | return $self->_remark('The game is over.') unless $thought; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 2 | return $self->_remark('The program would play ' . $self->_paint($thought->{move}, 'key') . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 1243 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | 5 | ▶ | level => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1245 | 5 | my ($self, $rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1246 | 5 | ▶ | return $self->_remark('A level is a number from 1 to ' . scalar(@LEVEL) . '.') unless $rest =~ /\A[1-5]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1247 | 3 | $self->level($rest); | |||||||||||||||||||||||||||||||||||||||||
| 1248 | 3 | return $self->_remark("Level $rest: the program " . $LEVEL[ $rest - 1 ] . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 1249 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | 2 | ▶ | side => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1251 | 2 | my ($self, $rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1252 | 2 | $rest = lc $rest; | |||||||||||||||||||||||||||||||||||||||||
| 1253 | 2 | ▶ | return $self->_remark('A side is white, black, both or neither.') unless $rest =~ /\A(?:white|black|both|neither)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1254 | 1 | $self->human($rest); | |||||||||||||||||||||||||||||||||||||||||
| 1255 | 1 | ▶ | return $self->_remark($rest eq 'both' ? 'Both sides are played here.' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1256 | : $rest eq 'neither' ? 'The program plays both sides.' : 'You play ' . $rest . '.'); | ||||||||||||||||||||||||||||||||||||||||||
| 1257 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | 5 | ▶ | new => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1259 | 5 | my ($self, $rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1260 | 5 | ▶ | if (length $rest) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1261 | 2 | ▶ | return $self->_remark("$rest is not a board. The boards are " . join(', ', Game::Fanorona::Variant->names) . '.') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1262 | unless Game::Fanorona::Variant->from_string($rest); | ||||||||||||||||||||||||||||||||||||||||||
| 1263 | 1 | $self->variant($rest); | |||||||||||||||||||||||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1265 | 4 | $self->swap($self->_fresh_game); | |||||||||||||||||||||||||||||||||||||||||
| 1266 | 4 | $self->history->start($self->game); | |||||||||||||||||||||||||||||||||||||||||
| 1267 | 4 | return $self->_remark('A new game.'); | |||||||||||||||||||||||||||||||||||||||||
| 1268 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | 4 | ▶ | save => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1270 | 4 | my ($self, $rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1271 | 4 | ▶ | return $self->_remark('save takes the name of a file.') unless length $rest; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1272 | 3 | my $text = $self->game->as_text; | |||||||||||||||||||||||||||||||||||||||||
| 1273 | 3 | ▶ | open my $fh, '>', $rest or return $self->_remark("Cannot write $rest: $!."); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1274 | 3 | ▶ | my $saved = (print {$fh} $text) && close $fh; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
print({$fh;} $text) && close $fh
MC/DC0%0/2
print({$fh;} $text) && close $fh
print({$fh;} $text)
close $fh
Truth table33%1/3
A && B
A= print({$fh;} $text)B= close $fh
| |||||||||||||||||||||||||||||||||||||||||||
| 1275 | 3 | ▶ | return $self->_remark($saved ? "Saved to $rest." : "Cannot write $rest: $!."); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1276 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | 5 | ▶ | load => sub { $_[0]->load($_[1]); return }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1278 | 5 | ▶ | draw => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1279 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1280 | 5 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1281 | 5 | my $side = $self->_mine; | |||||||||||||||||||||||||||||||||||||||||
| 1282 | 5 | ▶ | return $self->_remark('There is no game being played here to draw.') unless defined $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1283 | 4 | ▶ | unless ($game->offer_draw($side)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | return $self->_remark(ucfirst($game->error->message) . '.'); | |||||||||||||||||||||||||||||||||||||||||
| 1285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1286 | 4 | ▶ | if ($self->human eq 'both') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1287 | 2 | return $self->_remark(ucfirst($side) . ' offers a draw. accept or decline answers it.'); | |||||||||||||||||||||||||||||||||||||||||
| 1288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1289 | 2 | my $reply = Game::Fanorona::Bot->answer_draw($game); | |||||||||||||||||||||||||||||||||||||||||
| 1290 | 2 | ▶ | if (defined $reply && $reply eq 'accept') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $reply and $reply eq "accept"
MC/DC50%1/2
defined $reply and $reply eq "accept"
defined $reply
$reply eq "accept"
Truth table66%2/3
A and B
A= defined $replyB= $reply eq "accept"
| |||||||||||||||||||||||||||||||||||||||||||
| 1291 | 1 | $game->accept_draw($other->($side)); | |||||||||||||||||||||||||||||||||||||||||
| 1292 | 1 | return $self->_remark('The program accepts.'); | |||||||||||||||||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | 1 | $game->decline_draw($other->($side)); | |||||||||||||||||||||||||||||||||||||||||
| 1295 | 1 | return $self->_remark('The program declines the draw.'); | |||||||||||||||||||||||||||||||||||||||||
| 1296 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | 1 | ▶ | accept => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1298 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1299 | 1 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1300 | 1 | my $offer = $game->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 1301 | 1 | ▶ | return $self->_remark('No draw has been offered.') unless defined $offer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1302 | 1 | $game->accept_draw($other->($offer)); | |||||||||||||||||||||||||||||||||||||||||
| 1303 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1304 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1305 | 1 | ▶ | decline => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1306 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1307 | 1 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||
| 1308 | 1 | my $offer = $game->draw_offered_by; | |||||||||||||||||||||||||||||||||||||||||
| 1309 | 1 | ▶ | return $self->_remark('No draw has been offered.') unless defined $offer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1310 | 1 | $game->decline_draw($other->($offer)); | |||||||||||||||||||||||||||||||||||||||||
| 1311 | 1 | return $self->_remark(ucfirst($other->($offer)) . ' declines the draw.'); | |||||||||||||||||||||||||||||||||||||||||
| 1312 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1313 | 4 | ▶ | resign => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1314 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1315 | 4 | my $side = $self->_mine; | |||||||||||||||||||||||||||||||||||||||||
| 1316 | 4 | ▶ | return $self->_remark('There is no game being played here to resign.') unless defined $side; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1317 | 3 | $self->game->resign($side); | |||||||||||||||||||||||||||||||||||||||||
| 1318 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1319 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | 19 | ); | |||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||
| 1322 | 14 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1323 | 14 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 1324 | fanorona - the board game of Madagascar, in a terminal | ||||||||||||||||||||||||||||||||||||||||||
| 1325 | |||||||||||||||||||||||||||||||||||||||||||
| 1326 | fanorona [options] | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||||||||||||||||
| 1328 | --side WHO white (the default, and White moves first), black, both, or neither | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | --level N how hard the program plays: 1 to 5, 3 by default | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | --variant NAME the board: sivy (nine by five, the default), dimy or telo | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | --load FILE carry on with a saved game | ||||||||||||||||||||||||||||||||||||||||||
| 1332 | --no-colour letters and lines instead of a painted board | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | --no-pick type moves instead of choosing them with the arrow keys | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | --no-unicode letters for the stones, with colour kept | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | --version the version, and stop | ||||||||||||||||||||||||||||||||||||||||||
| 1336 | --help this, and stop | ||||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||
| 1338 | In a terminal, moves are chosen on the board with the arrow keys; press ? for | ||||||||||||||||||||||||||||||||||||||||||
| 1339 | the keys. Anywhere else, type a move as the points the stone stands on, like | ||||||||||||||||||||||||||||||||||||||||||
| 1340 | d2-e3A, or help. | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||
| 1344 | 2 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1345 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | 2 | { name => 'side', type => 'enum', choices => [qw(white black both neither)], help => 'your side; White moves first' }, | |||||||||||||||||||||||||||||||||||||||||
| 1347 | { name => 'level', type => 'int', min => 1, max => 5, help => 'how hard the program plays' }, | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | { name => 'variant', type => 'enum', choices => [qw(sivy dimy telo)], help => 'the board: nine by five, five by five, or three by three' }, | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||
| 1352 | 24 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=17 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1353 | 24 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||
| 1355 | 24 | my %given; | |||||||||||||||||||||||||||||||||||||||||
| 1356 | 24 | my $parsed = Getopt::Long::GetOptionsFromArray( | |||||||||||||||||||||||||||||||||||||||||
| 1357 | \@argv, \%given, | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | 'level=i', 'side=s', 'variant=s', 'load=s', | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | 'colour|color!', 'pick!', 'unicode!', 'version', 'help', | ||||||||||||||||||||||||||||||||||||||||||
| 1360 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||||||||||||||||
| 1362 | 24 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1363 | 3 | ▶ | print STDERR "fanorona: 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1364 | 3 | print STDERR _usage(); | |||||||||||||||||||||||||||||||||||||||||
| 1365 | 3 | return 2; | |||||||||||||||||||||||||||||||||||||||||
| 1366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | 21 | ▶ | if ($given{help}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1368 | 11 | print _usage(); | |||||||||||||||||||||||||||||||||||||||||
| 1369 | 11 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | 10 | ▶ | if ($given{version}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1372 | 1 | print "fanorona $Game::Fanorona::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1373 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1375 | |||||||||||||||||||||||||||||||||||||||||||
| 1376 | 9 | my %with; | |||||||||||||||||||||||||||||||||||||||||
| 1377 | 9 | ▶ | $with{level} = $given{level} if defined $given{level}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1378 | 9 | ▶ | $with{human} = $given{side} if defined $given{side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1379 | 9 | ▶ | $with{variant} = $given{variant} if defined $given{variant}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1380 | 9 | ▶ | $with{colour} = $given{colour} if defined $given{colour}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1381 | 9 | ▶ | $with{picking} = $given{pick} if defined $given{pick}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1382 | 9 | ▶ | $with{unicode} = $given{unicode} if defined $given{unicode}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1383 | 9 | ▶ | $with{menu} = 1 unless grep { defined $given{$_} } qw(side level variant load); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||
| 1385 | 9 | my $terminal = eval { $class->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||
| 1386 | 9 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1387 | 3 | (my $why = $@) =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||
| 1388 | 3 | $why =~ s/\AGame::Fanorona(?:::\w+)*: //; | |||||||||||||||||||||||||||||||||||||||||
| 1389 | 3 | print STDERR "fanorona: $why.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1390 | 3 | return 2; | |||||||||||||||||||||||||||||||||||||||||
| 1391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 6 | ▶ | if (defined $given{load}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1394 | 2 | ▶ | return 2 unless $terminal->load($given{load}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||
| 1397 | 5 | return $terminal->start; | |||||||||||||||||||||||||||||||||||||||||
| 1398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | |||||||||||||||||||||||||||||||||||||||||||
| 1400 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||||||||||||||||
| 1402 | __END__ | ||||||||||||||||||||||||||||||||||||||||||