| 1 | package Game::Brandubh::Engine; | ||||||||||
| 2 | |||||||||||
| 3 | 59 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 59 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 59 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 59 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 59 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 59 | ▶ | use Object::Proto::Sugar; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 59 | our $VERSION = '0.02'; | |||||||||
| 12 | |||||||||||
| 13 | 59 | require XSLoader; | |||||||||
| 14 | 59 | XSLoader::load('Game::Brandubh', $VERSION); | |||||||||
| 15 | |||||||||||
| 16 | 59 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 59 | EMPTY => 0, | |||||||||
| 18 | ATTACKER => 1, | ||||||||||
| 19 | DEFENDER => 2, | ||||||||||
| 20 | KING => 3, | ||||||||||
| 21 | BORDER => 4, | ||||||||||
| 22 | |||||||||||
| 23 | ATTACKERS => 0, | ||||||||||
| 24 | DEFENDERS => 1, | ||||||||||
| 25 | |||||||||||
| 26 | SIZE => 7, | ||||||||||
| 27 | SQUARES => 49, | ||||||||||
| 28 | 59 | }; | |||||||||
| 29 | |||||||||||
| 30 | 59 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 59 | POS_OK => 0, | |||||||||
| 32 | POS_NULL => 1, | ||||||||||
| 33 | POS_ROWS => 2, | ||||||||||
| 34 | POS_WIDTH => 3, | ||||||||||
| 35 | POS_LETTER => 4, | ||||||||||
| 36 | POS_SIDE => 5, | ||||||||||
| 37 | POS_LONG => 6, | ||||||||||
| 38 | 59 | }; | |||||||||
| 39 | |||||||||||
| 40 | 59 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 59 | WHY_OK => 0, | |||||||||
| 42 | WHY_OFF_BOARD => 1, | ||||||||||
| 43 | WHY_NO_PIECE => 2, | ||||||||||
| 44 | WHY_NOT_YOURS => 3, | ||||||||||
| 45 | WHY_NO_MOVE => 4, | ||||||||||
| 46 | WHY_NOT_A_LINE => 5, | ||||||||||
| 47 | WHY_THRONE => 6, | ||||||||||
| 48 | WHY_CORNER => 7, | ||||||||||
| 49 | WHY_BLOCKED => 8, | ||||||||||
| 50 | 59 | }; | |||||||||
| 51 | |||||||||||
| 52 | 59 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 53 | 59 | DID_CAPTURE => 1, | |||||||||
| 54 | KING_TAKEN => 2, | ||||||||||
| 55 | KING_HOME => 4, | ||||||||||
| 56 | 59 | }; | |||||||||
| 57 | |||||||||||
| 58 | 59 | our @EXPORT_OK = qw( | |||||||||
| 59 | EMPTY ATTACKER DEFENDER KING BORDER | ||||||||||
| 60 | ATTACKERS DEFENDERS SIZE SQUARES | ||||||||||
| 61 | POS_OK POS_NULL POS_ROWS POS_WIDTH POS_LETTER POS_SIDE POS_LONG | ||||||||||
| 62 | WHY_OK WHY_OFF_BOARD WHY_NO_PIECE WHY_NOT_YOURS WHY_NO_MOVE | ||||||||||
| 63 | WHY_NOT_A_LINE WHY_THRONE WHY_CORNER WHY_BLOCKED | ||||||||||
| 64 | DID_CAPTURE KING_TAKEN KING_HOME | ||||||||||
| 65 | other | ||||||||||
| 66 | ); | ||||||||||
| 67 | 59 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | sub other { $_[0] == ATTACKERS ? DEFENDERS : ATTACKERS } | ||||||||
|
Subroutine
other: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 59 | has _ptr => (is => 'rw', private => 1); | |||||||||
| 72 | |||||||||||
| 73 | 59 | has _empty => (is => 'ro', init_arg => 'empty', private => 1, default => 0); | |||||||||
| 74 | |||||||||||
| 75 | 59 | has _position => (is => 'ro', init_arg => 'position', private => 1); | |||||||||
| 76 | |||||||||||
| 77 | 59 | my %ADOPTING; | |||||||||
| 78 | |||||||||||
| 79 | 53623 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 80 | 53623 | my ($self) = @_; | |||||||||
| 81 | 53623 | my $given = $self->_ptr; | |||||||||
| 82 | 53623 | ▶ | if ($given) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 5851 | ▶ | return if delete $ADOPTING{$given}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 1 | $self->_ptr(0); | |||||||||
| 85 | 1 | Carp::croak("Game::Brandubh::Engine: a board is made by new, of_string or clone"); | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 47772 | my $position = $self->_position; | |||||||||
| 89 | 47772 | ▶ | if (defined $position) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 8 | my ($ptr, $err) = _of_string($position); | |||||||||
| 91 | 8 | ▶ | Carp::croak("Game::Brandubh::Engine: the position was refused, code $err") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | unless defined $ptr; | ||||||||||
| 93 | 6 | $self->_ptr($ptr); | |||||||||
| 94 | 6 | return; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 47764 | ▶ | $self->_ptr($self->_empty ? _new_empty() : _new_board()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 47764 | return; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 5850 | ▶ | my $adopt = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 102 | 5850 | my ($class, $ptr) = @_; | |||||||||
| 103 | 5850 | $ADOPTING{$ptr} = 1; | |||||||||
| 104 | 5850 | return $class->new(_ptr => $ptr); | |||||||||
| 105 | 59 | }; | |||||||||
| 106 | |||||||||||
| 107 | 5346 | ▶ | sub of_string { | ||||||||
|
Subroutine
of_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 108 | 5346 | my ($class, $position) = @_; | |||||||||
| 109 | 5346 | ▶ | my ($ptr, $err) = _of_string(defined $position ? $position : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 5346 | ▶ | return (undef, $err) unless defined $ptr; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 4364 | return ($adopt->($class, $ptr), POS_OK); | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 1486 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 115 | 1486 | my ($self) = @_; | |||||||||
| 116 | 1486 | return $adopt->(ref($self), _copy_board($self->_ptr)); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 53620 | ▶ | sub DEMOLISH { | ||||||||
|
Subroutine
DEMOLISH: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 120 | 53620 | my ($self) = @_; | |||||||||
| 121 | 53620 | my $ptr = $self->_ptr; | |||||||||
| 122 | 53620 | ▶ | return unless $ptr; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 53620 | _drop_board($ptr); | |||||||||
| 124 | 53620 | $self->_ptr(0); | |||||||||
| 125 | 53620 | return; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 524960 | ▶ | sub at { _at($_[0]->_ptr, $_[1]) } | ||||||||
|
Subroutine
at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 129 | 775114 | ▶ | sub put { _put($_[0]->_ptr, $_[1], $_[2]); return $_[0] } | ||||||||
|
Subroutine
put: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 130 | 2561 | ▶ | sub lift { _lift($_[0]->_ptr, $_[1]); return $_[0] } | ||||||||
|
Subroutine
lift: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 131 | 4018 | ▶ | sub side { _side($_[0]->_ptr) } | ||||||||
|
Subroutine
side: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 132 | 43631 | ▶ | sub set_side { _set_side($_[0]->_ptr, $_[1]); return $_[0] } | ||||||||
|
Subroutine
set_side: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 133 | 12 | ▶ | sub count { _count($_[0]->_ptr, $_[1]) } | ||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 134 | 5 | ▶ | sub king_square { _king_square($_[0]->_ptr) } | ||||||||
|
Subroutine
king_square: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 135 | 177325 | ▶ | sub to_string { _to_string($_[0]->_ptr) } | ||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 136 | 326509 | ▶ | sub key_hex { _key_hex($_[0]->_ptr) } | ||||||||
|
Subroutine
key_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 137 | 156028 | ▶ | sub key_full_hex { _key_full_hex($_[0]->_ptr) } | ||||||||
|
Subroutine
key_full_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 138 | |||||||||||
| 139 | 361748 | ▶ | sub square_of { my $c = shift; _square_of($_[0], $_[1]) } | ||||||||
|
Subroutine
square_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 140 | 3015524 | ▶ | sub file_of { my $c = shift; _file_of($_[0]) } | ||||||||
|
Subroutine
file_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 141 | 3015524 | ▶ | sub rank_of { my $c = shift; _rank_of($_[0]) } | ||||||||
|
Subroutine
rank_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 142 | 243 | ▶ | sub on_board { my $c = shift; _on_board($_[0]) } | ||||||||
|
Subroutine
on_board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 143 | 132 | ▶ | sub is_throne { my $c = shift; _is_throne($_[0]) } | ||||||||
|
Subroutine
is_throne: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 144 | 130 | ▶ | sub is_corner { my $c = shift; _is_corner($_[0]) } | ||||||||
|
Subroutine
is_corner: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 145 | 130 | ▶ | sub beside_throne { my $c = shift; _beside_throne($_[0]) } | ||||||||
|
Subroutine
beside_throne: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 146 | 5 | ▶ | sub side_of { my $c = shift; _side_of($_[0]) } | ||||||||
|
Subroutine
side_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 147 | 1 | ▶ | sub stride { _stride() } | ||||||||
|
Subroutine
stride: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 148 | |||||||||||
| 149 | 84511 | ▶ | sub all_squares { | ||||||||
|
Subroutine
all_squares: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 150 | 84511 | my @squares; | |||||||||
| 151 | 84511 | for my $rank (0 .. SIZE - 1) { | |||||||||
| 152 | 591577 | push @squares, map { _square_of($_, $rank) } 0 .. SIZE - 1; | |||||||||
| 153 | } | ||||||||||
| 154 | 84511 | return @squares; | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | 5 | ▶ | sub zobrist_hex { my $c = shift; _zobrist_hex($_[0], $_[1]) } | ||||||||
|
Subroutine
zobrist_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 158 | 1 | ▶ | sub zobrist_side_hex { _zobrist_side_hex() } | ||||||||
|
Subroutine
zobrist_side_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 159 | 1 | ▶ | sub abi_version { _abi_version() } | ||||||||
|
Subroutine
abi_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 160 | 14 | ▶ | sub live { _live() } | ||||||||
|
Subroutine
live: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 161 | |||||||||||
| 162 | 1476139 | ▶ | sub move { _move_make($_[1], $_[2]) } | ||||||||
|
Subroutine
move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 163 | 3016745 | ▶ | sub move_from { _move_from($_[1]) } | ||||||||
|
Subroutine
move_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 164 | 1400566 | ▶ | sub move_to { _move_to($_[1]) } | ||||||||
|
Subroutine
move_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 165 | 1 | ▶ | sub moves_max { _moves_max() } | ||||||||
|
Subroutine
moves_max: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 166 | |||||||||||
| 167 | 33795 | ▶ | sub moves { | ||||||||
|
Subroutine
moves: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 168 | 33795 | my @m = _gen_moves($_[0]->_ptr, $_[1]); | |||||||||
| 169 | 33792 | ▶ | return wantarray ? @m : scalar @m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | 96094 | ▶ | sub is_legal { _is_legal($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
is_legal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 173 | 1200525 | ▶ | sub why_not { _why_not($_[0]->_ptr, $_[1], $_[2], $_[3]) } | ||||||||
|
Subroutine
why_not: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 174 | 871 | ▶ | sub relocate { _relocate($_[0]->_ptr, $_[1]); return $_[0] } | ||||||||
|
Subroutine
relocate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 175 | |||||||||||
| 176 | 5138 | ▶ | sub perft_slides { _perft_slides($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
perft_slides: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 177 | |||||||||||
| 178 | 86 | ▶ | sub hostile_to { _hostile_to($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
hostile_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 179 | 2711 | ▶ | sub captures_at { _captures_at($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
captures_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 180 | 154495 | ▶ | sub do_move { _do_move($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
do_move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 181 | 154031 | ▶ | sub undo_move { _undo_move($_[0]->_ptr, $_[1]); return $_[0] } | ||||||||
|
Subroutine
undo_move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 182 | 251211 | ▶ | sub preview { _preview($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
preview: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 183 | 4818 | ▶ | sub perft { _perft($_[0]->_ptr, $_[1], $_[2]) } | ||||||||
|
Subroutine
perft: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 184 | |||||||||||
| 185 | 59 | 1; | |||||||||
| 186 | |||||||||||
| 187 | __END__ | ||||||||||