| 1 | package Term::Chess::Bot; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Chess::Plisco::Engine::Tree; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Chess::Plisco::Engine::TranspositionTable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Term::Chess::Watcher; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 6 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | our @LADDER = (2_000, 10_000, 10_000, 40_000); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | our $LEVEL; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | my $TT_MB = 1; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 39 | ▶ | sub ladder { @LADDER } | ||||||||||||||||||||||||||
|
Subroutine
ladder: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 226 | ▶ | sub level_for { | ||||||||||||||||||||||||||
|
Subroutine
level_for: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 226 | my ($class, $seed) = @_; | |||||||||||||||||||||||||||
| 25 | 226 | ▶ | return $LEVEL if defined $LEVEL; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 139 | my $n = unpack 'N', Digest::SHA::sha256("chess-level:$seed"); | |||||||||||||||||||||||||||
| 27 | 139 | return $LADDER[ $n % scalar @LADDER ]; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 91 | ▶ | sub choose { | ||||||||||||||||||||||||||
|
Subroutine
choose: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 91 | my ($class, $game, $seat) = @_; | |||||||||||||||||||||||||||
| 32 | 91 | ▶ | return undef unless $game->status eq 'active'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 90 | ▶ | return undef unless defined $game->turn && $game->turn eq $seat; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $game->turn and $game->turn eq $seat
MC/DC50%1/2
defined $game->turn and $game->turn eq $seat
defined $game->turn
$game->turn eq $seat
Truth table66%2/3
A and B
A= defined $game->turnB= $game->turn eq $seat
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 87 | my $budget = $class->level_for($game->_held_seed); | |||||||||||||||||||||||||||
| 36 | 87 | my $position = $game->position->copy; | |||||||||||||||||||||||||||
| 37 | 87 | my @info; | |||||||||||||||||||||||||||
| 38 | my $tree = Chess::Plisco::Engine::Tree->new( | ||||||||||||||||||||||||||||
| 39 | position => $position, | ||||||||||||||||||||||||||||
| 40 | signatures => $game->signatures, | ||||||||||||||||||||||||||||
| 41 | tt => Chess::Plisco::Engine::TranspositionTable->new($TT_MB), | ||||||||||||||||||||||||||||
| 42 | watcher => Term::Chess::Watcher->new($budget), | ||||||||||||||||||||||||||||
| 43 | 1315 | ▶ | info => sub { push @info, "@_" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 87 | ); | |||||||||||||||||||||||||||
| 45 | 87 | $tree->{max_nodes} = $budget; | |||||||||||||||||||||||||||
| 46 | 87 | $tree->{nodes_to_tc} = 1000; | |||||||||||||||||||||||||||
| 47 | 87 | $tree->{start_time} = [ Time::HiRes::gettimeofday() ]; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 87 | my ($move) = $tree->think; | |||||||||||||||||||||||||||
| 50 | 87 | ▶ | return undef unless $move; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 87 | ▶ | die "Term::Chess::Bot: the search failed: $info[-1]\n" if grep { /Error/ } @info; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 87 | my $uci = $game->position->moveCoordinateNotation($move); | |||||||||||||||||||||||||||
| 53 | 87 | ▶ | return wantarray ? ($uci, $tree->{nodes}, $budget) : $uci; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | ▶ | sub hint { | ||||||||||||||||||||||||||
|
Subroutine
hint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 5 | my ($class, $game, $seat) = @_; | |||||||||||||||||||||||||||
| 58 | 5 | local $LEVEL = $LADDER[-1]; | |||||||||||||||||||||||||||
| 59 | 5 | return $class->choose($game, $seat); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 6 | 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||