| 1 | 2 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Games::Go::Coordinate; | ||||||||||
| 6 | 2 | our $VERSION = '1.100860'; | |||||||||
| 7 | # ABSTRACT: Represents a board coordinate in the game of Go | ||||||||||
| 8 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | use overload | ||||||||||
| 10 | 2 | ▶ | '""' => 'stringify', | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | 'cmp' => 'str_cmp'; | |||||||||
| 12 | 2 | has [qw/x y/] => (is => 'rw', isa => 'Int'); | |||||||||
| 13 | |||||||||||
| 14 | # accept something like 'ac' and set x=1, y=3 | ||||||||||
| 15 | 1 | ▶ | sub set_sgf_coordinate { | ||||||||
|
Subroutine
set_sgf_coordinate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 16 | 1 | my ($self, $coord) = @_; | |||||||||
| 17 | 1 | my ($x, $y) = map { ord($_) - 96 } split // => lc($coord); | |||||||||
| 18 | 1 | $self->x($x); | |||||||||
| 19 | 1 | $self->y($y); | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | sub new_from_sgf_coordinate { | ||||||||
|
Subroutine
new_from_sgf_coordinate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | 1 | my ($class, $coord) = @_; | |||||||||
| 24 | 1 | my $self = $class->new; | |||||||||
| 25 | 1 | $self->set_sgf_coordinate($coord); | |||||||||
| 26 | 1 | $self; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 9 | ▶ | sub to_sgf { | ||||||||
|
Subroutine
to_sgf: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 30 | 9 | my $self = shift; | |||||||||
| 31 | 9 | join '' => map { chr($_ + 96) } $self->x, $self->y; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub as_list { | ||||||||
|
Subroutine
as_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 1 | my $self = shift; | |||||||||
| 36 | 1 | sprintf '(%d,%d)', $self->x, $self->y; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 9 | ▶ | sub stringify { | ||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | 9 | my $self = shift; | |||||||||
| 41 | 9 | $self->to_sgf; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 4 | ▶ | sub str_cmp { | ||||||||
|
Subroutine
str_cmp: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 45 | 4 | my ($lhs, $rhs, $reversed) = @_; | |||||||||
| 46 | 4 | $_ = "$_" for $lhs, $rhs; | |||||||||
| 47 | 4 | ▶ | ($lhs, $rhs) = ($rhs, $lhs) if $reversed; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 4 | $lhs cmp $rhs; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub translate { | ||||||||
|
Subroutine
translate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | 1 | my ($self, $dx, $dy) = @_; | |||||||||
| 53 | 1 | $self->x($self->x + $dx); | |||||||||
| 54 | 1 | $self->y($self->y + $dy); | |||||||||
| 55 | } | ||||||||||
| 56 | 2 | 1; | |||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||