| 1 | package Game::Floppy::Bot; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 9 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 9 | our @LADDER = (1, 2, 3); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | our $NEAR = 120; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 9 | 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
| |||||||||||||||||||||||||||||
| 33 | Carp::croak("Game::Floppy::Bot: a level is one of @LADDER, not '$level'") | ||||||||||||||||||||||||||||
| 34 | 477687 | ▶ | unless !ref $level && $DESCRIBE{$level}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $level and $DESCRIBE{$level}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 228321 | ▶ | return $middle if $level == 1 && $tube->{x} - $game->bird_x > $NEAR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$level == 1 and $tube->{"x"} - $game->bird_x > $Game::Floppy::Bot::NEAR
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 49 | 207041 | my $floor = $game->height - $game->gravity - 1; | |||||||||||||||||||||||||||
| 50 | 207041 | ▶ | return $target > $floor ? $floor : $target; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 238811 | ▶ | return $game->bird->{y} > $class->target($game, $level) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 9 | 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||