bin/brandubh

filter: Statementstmt 100% 53 / 53 Branchbran 100% 32 / 32 Conditioncond 91.6% 11 / 12 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 98.2% 109 / 111 CC 1 SCAR 0.0
CC
1
Cov
99%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« bd_engine.c ↑ Summary
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
BranchTrueFalseTotal
if (not $parsed or @ARGV) 3 32 35
Condition100%3/3
not $parsed or @ARGV
l!l&&r!l&&!r
2132
MC/DC100%2/2
not $parsed or @ARGV
not $parsed @ARGV
Truth table100%3/3
not(A) or B
A= not $parsedB= @ARGV
ABresult
1X1
011
000
19 3 ▶ print STDERR "brandubh: I do not know '@ARGV'.\n" if $parsed && @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if $parsed and @ARGV 1 2 3
Condition66%2/3
$parsed and @ARGV
!ll&&!rl&&r
201
MC/DC50%1/2
$parsed and @ARGV
$parsed @ARGV
Truth table66%2/3
A and B
A= $parsedB= @ARGV
ABresult
0X0
100
111
20 3 print STDERR usage();
21 3 exit 2;
22 }
23 32 ▶if ($given{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given{"help"}) 1 31 32
24 1 print usage();
25 1 exit 0;
26 }
27 31 ▶if ($given{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given{"version"}) 1 30 31
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
BranchTrueFalseTotal
if defined $given{"level"} 10 20 30
34 30 ▶$with{human} = $given{side} if defined $given{side};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"side"} 24 6 30
35 30 ▶$with{variant} = $given{variant} if defined $given{variant};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"variant"} 7 23 30
36 30 ▶$with{colour} = $given{colour} if defined $given{colour};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"colour"} 5 25 30
37 30 ▶$with{picking} = $given{pick} if defined $given{pick};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"pick"} 2 28 30
38 30 ▶$with{unicode} = $given{unicode} if defined $given{unicode};
Branch: 1 branch
BranchTrueFalseTotal
if defined $given{"unicode"} 2 28 30
39 30 ▶$with{menu} = 1 unless defined $given{side} || defined $given{level} || defined $given{load};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $given{"side"} or defined $given{"level"} or defined $given{"load"} 4 26 30
Condition100%6/6
defined $given{"side"} or defined $given{"level"} or defined $given{"load"}
l!l&&r!l&&!r
2514
defined $given{"side"} or defined $given{"level"}
l!l&&r!l&&!r
2415
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"}
ABCresult
1XX1
01X1
0011
0000
40  
41 30 ▶if (defined $given{seed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $given{"seed"}) 6 24 30
42 6 ▶ if ($given{seed} !~ /\A[0-9a-fA-F]{64}\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($given{"seed"} =~ /\A[0-9a-fA-F]{64}\z/) 2 4 6
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
BranchTrueFalseTotal
unless ($terminal) 3 25 28
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
BranchTrueFalseTotal
if (defined $given{"load"}) 2 23 25
58 2 ▶ exit 2 unless $terminal->load($given{load});
Branch: 1 branch
BranchTrueFalseTotal
unless $terminal->load($given{"load"}) 1 1 2
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__
« bd_engine.c ↑ Summary