| 1 | package Game::Gin::Bot; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Game::Gin::Deadwood qw(deadwood); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Game::Gin::Search qw(worth_taking best_discard knock_now LEVELS); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 5 | has level => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||
| 16 | 5 | has seed => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 41355 | ▶ | sub choose { | ||||||||||||||||||||||||||||||||
|
Subroutine
choose: called CC=25 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 19 | 41355 | my ($self, $game, $seat) = @_; | |||||||||||||||||||||||||||||||||
| 20 | 41355 | ▶ | my $deal = $game->can('deal') ? $game->deal : $game; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 21 | 41355 | ▶ | return undef unless $deal && !$deal->over; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$deal and not $deal->over
MC/DC0%0/2
$deal and not $deal->over
$deal
not $deal->over
Truth table33%1/3
A and not(B)
A= $dealB= not $deal->over
| |||||||||||||||||||||||||||||||||||
| 22 | 41355 | ▶ | return undef unless ($deal->turn // '') eq $seat; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$deal->turn // ""
MC/DC0%0/1
$deal->turn // ""
$deal->turn
Truth table50%1/2
A
A= $deal->turn
| |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 41354 | my $legal = $deal->legal($seat); | |||||||||||||||||||||||||||||||||
| 25 | 41354 | ▶ | return undef unless @$legal; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 41354 | ▶ | my $level = $self->level || LEVELS; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->level || 2
MC/DC0%0/1
$self->level || 2
$self->level
Truth table50%1/2
A
A= $self->level
| |||||||||||||||||||||||||||||||||||
| 28 | 41354 | my $hand = $deal->hand_of($seat)->cards; | |||||||||||||||||||||||||||||||||
| 29 | 41354 | my $phase = $deal->phase; | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 41354 | ▶ | if ($phase eq 'upcard' || $phase eq 'draw') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$phase eq "upcard" or $phase eq "draw"
MC/DC100%2/2
$phase eq "upcard" or $phase eq "draw"
$phase eq "upcard"
$phase eq "draw"
Truth table100%3/3
A or B
A= $phase eq "upcard"B= $phase eq "draw"
| |||||||||||||||||||||||||||||||||||
| 32 | 20711 | my $take = worth_taking(hand => $hand, upcard => $deal->upcard, level => $level); | |||||||||||||||||||||||||||||||||
| 33 | 20711 | ▶ | return { kind => 'take' } if $take && grep { $_->{kind} eq 'take' } @$legal; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$take and grep {$_->{"kind"} eq "take";} @$legal
MC/DC50%1/2
$take and grep {$_->{"kind"} eq "take";} @$legal
$take
grep {$_->{"kind"} eq "take";} @$legal
Truth table66%2/3
A and B
A= $takeB= grep {$_->{"kind"} eq "take";} @$legal
| |||||||||||||||||||||||||||||||||||
| 34 | 14610 | ▶ | return { kind => 'draw' } if grep { $_->{kind} eq 'draw' } @$legal; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | 729 | ▶ | return { kind => 'pass' } if grep { $_->{kind} eq 'pass' } @$legal; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | return $legal->[0]; | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | 20643 | ▶ | return { kind => 'draw' } if $phase eq 'forced_draw'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 20312 | my ($big) = grep { $_->{kind} eq 'big_gin' } @$legal; | |||||||||||||||||||||||||||||||||
| 41 | 20312 | ▶ | return $big if $big; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 20307 | ▶ | my $card = best_discard( | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$deal->taken || undef
MC/DC100%1/1
$deal->taken || undef
$deal->taken
Truth table100%2/2
A
A= $deal->taken
| |||||||||||||||||||||||||||||||||||
| 44 | hand => $hand, | ||||||||||||||||||||||||||||||||||
| 45 | level => $level, | ||||||||||||||||||||||||||||||||||
| 46 | just_taken => ($deal->taken || undef), | ||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||
| 48 | 20307 | ▶ | return $legal->[0] unless defined $card; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 20307 | my $left = deadwood([ grep { $_ != $card } @$hand ]); | |||||||||||||||||||||||||||||||||
| 51 | 20307 | my $knock = knock_now(deadwood => $left, stock_left => $deal->stock_left, level => $level); | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 20307 | ▶ | if ($knock) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 54 | 1456 | ▶ | my ($move) = grep { $_->{kind} eq 'discard' && $_->{card} == $card && $_->{knock} } @$legal; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$_->{'kind'} eq 'discard' && $_->{'card'} == $card && $_->{'knock'}
$_->{"kind"} eq "discard" and $_->{"card"} == $card
MC/DC66%2/3
$_->{'kind'} eq 'discard' && $_->{'card'} == $card && $_->{'knock'}
$_->{"kind"} eq "discard"
$_->{"card"} == $card
$_->{'knock'}
Truth table75%3/4
A and B && C
A= $_->{"kind"} eq "discard"B= $_->{"card"} == $cardC= $_->{'knock'}
| |||||||||||||||||||||||||||||||||||
| 55 | 1456 | ▶ | return $move if $move; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||
| 57 | 18851 | ▶ | my ($move) = grep { $_->{kind} eq 'discard' && $_->{card} == $card && !$_->{knock} } @$legal; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$_->{'kind'} eq 'discard' && $_->{'card'} == $card && !$_->{'knock'}
$_->{"kind"} eq "discard" and $_->{"card"} == $card
MC/DC66%2/3
$_->{'kind'} eq 'discard' && $_->{'card'} == $card && !$_->{'knock'}
$_->{"kind"} eq "discard"
$_->{"card"} == $card
!$_->{'knock'}
Truth table75%3/4
A and B && not(C)
A= $_->{"kind"} eq "discard"B= $_->{"card"} == $cardC= !$_->{'knock'}
| |||||||||||||||||||||||||||||||||||
| 58 | 18851 | ▶ | return $move || $legal->[0]; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$move || $legal->[0]
MC/DC0%0/2
$move || $legal->[0]
$move
$legal->[0]
Truth table33%1/3
A || B
A= $moveB= $legal->[0]
| |||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub seed_for { | ||||||||||||||||||||||||||||||||
|
Subroutine
seed_for: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 62 | 0 | my ($class, $game_seed, $seat) = @_; | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return unpack 'H16', Digest::SHA::sha256('gin-bot:' . ($game_seed // '') . ':' . ($seat // '?')); | ||||||||||||||||||||||||||||||||
|
Condition0%0/4
$game_seed // ""
$seat // "?"
MC/DC0%0/1
$game_seed // ""
$game_seed
MC/DC0%0/1
$seat // "?"
$seat
Truth table0%0/2
A
A= $game_seed
Truth table0%0/2
A
A= $seat
| |||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||