| 1 | package Game::Schnapsen::Bot; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Game::Schnapsen::Scoring qw(TARGET_POINTS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Game::Schnapsen::Search qw(best_lead best_follow best_marriage | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 10 | should_close should_claim LEVELS); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 10 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 10 | our @LADDER = (1, 1, 2, 2, 2); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 10 | has level => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||
| 18 | 10 | has seed => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 46 | ▶ | 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 // ""
MC/DC0%0/1
$self->seed // ""
$self->seed
Truth table50%1/2
A
A= $self->seed
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | return ( | ||||||||||||||||||||||||||||
| 33 | 61893 | ▶ | level => $self->level || 1, | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->level || 1
MC/DC0%0/1
$self->level || 1
$self->level
Truth table50%1/2
A
A= $self->level
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 61893 | my $legal = $game->legal($seat); | |||||||||||||||||||||||||||
| 51 | 61893 | ▶ | return undef unless @$legal; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 59 | 1689 | return $by{exchange}[0]; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 60204 | ▶ | if ($by{marriage}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 57346 | ▶ | if ($by{claim} && should_claim(%o)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$by{"claim"} and should_claim(%o)
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)
| |||||||||||||||||||||||||||||
| 69 | 2423 | return $by{claim}[0]; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 54923 | ▶ | if ($by{close} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$by{"close"} and should_close(%o, "cards", $deal->hand_of($seat)->cards)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 30572 | ▶ | if ($by{follow}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 7195 | ▶ | return $by{draw}[0] if $by{draw}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | return $legal->[0]; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 10 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||