| 1 | package Game::Shogi::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Game::Shogi::Engine (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | our @LADDER = (400, 6_000, 60_000, 300_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | our $LEVEL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 211 | ▶ | sub level_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
level_for: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 211 | my ($class, $seed) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 211 | ▶ | return $LEVEL if defined $LEVEL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 202 | ▶ | my $n = unpack 'N', Digest::SHA::sha256('shogi-level:' . ($seed // '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$seed // ""
MC/DC0%0/1
$seed // ""
$seed
Truth table50%1/2
A
A= $seed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 202 | return $LADDER[ $n % scalar @LADDER ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 94 | ▶ | sub tiebreak_seed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tiebreak_seed: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 94 | my ($class, $seed, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 94 | ▶ | return unpack 'N', Digest::SHA::sha256('shogi-bot:' . ($seed // '') . ':' . ($side // '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$seed // ""
$side // ""
MC/DC100%1/1
$seed // ""
$seed
MC/DC0%0/1
$side // ""
$side
Truth table100%2/2
A
A= $seed
Truth table50%1/2
A
A= $side
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 53 | ▶ | sub choose { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
choose: called CC=7 SCAR=21.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 53 | my ($class, $game, $side, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 53 | ▶ | return undef unless defined $game && $game->status eq 'active'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $game and $game->status eq "active"
MC/DC0%0/2
defined $game and $game->status eq "active"
defined $game
$game->status eq "active"
Truth table33%1/3
A and B
A= defined $gameB= $game->status eq "active"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 53 | ▶ | return undef unless defined $side && defined $game->turn && $game->turn eq $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $side and defined $game->turn and $game->turn eq $side
defined $side and defined $game->turn
MC/DC33%1/3
defined $side and defined $game->turn and $game->turn eq $side
defined $side
defined $game->turn
$game->turn eq $side
Truth table50%2/4
A and B and C
A= defined $sideB= defined $game->turnC= $game->turn eq $side
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 52 | ▶ | my $budget = $opt{nodes} // $class->level_for($opt{seed}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opt{"nodes"} // $class->level_for($opt{"seed"})
MC/DC0%0/2
$opt{"nodes"} // $class->level_for($opt{"seed"})
$opt{"nodes"}
$class->level_for($opt{"seed"})
Truth table66%2/3
A // B
A= $opt{"nodes"}B= $class->level_for($opt{"seed"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | return scalar $game->board->search( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | nodes => $budget, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 52 | seed => $class->tiebreak_seed($opt{seed}, $side), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | history => [ $game->history ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | ▶ | sub declares { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declares: called CC=6 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | my ($class, $game, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | return 0 unless defined $game && defined $side && defined $game->turn && $game->turn eq $side; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $game and defined $side and defined $game->turn and $game->turn eq $side
defined $game and defined $side and defined $game->turn
defined $game and defined $side
MC/DC0%0/4
defined $game and defined $side and defined $game->turn and $game->turn eq $side
defined $game
defined $side
defined $game->turn
$game->turn eq $side
Truth table20%1/5
A and B and C and D
A= defined $gameB= defined $sideC= defined $game->turnD= $game->turn eq $side
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | ▶ | return $game->can_declare ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | sub hint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | my ($class, $game, $side, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | return $class->choose($game, $side, %opt, nodes => $LADDER[-1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||