| 1 | #!perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Game::Fanorona; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Game::Fanorona::Terminal; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 13 | my %given; | |||||||||||||||||||||||||||
| 12 | 13 | my $parsed = Getopt::Long::GetOptionsFromArray( | |||||||||||||||||||||||||||
| 13 | \@ARGV, \%given, | ||||||||||||||||||||||||||||
| 14 | 'level=i', 'side=s', 'variant=s', 'load=s', | ||||||||||||||||||||||||||||
| 15 | 'colour|color!', 'pick!', 'unicode!', 'version', 'help', | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 13 | ▶ | 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
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | 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
| |||||||||||||||||||||||||||||
| 20 | 2 | print STDERR usage(); | |||||||||||||||||||||||||||
| 21 | 2 | exit 2; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 11 | ▶ | if ($given{help}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 1 | print usage(); | |||||||||||||||||||||||||||
| 25 | 1 | exit 0; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 10 | ▶ | if ($given{version}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 1 | print "fanorona $Game::Fanorona::VERSION\n"; | |||||||||||||||||||||||||||
| 29 | 1 | exit 0; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 9 | my %with; | |||||||||||||||||||||||||||
| 33 | 9 | ▶ | $with{level} = $given{level} if defined $given{level}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 9 | ▶ | $with{human} = $given{side} if defined $given{side}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 9 | ▶ | $with{variant} = $given{variant} if defined $given{variant}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 9 | ▶ | $with{colour} = $given{colour} if defined $given{colour}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 9 | ▶ | $with{picking} = $given{pick} if defined $given{pick}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 9 | ▶ | $with{unicode} = $given{unicode} if defined $given{unicode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 9 | ▶ | $with{menu} = 1 unless grep { defined $given{$_} } qw(side level variant load); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 9 | my $terminal = eval { Game::Fanorona::Terminal->new(%with) }; | |||||||||||||||||||||||||||
| 42 | 9 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 3 | (my $why = $@) =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||
| 44 | 3 | $why =~ s/\AGame::Fanorona(?:::\w+)*: //; | |||||||||||||||||||||||||||
| 45 | 3 | print STDERR "fanorona: $why.\n"; | |||||||||||||||||||||||||||
| 46 | 3 | exit 2; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | if (defined $given{load}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | exit 2 unless $terminal->load($given{load}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | exit $terminal->start; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | sub usage { | ||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 3 | return <<'USAGE'; | |||||||||||||||||||||||||||
| 57 | fanorona - the board game of Madagascar, in a terminal | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | fanorona [options] | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | --side WHO white (the default, and White moves first), black, both, or neither | ||||||||||||||||||||||||||||
| 62 | --level N how hard the program plays: 1 to 5, 3 by default | ||||||||||||||||||||||||||||
| 63 | --variant NAME the board: sivy (nine by five, the default), dimy or telo | ||||||||||||||||||||||||||||
| 64 | --load FILE carry on with a saved game | ||||||||||||||||||||||||||||
| 65 | --no-colour letters and lines instead of a painted board | ||||||||||||||||||||||||||||
| 66 | --no-pick type moves instead of choosing them with the arrow keys | ||||||||||||||||||||||||||||
| 67 | --no-unicode letters for the stones, with colour kept | ||||||||||||||||||||||||||||
| 68 | --version the version, and stop | ||||||||||||||||||||||||||||
| 69 | --help this, and stop | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | In a terminal, moves are chosen on the board with the arrow keys; press ? for | ||||||||||||||||||||||||||||
| 72 | the keys. Anywhere else, type a move as the points the stone stands on, like | ||||||||||||||||||||||||||||
| 73 | d2-e3A, or help. | ||||||||||||||||||||||||||||
| 74 | USAGE | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||