| 1 | package Game::Checkers::Piece; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 31 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 31 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 31 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 31 | our $VERSION = '0.04'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 31 | my %UI = ( | |||||||||||||
| 11 | 'b' => "\x{26C2}", | ||||||||||||||
| 12 | 'B' => "\x{26C3}", | ||||||||||||||
| 13 | 'w' => "\x{26C0}", | ||||||||||||||
| 14 | 'W' => "\x{26C1}", | ||||||||||||||
| 15 | ); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | has colour => ( | ||||||||||||||
| 18 | is => 'ro', | ||||||||||||||
| 19 | isa => Str | ||||||||||||||
| 20 | 31 | ); | |||||||||||||
| 21 | |||||||||||||||
| 22 | has king => ( | ||||||||||||||
| 23 | is => 'ro', | ||||||||||||||
| 24 | isa => Bool, | ||||||||||||||
| 25 | default => 0 | ||||||||||||||
| 26 | 31 | ); | |||||||||||||
| 27 | |||||||||||||||
| 28 | has square => ( | ||||||||||||||
| 29 | is => 'ro', | ||||||||||||||
| 30 | isa => Int | ||||||||||||||
| 31 | 31 | ); | |||||||||||||
| 32 | |||||||||||||||
| 33 | 9 | ▶ | sub from_value { | ||||||||||||
|
Subroutine
from_value: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 34 | 9 | my ($class, $value, $square) = @_; | |||||||||||||
| 35 | 9 | ▶ | return undef unless $value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 8 | ▶ | return $class->new( | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 37 | colour => $value > 0 ? 'black' : 'white', | ||||||||||||||
| 38 | king => abs($value) == 2 ? 1 : 0, | ||||||||||||||
| 39 | square => $square | ||||||||||||||
| 40 | ); | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 4 | ▶ | sub value { | ||||||||||||
|
Subroutine
value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 44 | 4 | my ($self) = @_; | |||||||||||||
| 45 | 4 | ▶ | my $value = $self->king ? 2 : 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 4 | ▶ | return $self->colour eq 'black' ? $value : -$value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 4 | ▶ | sub is_black { | ||||||||||||
|
Subroutine
is_black: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 50 | 4 | ▶ | return $_[0]->colour eq 'black' ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | ▶ | sub is_white { | ||||||||||||
|
Subroutine
is_white: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 54 | 0 | ▶ | return $_[0]->colour eq 'white' ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 4 | ▶ | sub stringify { | ||||||||||||
|
Subroutine
stringify: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 58 | 4 | my ($self) = @_; | |||||||||||||
| 59 | 4 | ▶ | my $letter = $self->is_black ? 'b' : 'w'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 4 | ▶ | return $self->king ? uc $letter : $letter; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | ▶ | sub ui_stringify { | ||||||||||||
|
Subroutine
ui_stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 64 | 0 | return $UI{$_[0]->stringify}; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 31 | 1; | |||||||||||||
| 68 | |||||||||||||||
| 69 | __END__ | ||||||||||||||