blib/lib/Game/Shogi/Bot.pm

filter: Statementstmt 100% 34 / 34 Branchbran 80.0% 8 / 10 Conditioncond 48.1% 13 / 27 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 72.0% 72 / 100 CC 16 SCAR 17.2
CC
16
Cov
77%
declares
9.0
choose
8.8
tiebreak_seed
3.0
CRAP 5.6
« blib/lib/Game/Shogi/Result.pm ↑ Summary blib/lib/Game/Shogi/Error.pm »
1 package Game::Shogi::Bot;
2  
3 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Game::Shogi::Engine ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 our $VERSION = '0.01';
11  
12 5 our @LADDER = (400, 6_000, 60_000, 300_000);
13  
14 5 our $LEVEL;
15  
16 211 ▶sub level_for {
Subroutine level_for: called CC=3 SCAR=11.0
Pod documented
17 211 my ($class, $seed) = @_;
18 211 ▶ return $LEVEL if defined $LEVEL;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Game::Shogi::Bot::LEVEL 9 202 211
19 202 ▶ my $n = unpack 'N', Digest::SHA::sha256('shogi-level:' . ($seed // ''));
Condition50%1/2
$seed // ""
l!l
2020
MC/DC0%0/1
$seed // ""
$seed
Truth table50%1/2
A
A= $seed
Aresult
11
00
20 202 return $LADDER[ $n % scalar @LADDER ];
21 }
22  
23 94 ▶sub tiebreak_seed {
Subroutine tiebreak_seed: called CC=3 SCAR=11.1
Pod documented
24 94 my ($class, $seed, $side) = @_;
25 94 ▶ return unpack 'N', Digest::SHA::sha256('shogi-bot:' . ($seed // '') . ':' . ($side // ''));
Condition75%3/4
$seed // ""
l!l
904
$side // ""
l!l
940
MC/DC100%1/1
$seed // ""
$seed
MC/DC0%0/1
$side // ""
$side
Truth table100%2/2
A
A= $seed
Aresult
11
00
Truth table50%1/2
A
A= $side
Aresult
11
00
26 }
27  
28 53 ▶sub choose {
Subroutine choose: called CC=7 SCAR=21.8
Pod documented
29 53 my ($class, $game, $side, %opt) = @_;
30 53 ▶ return undef unless defined $game && $game->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $game and $game->status eq "active" 0 53 53
Condition33%1/3
defined $game and $game->status eq "active"
!ll&&!rl&&r
0053
MC/DC0%0/2
defined $game and $game->status eq "active"
defined $game $game->status eq "active"
Truth table33%1/3
A and B
A= defined $gameB= $game->status eq "active"
ABresult
0X0
100
111
31 53 ▶ return undef unless defined $side && defined $game->turn && $game->turn eq $side;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $side and defined $game->turn and $game->turn eq $side 1 52 53
Condition50%3/6
defined $side and defined $game->turn and $game->turn eq $side
!ll&&!rl&&r
0152
defined $side and defined $game->turn
!ll&&!rl&&r
0053
MC/DC33%1/3
defined $side and defined $game->turn and $game->turn eq $side
defined $side defined $game->turn $game->turn eq $side
Truth table50%2/4
A and B and C
A= defined $sideB= defined $game->turnC= $game->turn eq $side
ABCresult
0XX0
10X0
1100
1111
32 52 ▶ my $budget = $opt{nodes} // $class->level_for($opt{seed});
Condition66%2/3
$opt{"nodes"} // $class->level_for($opt{"seed"})
l!l&&r!l&&!r
4480
MC/DC0%0/2
$opt{"nodes"} // $class->level_for($opt{"seed"})
$opt{"nodes"} $class->level_for($opt{"seed"})
Truth table66%2/3
A // B
A= $opt{"nodes"}B= $class->level_for($opt{"seed"})
ABresult
1X1
011
000
33 return scalar $game->board->search(
34 nodes => $budget,
35 52 seed => $class->tiebreak_seed($opt{seed}, $side),
36 history => [ $game->history ],
37 );
38 }
39  
40 11 ▶sub declares {
Subroutine declares: called CC=6 SCAR=22.0
Pod documented
41 11 my ($class, $game, $side) = @_;
42 11 ▶ return 0 unless defined $game && defined $side && defined $game->turn && $game->turn eq $side;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $game and defined $side and defined $game->turn and $game->turn eq $side 0 11 11
Condition33%3/9
defined $game and defined $side and defined $game->turn and $game->turn eq $side
!ll&&!rl&&r
0011
defined $game and defined $side and defined $game->turn
!ll&&!rl&&r
0011
defined $game and defined $side
!ll&&!rl&&r
0011
MC/DC0%0/4
defined $game and defined $side and defined $game->turn and $game->turn eq $side
defined $game defined $side defined $game->turn $game->turn eq $side
Truth table20%1/5
A and B and C and D
A= defined $gameB= defined $sideC= defined $game->turnD= $game->turn eq $side
ABCDresult
0XXX0
10XX0
110X0
11100
11111
43 11 ▶ return $game->can_declare ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$game->can_declare ? : 1 10 11
44 }
45  
46 3 ▶sub hint {
Subroutine hint: called CC=1 SCAR=0.0
Pod documented
47 3 my ($class, $game, $side, %opt) = @_;
48 3 return $class->choose($game, $side, %opt, nodes => $LADDER[-1]);
49 }
50  
51 5 1;
52  
53 __END__
« blib/lib/Game/Shogi/Result.pm ↑ Summary blib/lib/Game/Shogi/Error.pm »