| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 34 | 63 | ▶ | return undef unless defined $game->turn && $game->turn eq $seat; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $game->turn and $game->turn eq $seat
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||