bin/durak

filter: Statementstmt 71.1% 32 / 45 Branchbran 40.0% 8 / 20 Conditioncond 41.6% 5 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 58.2% 53 / 91 CC 2 SCAR 8.0
CC
2
Cov
58%
usage
6.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.2
« blib/lib/Game/Durak/Bot.pm ↑ Summary blib/lib/Game/Durak/Result.pm »
1 #!/usr/bin/env perl
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Game::Durak::Bot;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Game::Durak::Terminal;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 my %opt = (level => 3, seat => 1);
12 4 ▶GetOptions(\%opt, 'level=i', 'seat=i', 'seed=s', 'ascii', 'colour!',
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%opt, "level=i", "seat=i", "seed=s", "ascii", "colour!", "paint!", "pick!", "width=i", "height=i", "help") or usage(2) 4 0 4
13 'paint!', 'pick!', 'width=i', 'height=i', 'help')
14 or usage(2);
15  
16 4 ▶usage(0) if $opt{help};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"help"} 0 4 4
17  
18 4 my $levels = Game::Durak::Bot->ladder;
19 bad("--seat must be 1 or 2, not '$opt{seat}'")
20 4 ▶ unless $opt{seat} =~ /\A[12]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"seat"} =~ /\A[12]\z/ 0 4 4
21 bad("--level must be 1 to $levels, not '$opt{level}'")
22 unless $opt{level} =~ /\A[0-9]+\z/
23 4 ▶ && $opt{level} >= 1 && $opt{level} <= $levels;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"level"} =~ /\A[0-9]+\z/ and $opt{"level"} >= 1 and $opt{"level"} <= $levels 2 2 4
Condition83%5/6
$opt{"level"} =~ /\A[0-9]+\z/ and $opt{"level"} >= 1 and $opt{"level"} <= $levels
!ll&&!rl&&r
112
$opt{"level"} =~ /\A[0-9]+\z/ and $opt{"level"} >= 1
!ll&&!rl&&r
013
MC/DC66%2/3
$opt{"level"} =~ /\A[0-9]+\z/ and $opt{"level"} >= 1 and $opt{"level"} <= $levels
$opt{"level"} =~ /\A[0-9]+\z/ $opt{"level"} >= 1 $opt{"level"} <= $levels
Truth table75%3/4
A and B and C
A= $opt{"level"} =~ /\A[0-9]+\z/B= $opt{"level"} >= 1C= $opt{"level"} <= $levels
ABCresult
0XX0
10X0
1100
1111
24  
25 2 ▶sub bad {
Subroutine bad: called CC=1 SCAR=0.0
26 2 my ($why) = @_;
27 2 print {\*STDERR} "durak: $why\n";
28 2 exit 2;
29 }
30  
31 0 ▶sub usage {
Subroutine usage: not called CC=2 SCAR=17.9
32 0 my ($status) = @_;
33 0 ▶ my $fh = $status ? \*STDERR : \*STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 0 0 0
34 0 print {$fh} <<"USAGE";
35 usage: $0 [--level 1-5] [--seat 1|2] [--seed STRING] [--ascii] [--no-colour]
36 [--no-paint] [--width N] [--height N]
37  
38 A deal of Podkidnoy Durak against the bot. You are the seat given by --seat
39 and the bot plays the other one. The seed decides the deal, and the same seed
40 deals the same cards every time.
41  
42 The table is drawn on one painted screen at a terminal and printed as plain
43 lines when the output is a pipe or a file. --paint and --no-paint say so
44 either way, and --width and --height fit the screen to a window that is not
45 eighty by twenty-four.
46  
47 At a terminal the arrow keys walk the cards you may play and the line above
48 the table says what the one under the cursor would do: whether they must beat
49 it, which attack it beats, whether it is a trump, and how much room the bout
50 has left. Enter plays it. The moves that are not cards keep their own keys.
51 Needs Term::ReadKey; --no-pick, or no terminal, numbers them at a prompt
52 instead.
53  
54 At the prompt, a number plays that card. t takes, d is done, x exchanges the
55 trump, r resigns and q (or quit) stops.
56  
57 Exit status is 0 if you won or the deal was stopped, 1 if you were the fool,
58 2 for an option the game will not take.
59 USAGE
60 0 exit $status;
61 }
62  
63 my $said = defined $opt{seed} ? $opt{seed}
64 2 ▶ : join q{}, map { chr 97 + int rand 26 } 1 .. 32;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'seed'} ? : 2 0 2
65 2 my $seed = sprintf q{%-32.32s}, $said;
66  
67 my $terminal = Game::Durak::Terminal->new(
68 seed => $seed,
69 level => $opt{level},
70 seat => $opt{seat},
71 ascii => $opt{ascii},
72 colour => $opt{colour},
73 paint => $opt{paint},
74 width => $opt{width},
75 height => $opt{height},
76 2 ▶ (defined $opt{pick} ? (picking => $opt{pick} ? 1 : 0) : ()),
Branch: 2 branches
BranchTrueFalseTotal
defined $opt{'pick'} ? : 0 2 2
$opt{'pick'} ? : 0 0 0
77 );
78  
79 2 for my $signal (qw/ INT TERM HUP /) {
80 0 ▶ $SIG{$signal} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 $terminal->leave_raw;
82 0 $SIG{ $_[0] } = 'DEFAULT';
83 0 kill $_[0], $$;
84 6 };
85 }
86  
87 2 my $result = $terminal->run;
88 2 ▶exit 0 unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 2 0 2
89  
90 0 $terminal->say('');
91 0 $terminal->say("the seed was $said");
92  
93 exit 1 if ref $result eq 'HASH'
94 0 ▶ && defined $result->{fool} && $result->{fool} == $opt{seat};
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "HASH" and defined $result->{"fool"} and $result->{"fool"} == $opt{"seat"} 0 0 0
Condition0%0/6
ref $result eq "HASH" and defined $result->{"fool"} and $result->{"fool"} == $opt{"seat"}
!ll&&!rl&&r
000
ref $result eq "HASH" and defined $result->{"fool"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $result eq "HASH" and defined $result->{"fool"} and $result->{"fool"} == $opt{"seat"}
ref $result eq "HASH" defined $result->{"fool"} $result->{"fool"} == $opt{"seat"}
Truth table0%0/4
A and B and C
A= ref $result eq "HASH"B= defined $result->{"fool"}C= $result->{"fool"} == $opt{"seat"}
ABCresult
0XX0
10X0
1100
1111
95 0 exit 0;
96  
97 __END__
« blib/lib/Game/Durak/Bot.pm ↑ Summary blib/lib/Game/Durak/Result.pm »