blib/lib/Game/Xiangqi/Bot.pm

filter: Statementstmt 87.1% 34 / 39 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 78.7% 52 / 66 CC 6 SCAR 10.3
CC
6
Cov
78%
choose
5.6
level_for
2.5
hint
2.0
CRAP 2.8
« blib/lib/Game/Xiangqi/Notation.pm ↑ Summary blib/lib/Game/Xiangqi/Engine.pm »
1 package Game::Xiangqi::Bot;
2  
3 11 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Game::Xiangqi::Engine ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Game::Xiangqi::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 our $VERSION = '0.05';
12  
13 11 my $N = 'Game::Xiangqi::Notation';
14  
15 11 our @LADDER = (400, 6_000, 6_000, 60_000);
16  
17 11 our $LEVEL;
18  
19 152 ▶sub level_for {
Subroutine level_for: called CC=2 SCAR=9.2
Pod documented
20 152 my ($class, $seed) = @_;
21 152 ▶ return $LEVEL if defined $LEVEL;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Game::Xiangqi::Bot::LEVEL 152 0 152
22 0 my $n = unpack 'N', Digest::SHA::sha256("xiangqi-level:$seed");
23 0 return $LADDER[ $n % scalar @LADDER ];
24 }
25  
26 156 ▶sub tiebreak_seed {
Subroutine tiebreak_seed: called CC=1 SCAR=0.0
Pod documented
27 156 my ($class, $seed, $seat) = @_;
28 156 return unpack 'N', Digest::SHA::sha256("xiangqi-bot:$seed:$seat");
29 }
30  
31 152 ▶sub choose {
Subroutine choose: called CC=5 SCAR=17.3
Pod documented
32 152 my ($class, $game, $seat) = @_;
33 152 ▶ return undef unless $game->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
unless $game->status eq "active" 0 152 152
34 152 ▶ return undef unless defined $game->turn && $game->turn eq $seat;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $game->turn and $game->turn eq $seat 0 152 152
Condition33%1/3
defined $game->turn and $game->turn eq $seat
!ll&&!rl&&r
00152
MC/DC0%0/2
defined $game->turn and $game->turn eq $seat
defined $game->turn $game->turn eq $seat
Truth table33%1/3
A and B
A= defined $game->turnB= $game->turn eq $seat
ABresult
0X0
100
111
35  
36 152 my $budget = $class->level_for($game->_held_seed);
37 152 my $tie = $class->tiebreak_seed($game->_held_seed, $seat);
38  
39 152 my ($mv, $nodes, $depth, $score, $stopped) =
40 $game->position->search($budget, $tie);
41 152 ▶ return undef unless $mv;
Branch: 1 branch
BranchTrueFalseTotal
unless $mv 0 152 152
42 152 return $N->iccs_of($mv);
43 }
44  
45 0 ▶sub hint {
Subroutine hint: not called CC=1 SCAR=6.9
Pod documented
46 0 my ($class, $game, $seat) = @_;
47 0 local $LEVEL = $LADDER[-1];
48 0 return $class->choose($game, $seat);
49 }
50  
51 11 1;
52  
53 __END__
« blib/lib/Game/Xiangqi/Notation.pm ↑ Summary blib/lib/Game/Xiangqi/Engine.pm »