| 1 | #!perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Game::Brandubh; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use Game::Brandubh::Terminal; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 35 | my %given; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 35 | my $parsed = Getopt::Long::GetOptionsFromArray( | |||||||||||||||||||||||||||||||||||||||||
| 13 | \@ARGV, \%given, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 'level=i', 'side=s', 'seed=s', 'variant=s', 'load=s', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 'colour|color!', 'pick!', 'unicode!', 'version', 'help', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 35 | ▶ | 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 | 3 | ▶ | print STDERR "brandubh: 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 | 3 | print STDERR usage(); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | exit 2; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 32 | ▶ | if ($given{help}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | print usage(); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 31 | ▶ | if ($given{version}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | print "brandubh $Game::Brandubh::VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 30 | my %with; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 30 | ▶ | $with{level} = $given{level} if defined $given{level}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 30 | ▶ | $with{human} = $given{side} if defined $given{side}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 30 | ▶ | $with{variant} = $given{variant} if defined $given{variant}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 30 | ▶ | $with{colour} = $given{colour} if defined $given{colour}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 30 | ▶ | $with{picking} = $given{pick} if defined $given{pick}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 30 | ▶ | $with{unicode} = $given{unicode} if defined $given{unicode}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 30 | ▶ | $with{menu} = 1 unless defined $given{side} || defined $given{level} || defined $given{load}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $given{"side"} or defined $given{"level"} or defined $given{"load"}
defined $given{"side"} or defined $given{"level"}
MC/DC100%3/3
defined $given{"side"} or defined $given{"level"} or defined $given{"load"}
defined $given{"side"}
defined $given{"level"}
defined $given{"load"}
Truth table100%4/4
A or B or C
A= defined $given{"side"}B= defined $given{"level"}C= defined $given{"load"}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 30 | ▶ | if (defined $given{seed}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | if ($given{seed} !~ /\A[0-9a-fA-F]{64}\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | print STDERR "brandubh: a seed is sixty-four hexadecimal characters.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | exit 2; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | $with{seed} = pack 'H*', $given{seed}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 28 | my $terminal = eval { Game::Brandubh::Terminal->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 28 | ▶ | if (!$terminal) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | (my $why = $@) =~ s/ at \S+ line \d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | $why =~ s/\AGame::Brandubh(?:::\w+)*: //; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | print STDERR "brandubh: $why.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | exit 2; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 25 | ▶ | if (defined $given{load}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | exit 2 unless $terminal->load($given{load}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 24 | exit $terminal->start; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 65 | brandubh - the Irish tafl game, in a terminal | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | brandubh [options] | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | --side WHO attackers (the default), defenders, both, or none | ||||||||||||||||||||||||||||||||||||||||||
| 70 | --level N how hard the program plays: 1, 2 (the default) or 3 | ||||||||||||||||||||||||||||||||||||||||||
| 71 | --variant TEXT the rule set, for example 'custom repeat=2' | ||||||||||||||||||||||||||||||||||||||||||
| 72 | --seed HEX sixty-four hexadecimal characters; the same seed plays the same game | ||||||||||||||||||||||||||||||||||||||||||
| 73 | --load FILE carry on with a saved game | ||||||||||||||||||||||||||||||||||||||||||
| 74 | --no-colour letters and lines instead of a painted board | ||||||||||||||||||||||||||||||||||||||||||
| 75 | --no-pick type moves instead of choosing them with the arrow keys | ||||||||||||||||||||||||||||||||||||||||||
| 76 | --no-unicode letters for the pieces, with colour kept | ||||||||||||||||||||||||||||||||||||||||||
| 77 | --version the version, and stop | ||||||||||||||||||||||||||||||||||||||||||
| 78 | --help this, and stop | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | In a terminal, moves are chosen on the board with the arrow keys; press ? for | ||||||||||||||||||||||||||||||||||||||||||
| 81 | the keys. Anywhere else, type a move as two squares, like d1d3, or help. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||||||||||||