blib/lib/Game/Schnapsen/Bot.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 76.9% 20 / 26 Conditioncond 80.0% 8 / 10 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 91.1% 113 / 124 CC 19 SCAR 23.0
CC
19
Cov
91%
choose
16.3
_public
3.0
seed_for
2.1
CRAP 10.0
« blib/lib/Game/Schnapsen/Scoring.pm ↑ Summary blib/lib/Game/Schnapsen/Deal.pm »
1 package Game::Schnapsen::Bot;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use Game::Schnapsen::Scoring qw(TARGET_POINTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Game::Schnapsen::Search qw(best_lead best_follow best_marriage
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 should_close should_claim LEVELS);
12  
13 9 our $VERSION = '0.02';
14  
15 9 our @LADDER = (1, 1, 2, 2, 2);
16  
17 9 has level => (is => 'ro', isa => Int);
18 9 has seed => (is => 'ro', isa => Str);
19  
20 45 ▶sub levels { return LEVELS }
Subroutine levels: called CC=1 SCAR=0.0
Pod documented
21  
22 6 ▶sub seed_for {
Subroutine seed_for: called CC=2 SCAR=7.2
Pod documented
23 6 my ($self, $seat, $ply) = @_;
24 6 ▶ return Digest::SHA::sha256_hex(($self->seed // '') . ":$seat:$ply");
Condition50%1/2
$self->seed // ""
l!l
60
MC/DC0%0/1
$self->seed // ""
$self->seed
Truth table50%1/2
A
A= $self->seed
Aresult
11
00
25 }
26  
27 61893 ▶sub _public {
Subroutine _public: called CC=3 SCAR=11.0
28 61893 my ($self, $game, $seat) = @_;
29 61893 my $deal = $game->deal;
30 61893 ▶ my $them = $seat eq 'p1' ? 'p2' : 'p1';
Branch: 1 branch
BranchTrueFalseTotal
$seat eq 'p1' ? : 30988 30905 61893
31  
32 return (
33 61893 ▶ level => $self->level || 1,
Condition50%1/2
$self->level || 1
l!l
618930
MC/DC0%0/1
$self->level || 1
$self->level
Truth table50%1/2
A
A= $self->level
Aresult
11
00
34 trump => $deal->trump,
35 phase => $deal->phase,
36 talon_left => $deal->talon_left,
37 closed => $deal->closed,
38 turn_up => $deal->turn_up,
39 my_points => $deal->points_of($seat),
40 their_points => $deal->points_of($them),
41 their_tricks => $deal->tricks_won($them),
42 target => TARGET_POINTS,
43 );
44 }
45  
46 61893 ▶sub choose {
Subroutine choose: called CC=16 SCAR=27.9
Pod documented
47 61893 my ($self, $game, $seat) = @_;
48 61893 ▶ return undef if $game->over;
Branch: 1 branch
BranchTrueFalseTotal
if $game->over 0 61893 61893
49  
50 61893 my $legal = $game->legal($seat);
51 61893 ▶ return undef unless @$legal;
Branch: 1 branch
BranchTrueFalseTotal
unless @$legal 0 61893 61893
52  
53 61893 my $deal = $game->deal;
54 61893 my %o = $self->_public($game, $seat);
55 61893 my %by;
56 61893 push @{ $by{ $_->{kind} } }, $_ for @$legal;
57  
58 61893 ▶ if ($by{exchange}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"exchange"}) 1689 60204 61893
59 1689 return $by{exchange}[0];
60 }
61  
62 60204 ▶ if ($by{marriage}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"marriage"}) 2858 57346 60204
63 2858 my $suit = best_marriage(%o, marriages => $by{marriage});
64 2858 my ($pick) = grep { $_->{suit} eq $suit } @{ $by{marriage} };
65 2858 ▶ return $pick if $pick;
Branch: 1 branch
BranchTrueFalseTotal
if $pick 2858 0 2858
66 }
67  
68 57346 ▶ if ($by{claim} && should_claim(%o)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"claim"} and should_claim(%o)) 2423 54923 57346
Condition100%3/3
$by{"claim"} and should_claim(%o)
!ll&&!rl&&r
25689292342423
MC/DC100%2/2
$by{"claim"} and should_claim(%o)
$by{"claim"} should_claim(%o)
Truth table100%3/3
A and B
A= $by{"claim"}B= should_claim(%o)
ABresult
0X0
100
111
69 2423 return $by{claim}[0];
70 }
71  
72 54923 ▶ if ($by{close}
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"close"} and should_close(%o, "cards", $deal->hand_of($seat)->cards)) 972 53951 54923
Condition100%3/3
$by{"close"} and should_close(%o, "cards", $deal->hand_of($seat)->cards)
!ll&&!rl&&r
3305820893972
MC/DC100%2/2
$by{"close"} and should_close(%o, "cards", $deal->hand_of($seat)->cards)
$by{"close"} should_close(%o, "cards", $deal->hand_of($seat)->cards)
Truth table100%3/3
A and B
A= $by{"close"}B= should_close(%o, "cards", $deal->hand_of($seat)->cards)
ABresult
0X0
100
111
73 && should_close(%o, cards => $deal->hand_of($seat)->cards)) {
74 972 return $by{close}[0];
75 }
76  
77 53951 ▶ if ($by{lead}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"lead"}) 23379 30572 53951
78 23379 my $card = best_lead(%o, cards => [ map { $_->{card} } @{ $by{lead} } ]);
79 23379 my ($pick) = grep { $_->{card} == $card } @{ $by{lead} };
80 23379 ▶ return $pick if $pick;
Branch: 1 branch
BranchTrueFalseTotal
if $pick 23379 0 23379
81 }
82  
83 30572 ▶ if ($by{follow}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"follow"}) 23377 7195 30572
84 my $card = best_follow(%o, led => $deal->lead,
85 23377 cards => [ map { $_->{card} } @{ $by{follow} } ]);
86 23377 my ($pick) = grep { $_->{card} == $card } @{ $by{follow} };
87 23377 ▶ return $pick if $pick;
Branch: 1 branch
BranchTrueFalseTotal
if $pick 23377 0 23377
88 }
89  
90 7195 ▶ return $by{draw}[0] if $by{draw};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"draw"} 7195 0 7195
91 0 return $legal->[0];
92 }
93  
94 9 1;
95  
96 __END__
« blib/lib/Game/Schnapsen/Scoring.pm ↑ Summary blib/lib/Game/Schnapsen/Deal.pm »