| 1 | package Game::Xiangqi::Notation; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Game::Xiangqi::Engine ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 12 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 12 | my $E = 'Game::Xiangqi::Engine'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 12 | my %LETTER = ( | |||||||||||||||||||||||||||
| 14 | GENERAL() => 'K', | ||||||||||||||||||||||||||||
| 15 | ADVISOR() => 'A', | ||||||||||||||||||||||||||||
| 16 | ELEPHANT() => 'E', | ||||||||||||||||||||||||||||
| 17 | CHARIOT() => 'R', | ||||||||||||||||||||||||||||
| 18 | HORSE() => 'H', | ||||||||||||||||||||||||||||
| 19 | CANNON() => 'C', | ||||||||||||||||||||||||||||
| 20 | SOLDIER() => 'P', | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 12 | my %DIAGONAL = (ADVISOR() => 1, ELEPHANT() => 1, HORSE() => 1); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1151 | ▶ | sub iccs_of { | ||||||||||||||||||||||||||
|
Subroutine
iccs_of: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 1151 | my ($class, $mv) = @_; | |||||||||||||||||||||||||||
| 27 | 1151 | my ($from, $to) = ($E->move_from($mv), $E->move_to($mv)); | |||||||||||||||||||||||||||
| 28 | 1151 | ▶ | return undef unless $E->on_board($from) && $E->on_board($to); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$E->on_board($from) and $E->on_board($to)
MC/DC0%0/2
$E->on_board($from) and $E->on_board($to)
$E->on_board($from)
$E->on_board($to)
Truth table33%1/3
A and B
A= $E->on_board($from)B= $E->on_board($to)
| |||||||||||||||||||||||||||||
| 29 | 1151 | return sprintf('%s%d%s%d', | |||||||||||||||||||||||||||
| 30 | ('a' .. 'i')[ $E->file_of($from) ], $E->rank_of($from), | ||||||||||||||||||||||||||||
| 31 | ('a' .. 'i')[ $E->file_of($to) ], $E->rank_of($to)); | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 282 | ▶ | sub move_of_iccs { | ||||||||||||||||||||||||||
|
Subroutine
move_of_iccs: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 282 | my ($class, $s) = @_; | |||||||||||||||||||||||||||
| 36 | 282 | ▶ | return undef unless defined $s && $s =~ /\A([a-i])([0-9])([a-i])([0-9])\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $s and $s =~ /\A([a-i])([0-9])([a-i])([0-9])\z/
MC/DC100%2/2
defined $s and $s =~ /\A([a-i])([0-9])([a-i])([0-9])\z/
defined $s
$s =~ /\A([a-i])([0-9])([a-i])([0-9])\z/
Truth table100%3/3
A and B
A= defined $sB= $s =~ /\A([a-i])([0-9])([a-i])([0-9])\z/
| |||||||||||||||||||||||||||||
| 37 | 266 | my %f = map { ('a' .. 'i')[$_] => $_ } 0 .. 8; | |||||||||||||||||||||||||||
| 38 | 266 | return $E->move($E->point_of($f{$1}, $2), $E->point_of($f{$3}, $4)); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 105 | ▶ | sub wxf_file { | ||||||||||||||||||||||||||
|
Subroutine
wxf_file: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 105 | my ($class, $file, $colour) = @_; | |||||||||||||||||||||||||||
| 43 | 105 | ▶ | return $colour == RED ? 9 - $file : $file + 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 74 | ▶ | sub wxf_of { | ||||||||||||||||||||||||||
|
Subroutine
wxf_of: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 74 | my ($class, $board, $mv) = @_; | |||||||||||||||||||||||||||
| 48 | 74 | my ($from, $to) = ($E->move_from($mv), $E->move_to($mv)); | |||||||||||||||||||||||||||
| 49 | 74 | my $piece = $board->at($from); | |||||||||||||||||||||||||||
| 50 | 74 | ▶ | return undef unless $piece && $piece != BORDER; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$piece and $piece != 32
MC/DC0%0/2
$piece and $piece != 32
$piece
$piece != 32
Truth table33%1/3
A and B
A= $pieceB= $piece != 32
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 74 | my $colour = Game::Xiangqi::Engine::colour_of($piece); | |||||||||||||||||||||||||||
| 53 | 74 | my $kind = Game::Xiangqi::Engine::kind_of($piece); | |||||||||||||||||||||||||||
| 54 | 74 | ▶ | my $letter = $LETTER{$kind} or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 74 | my ($ff, $fr) = ($E->file_of($from), $E->rank_of($from)); | |||||||||||||||||||||||||||
| 57 | 74 | my ($tf, $tr) = ($E->file_of($to), $E->rank_of($to)); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | my @same = grep { | ||||||||||||||||||||||||||||
| 60 | 74 | ▶ | $board->at($_) == $piece && $E->file_of($_) == $ff | ||||||||||||||||||||||||||
|
Condition100%3/3
$board->at($_) == $piece && $E->file_of($_) == $ff
MC/DC100%2/2
$board->at($_) == $piece && $E->file_of($_) == $ff
$board->at($_) == $piece
$E->file_of($_) == $ff
Truth table100%3/3
A && B
A= $board->at($_) == $pieceB= $E->file_of($_) == $ff
| |||||||||||||||||||||||||||||
| 61 | } $E->all_points; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 74 | my $head; | |||||||||||||||||||||||||||
| 64 | 74 | ▶ | if (@same > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | my @order = sort { | ||||||||||||||||||||||||||||
| 66 | 9 | ▶ | $colour == RED ? $E->rank_of($b) <=> $E->rank_of($a) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | : $E->rank_of($a) <=> $E->rank_of($b) | ||||||||||||||||||||||||||||
| 68 | } @same; | ||||||||||||||||||||||||||||
| 69 | 9 | my ($idx) = grep { $order[$_] == $from } 0 .. $#order; | |||||||||||||||||||||||||||
| 70 | 9 | ▶ | $head = @same == 2 ? ($idx == 0 ? "+$letter" : "-$letter") | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 71 | : ($idx + 1) . $letter; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||
| 74 | 65 | $head = $letter . $class->wxf_file($ff, $colour); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 74 | ▶ | my $dir = $tr == $fr ? '.' | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 78 | : ($colour == RED ? ($tr > $fr ? '+' : '-') | ||||||||||||||||||||||||||||
| 79 | : ($tr < $fr ? '+' : '-')); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | my $tail = $dir eq '.' ? $class->wxf_file($tf, $colour) | ||||||||||||||||||||||||||||
| 82 | 74 | ▶ | : $DIAGONAL{$kind} ? $class->wxf_file($tf, $colour) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 83 | : abs($tr - $fr); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 74 | return "$head$dir$tail"; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 12 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||