blib/lib/Game/Floppy/Bot.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 16 / 16 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 97.4% 76 / 78 CC 11 SCAR 12.2
CC
11
Cov
98%
target
6.0
_level
4.0
choose
3.0
CRAP 3.4
« blib/lib/Game/Floppy/Result.pm ↑ Summary blib/lib/Game/Floppy/Error.pm »
1 package Game::Floppy::Bot;
2  
3 8 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 our $VERSION = '0.09';
10  
11 8 our @LADDER = (1, 2, 3);
12  
13 8 our $NEAR = 120;
14  
15 8 my %DESCRIBE = (
16 1 => 'short-sighted: a tube counts only once it is near; until then it holds the middle',
17 2 => 'far-sighted: it aims at the next gap from the moment the tube appears',
18 3 => 'sits low: far-sighted, and it waits at the bottom of each gap, since rising is fast and falling slow',
19 );
20  
21 1 ▶sub levels { return @LADDER }
Subroutine levels: called CC=1 SCAR=0.0
Pod documented
22  
23 1 ▶sub near { return $NEAR }
Subroutine near: called CC=1 SCAR=0.0
Pod documented
24  
25 52 ▶sub describe {
Subroutine describe: called CC=1 SCAR=0.0
Pod documented
26 52 my ($class, $level) = @_;
27 52 return $DESCRIBE{ $class->_level($level) };
28 }
29  
30 477687 ▶sub _level {
Subroutine _level: called CC=4 SCAR=13.9
31 477687 my ($class, $level) = @_;
32 477687 ▶ $level = $LADDER[-1] unless defined $level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $level 2 477685 477687
33 Carp::croak("Game::Floppy::Bot: a level is one of @LADDER, not '$level'")
34 477687 ▶ unless !ref $level && $DESCRIBE{$level};
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $level and $DESCRIBE{$level} 5 477682 477687
Condition66%2/3
not ref $level and $DESCRIBE{$level}
!ll&&!rl&&r
05477682
MC/DC50%1/2
not ref $level and $DESCRIBE{$level}
not ref $level $DESCRIBE{$level}
Truth table66%2/3
not(A) and B
A= not ref $levelB= $DESCRIBE{$level}
ABresult
0X0
100
111
35 477682 return $level;
36 }
37  
38 238822 ▶sub target {
Subroutine target: called CC=6 SCAR=17.9
Pod documented
39 238822 my ($class, $game, $level) = @_;
40 238822 $level = $class->_level($level);
41  
42 238822 my $middle = $game->height / 2;
43 238822 my $tube = $game->tubes->[0];
44 238822 ▶ return $middle unless $tube;
Branch: 1 branch
BranchTrueFalseTotal
unless $tube 10501 228321 238822
45 228321 ▶ return $middle if $level == 1 && $tube->{x} - $game->bird_x > $NEAR;
Branch: 1 branch
BranchTrueFalseTotal
if $level == 1 and $tube->{"x"} - $game->bird_x > $Game::Floppy::Bot::NEAR 21280 207041 228321
Condition100%3/3
$level == 1 and $tube->{"x"} - $game->bird_x > $Game::Floppy::Bot::NEAR
!ll&&!rl&&r
1827032433821280
MC/DC100%2/2
$level == 1 and $tube->{"x"} - $game->bird_x > $Game::Floppy::Bot::NEAR
$level == 1 $tube->{"x"} - $game->bird_x > $Game::Floppy::Bot::NEAR
Truth table100%3/3
A and B
A= $level == 1B= $tube->{"x"} - $game->bird_x > $Game::Floppy::Bot::NEAR
ABresult
0X0
100
111
46 my $target = $level == 3
47 ? $tube->{gap_bottom} - $game->bird_radius - 9
48 207041 ▶ : ($tube->{gap_top} + $tube->{gap_bottom}) / 2;
Branch: 1 branch
BranchTrueFalseTotal
$level == 3 ? : 95742 111299 207041
49 207041 my $floor = $game->height - $game->gravity - 1;
50 207041 ▶ return $target > $floor ? $floor : $target;
Branch: 1 branch
BranchTrueFalseTotal
$target > $floor ? : 3063 203978 207041
51 }
52  
53 238813 ▶sub choose {
Subroutine choose: called CC=3 SCAR=11.0
Pod documented
54 238813 my ($class, $game, %with) = @_;
55 238813 my $level = $class->_level($with{level});
56  
57 238812 ▶ return undef if $game->status eq 'finished';
Branch: 1 branch
BranchTrueFalseTotal
if $game->status eq "finished" 1 238811 238812
58  
59 238811 ▶ return $game->bird->{y} > $class->target($game, $level) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$game->bird->{'y'} > $class->target($game, $level) ? : 23623 215188 238811
60 }
61  
62 8 1;
63  
64 __END__
« blib/lib/Game/Floppy/Result.pm ↑ Summary blib/lib/Game/Floppy/Error.pm »