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 7 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Game::Xiangqi::Engine ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Game::Xiangqi::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 our $VERSION = '0.04';
12  
13 7 my $N = 'Game::Xiangqi::Notation';
14  
15 7 our @LADDER = (400, 6_000, 6_000, 60_000);
16  
17 7 our $LEVEL;
18  
19 63 ▶sub level_for {
Subroutine level_for: called CC=2 SCAR=9.2
Pod documented
20 63 my ($class, $seed) = @_;
21 63 ▶ return $LEVEL if defined $LEVEL;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Game::Xiangqi::Bot::LEVEL 63 0 63
22 0 my $n = unpack 'N', Digest::SHA::sha256("xiangqi-level:$seed");
23 0 return $LADDER[ $n % scalar @LADDER ];
24 }
25  
26 67 ▶sub tiebreak_seed {
Subroutine tiebreak_seed: called CC=1 SCAR=0.0
Pod documented
27 67 my ($class, $seed, $seat) = @_;
28 67 return unpack 'N', Digest::SHA::sha256("xiangqi-bot:$seed:$seat");
29 }
30  
31 63 ▶sub choose {
Subroutine choose: called CC=5 SCAR=17.3
Pod documented
32 63 my ($class, $game, $seat) = @_;
33 63 ▶ return undef unless $game->status eq 'active';
Branch: 1 branch
BranchTrueFalseTotal
unless $game->status eq "active" 0 63 63
34 63 ▶ return undef unless defined $game->turn && $game->turn eq $seat;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $game->turn and $game->turn eq $seat 0 63 63
Condition33%1/3
defined $game->turn and $game->turn eq $seat
!ll&&!rl&&r
0063
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 63 my $budget = $class->level_for($game->_held_seed);
37 63 my $tie = $class->tiebreak_seed($game->_held_seed, $seat);
38  
39 63 my ($mv, $nodes, $depth, $score, $stopped) =
40 $game->position->search($budget, $tie);
41 63 ▶ return undef unless $mv;
Branch: 1 branch
BranchTrueFalseTotal
unless $mv 0 63 63
42 63 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 7 1;
52  
53 __END__
« blib/lib/Game/Xiangqi/Notation.pm ↑ Summary blib/lib/Game/Xiangqi/Engine.pm »