| 1 | package Game::Mahjong::Search; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 34 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 34 | ▶ | use Game::Mahjong::Tiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 34 | ▶ | use Game::Mahjong::Hand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 34 | ▶ | use Game::Mahjong::Meld; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 34 | ▶ | use Game::Mahjong::Decompose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 34 | ▶ | use Game::Mahjong::Shanten; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 34 | ▶ | use Game::Mahjong::Score; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 34 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 34 | our %OFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 17014 | ▶ | sub view_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view_of: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 17014 | my ($rules, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 17014 | my $hand = $rules->hand_of($seat)->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 17014 | my %visible; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 17014 | for my $s (0 .. 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 68056 | $visible{$_}++ for @{ $rules->pool_of($s) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 68056 | for my $m (@{ $rules->hand_of($s)->melds }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 7739 | ▶ | next if $m->concealed && $s != $seat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$m->concealed and $s != $seat
MC/DC100%2/2
$m->concealed and $s != $seat
$m->concealed
$s != $seat
Truth table100%3/3
A and B
A= $m->concealedB= $s != $seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7474 | $visible{$_}++ for @{ $m->tiles }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 17014 | $visible{$_}++ for $hand->tiles; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 17014 | my @melds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 17014 | for my $s (0 .. 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | push @melds, [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 7739 | ▶ | { kind => $_->kind, tiles => ($_->concealed && $s != $seat) ? [] : [ @{ $_->tiles } ], concealed => $_->concealed ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$_->concealed and $s != $seat
MC/DC100%2/2
$_->concealed and $s != $seat
$_->concealed
$s != $seat
Truth table100%3/3
A and B
A= $_->concealedB= $s != $seat
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 68056 | } @{ $rules->hand_of($s)->melds } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 17014 | my $w = $rules->window; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | seat => $seat, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | hand => $hand, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | phase => $rules->phase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | turn => $rules->turn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | window => $w ? { tile => $w->{tile}, from => $w->{from}, kind => $w->{kind} } : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | prevailing => $rules->prevailing, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | seat_wind => $rules->seat_wind($seat), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | wall => $rules->wall->remaining, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 68056 | pools => [ map { [ @{ $rules->pool_of($_) } ] } 0 .. 3 ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | melds => \@melds, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | visible => \%visible, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 17014 | ▶ | totals => [ @{ $rules->totals } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | hand_no => $rules->hand_no, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | moves => $rules->moves, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | drawn => $rules->drawn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | legal => [ $rules->legal($seat) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub _word { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_word: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ($view, $tag, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $seed = $view->{seed} // 'search'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$view->{"seed"} // "search"
MC/DC0%0/1
$view->{"seed"} // "search"
$view->{"seed"}
Truth table0%0/2
A
A= $view->{"seed"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($w) = unpack 'N', Digest::SHA::sha256("$seed:$view->{hand_no}:$view->{moves}:$tag"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $w % $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 17028 | ▶ | sub best { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
best: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 17028 | my ($view, $level, $word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 17028 | ▶ | $word ||= sub { _word($view, @_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$word ||= sub {
_word($view, @_);
}
MC/DC0%0/2
$word ||= sub {
_word($view, @_);
}
$word
sub {
_word($view, @_);
}
Truth table33%1/3
A ||= B
A= $wordB= sub {
_word($view, @_);
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 17028 | my @legal = @{ $view->{legal} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 17028 | ▶ | return undef unless @legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 17028 | ▶ | return $legal[0] if @legal == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 17025 | my ($win) = grep { $_->{kind} eq 'win' } @legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 17025 | ▶ | return $win if $win; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 16888 | ▶ | if ($view->{phase} eq 'discard') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 12623 | my $kong = _self_kong($view, $level, \@legal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 12623 | ▶ | return $kong if $kong; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 12603 | return _discard($view, $level, \@legal, $word); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 4265 | return _answer($view, $level, \@legal, $word); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 370275 | ▶ | sub _isolation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isolation: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 370275 | my ($hand, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 370275 | my $c = $hand->count($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 370275 | my $n = ($c - 1) * 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 370275 | ▶ | if (my $rank = Game::Mahjong::Tiles::rank_of($kind)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 346484 | ▶ | $n += 2 * $hand->count($kind - 1) if $rank > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 346484 | ▶ | $n += 2 * $hand->count($kind + 1) if $rank < 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 346484 | ▶ | $n += $hand->count($kind - 2) if $rank > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 346484 | ▶ | $n += $hand->count($kind + 2) if $rank < 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 370275 | ▶ | my $tie = Game::Mahjong::Tiles::is_honour($kind) ? 0 : Game::Mahjong::Tiles::is_terminal($kind) ? 1 : 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 370275 | return $n * 10 + $tie; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 169226 | ▶ | sub _remaining { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remaining: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 169226 | my ($view, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 169226 | ▶ | my $r = Game::Mahjong::Tiles::PER_KIND - ($view->{visible}{$kind} || 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$view->{'visible'}{$kind} || 0
MC/DC100%1/1
$view->{'visible'}{$kind} || 0
$view->{'visible'}{$kind}
Truth table100%2/2
A
A= $view->{'visible'}{$kind}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 169226 | ▶ | return $r < 0 ? 0 : $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 22551 | ▶ | sub _acceptance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_acceptance: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 22551 | my ($view, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 22551 | my $after = $view->{hand}->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 22551 | $after->remove($kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 22551 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 22551 | $n += _remaining($view, $_) for Game::Mahjong::Shanten::ukeire($after); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 22551 | return $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 12603 | ▶ | sub _discard { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_discard: called CC=13 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 12603 | my ($view, $level, $legal, $word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 12603 | my @discards = grep { $_->{kind} eq 'discard' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 12603 | my $hand = $view->{hand}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 12603 | ▶ | if ($level <= 1 || $OFF{shanten}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$level <= 1 or $Game::Mahjong::Search::OFF{"shanten"}
MC/DC100%2/2
$level <= 1 or $Game::Mahjong::Search::OFF{"shanten"}
$level <= 1
$Game::Mahjong::Search::OFF{"shanten"}
Truth table100%3/3
A or B
A= $level <= 1B= $Game::Mahjong::Search::OFF{"shanten"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7627 | ▶ | my @ranked = sort { _isolation($hand, $a->{tile}) <=> _isolation($hand, $b->{tile}) || $a->{tile} <=> $b->{tile} } @discards; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
_isolation($hand, $Game::Mahjong::Search::a->{'tile'}) <=> _isolation($hand, $Game::Mahjong::Search::b->{'tile'}) || $Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
MC/DC0%0/2
_isolation($hand, $Game::Mahjong::Search::a->{'tile'}) <=> _isolation($hand, $Game::Mahjong::Search::b->{'tile'}) || $Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
_isolation($hand, $Game::Mahjong::Search::a->{'tile'}) <=> _isolation($hand, $Game::Mahjong::Search::b->{'tile'})
$Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
Truth table66%2/3
A || B
A= _isolation($hand, $Game::Mahjong::Search::a->{'tile'}) <=> _isolation($hand, $Game::Mahjong::Search::b->{'tile'})B= $Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 7627 | return $ranked[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4976 | my %after = map { $_->{tile} => Game::Mahjong::Shanten::after_discard($hand, $_->{tile}) } @discards; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4976 | my $min = (sort { $a <=> $b } values %after)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4976 | my @keep = grep { $after{ $_->{tile} } == $min } @discards; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 4976 | ▶ | my @safe = $level >= 3 && !$OFF{defence} ? _safe_kinds($view) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$level >= 3 and not $Game::Mahjong::Search::OFF{"defence"}
MC/DC50%1/2
$level >= 3 and not $Game::Mahjong::Search::OFF{"defence"}
$level >= 3
not $Game::Mahjong::Search::OFF{"defence"}
Truth table66%2/3
A and not(B)
A= $level >= 3B= not $Game::Mahjong::Search::OFF{"defence"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4976 | my %safe = map { $_ => 1 } @safe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4976 | ▶ | if (@safe && Game::Mahjong::Shanten::shanten($hand) >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@safe and Game::Mahjong::Shanten::shanten($hand) >= 2
MC/DC50%1/2
@safe and Game::Mahjong::Shanten::shanten($hand) >= 2
@safe
Game::Mahjong::Shanten::shanten($hand) >= 2
Truth table66%2/3
A and B
A= @safeB= Game::Mahjong::Shanten::shanten($hand) >= 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | my @s = grep { $safe{ $_->{tile} } } @keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | @keep = @s if @s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 4976 | my %score; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 4976 | for my $d (@keep) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 22549 | my $s = _acceptance($view, $d->{tile}) * 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 22549 | ▶ | $s += _potential_after($view, $d->{tile}) if $level >= 3 && !$OFF{planning}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"}
MC/DC50%1/2
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"}
$level >= 3
not $Game::Mahjong::Search::OFF{"planning"}
Truth table66%2/3
A and not(B)
A= $level >= 3B= not $Game::Mahjong::Search::OFF{"planning"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 22549 | $s -= _isolation($hand, $d->{tile}) / 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 22549 | $score{ $d->{tile} } = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4976 | ▶ | my @ranked = sort { $score{ $b->{tile} } <=> $score{ $a->{tile} } || $a->{tile} <=> $b->{tile} } @keep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$score{$Game::Mahjong::Search::b->{'tile'}} <=> $score{$Game::Mahjong::Search::a->{'tile'}} || $Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
MC/DC0%0/2
$score{$Game::Mahjong::Search::b->{'tile'}} <=> $score{$Game::Mahjong::Search::a->{'tile'}} || $Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
$score{$Game::Mahjong::Search::b->{'tile'}} <=> $score{$Game::Mahjong::Search::a->{'tile'}}
$Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
Truth table66%2/3
A || B
A= $score{$Game::Mahjong::Search::b->{'tile'}} <=> $score{$Game::Mahjong::Search::a->{'tile'}}B= $Game::Mahjong::Search::a->{'tile'} <=> $Game::Mahjong::Search::b->{'tile'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 4976 | return $ranked[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2018 | ▶ | sub _safe_kinds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_safe_kinds: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2018 | my ($view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2018 | ▶ | my @near = grep { $_ != $view->{seat} && scalar(@{ $view->{melds}[$_] }) >= 3 } 0 .. 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ != $view->{'seat'} && scalar @{$view->{'melds'}[$_];} >= 3
MC/DC100%2/2
$_ != $view->{'seat'} && scalar @{$view->{'melds'}[$_];} >= 3
$_ != $view->{'seat'}
scalar @{$view->{'melds'}[$_];} >= 3
Truth table100%3/3
A && B
A= $_ != $view->{'seat'}B= scalar @{$view->{'melds'}[$_];} >= 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2018 | ▶ | return () unless @near; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my %safe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | for my $kind ($view->{hand}->kinds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 12 | ▶ | $safe{$kind} = 1 if _remaining($view, $kind) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 12 | for my $s (@near) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 12 | ▶ | $safe{$kind} = 1 if grep { $_ == $kind } @{ $view->{pools}[$s] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | return sort { $a <=> $b } keys %safe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8877 | ▶ | sub _potential_after { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_potential_after: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 8877 | my ($view, $discard) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 8877 | my $hand = $view->{hand}->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 8877 | $hand->remove($discard); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 8877 | my (%suit, $honours); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 8877 | my @tiles = ($hand->tiles, map { @{ $_->tiles } } @{ $hand->melds }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 8877 | for my $t (@tiles) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 115563 | ▶ | if (my $s = Game::Mahjong::Tiles::suit_of($t)) { $suit{$s}++ } else { $honours++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 8877 | my ($big) = sort { $b <=> $a } values %suit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 8877 | ▶ | $big ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$big ||= 0
MC/DC0%0/1
$big ||= 0
$big
Truth table50%1/2
A
A= $big
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 8877 | my $p = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 8877 | ▶ | $p += 24 * ($big / 14) if $big >= 9 && !$honours; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$big >= 9 and not $honours
MC/DC100%2/2
$big >= 9 and not $honours
$big >= 9
not $honours
Truth table100%3/3
A and not(B)
A= $big >= 9B= not $honours
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 8877 | ▶ | $p += 6 * (($big + ($honours || 0)) / 14) if $big >= 8 && $honours; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$big >= 8 and $honours
$honours || 0
MC/DC100%2/2
$big >= 8 and $honours
$big >= 8
$honours
MC/DC0%0/1
$honours || 0
$honours
Truth table100%3/3
A and B
A= $big >= 8B= $honours
Truth table50%1/2
A
A= $honours
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 8877 | my $pungs = grep { $hand->count($_) >= 3 } $hand->kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 8877 | $pungs += grep { $_->is_pung } @{ $hand->melds }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 8877 | ▶ | $p += 6 * ($pungs / 4) if $pungs >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 8877 | for my $k ($hand->kinds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 89366 | ▶ | next unless $hand->count($k) >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 17930 | ▶ | $p += 2 if Game::Mahjong::Tiles::is_dragon($k); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 17930 | ▶ | $p += 2 if Game::Mahjong::Tiles::is_wind($k) && (Game::Mahjong::Tiles::wind_index($k) == $view->{prevailing} || Game::Mahjong::Tiles::wind_index($k) == $view->{seat_wind}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
Game::Mahjong::Tiles::is_wind($k) and Game::Mahjong::Tiles::wind_index($k) == $view->{"prevailing"} || Game::Mahjong::Tiles::wind_index($k) == $view->{"seat_wind"}
Game::Mahjong::Tiles::wind_index($k) == $view->{"prevailing"} or Game::Mahjong::Tiles::wind_index($k) == $view->{"seat_wind"}
MC/DC100%3/3
Game::Mahjong::Tiles::is_wind($k) and Game::Mahjong::Tiles::wind_index($k) == $view->{"prevailing"} || Game::Mahjong::Tiles::wind_index($k) == $view->{"seat_wind"}
Game::Mahjong::Tiles::is_wind($k)
Game::Mahjong::Tiles::wind_index($k) == $view->{"prevailing"}
Game::Mahjong::Tiles::wind_index($k) == $view->{"seat_wind"}
Truth table100%4/4
A and B or C
A= Game::Mahjong::Tiles::is_wind($k)B= Game::Mahjong::Tiles::wind_index($k) == $view->{"prevailing"}C= Game::Mahjong::Tiles::wind_index($k) == $view->{"seat_wind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 17930 | ▶ | $p += 1 if Game::Mahjong::Tiles::is_terminal($k); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 8877 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 12623 | ▶ | sub _self_kong { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_self_kong: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 12623 | my ($view, $level, $legal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 12623 | ▶ | return undef if $level <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4997 | my @kongs = grep { $_->{kind} eq 'kong' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 4997 | ▶ | return undef unless @kongs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 51 | my $hand = $view->{hand}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 51 | my $now = Game::Mahjong::Shanten::shanten($hand); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 51 | for my $k (@kongs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 51 | my $after = $hand->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 51 | ▶ | if ($after->holds_kong_of($k->{tile})) { $after->concealed_kong($k->{tile}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | else { $after->promote_kong($k->{tile}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 51 | ▶ | return $k if Game::Mahjong::Shanten::shanten($after) <= $now; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 31 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1226 | ▶ | sub _ctx { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ctx: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1226 | my ($view, $by, $from) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | return { by => $by, prevailing => $view->{prevailing}, seat => $view->{seat_wind}, from => $from, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1226 | flowers => scalar @{ $view->{hand}->flowers } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 560 | ▶ | sub _reaches_eight { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reaches_eight: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 560 | my ($view, $hand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 560 | ▶ | return 0 unless $hand->total == 13; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 560 | my @waits = Game::Mahjong::Decompose::waits($hand); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 560 | for my $w (@waits) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 901 | my $with = $hand->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 901 | $with->add($w); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 901 | my $ctx = _ctx($view, 'discard', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 901 | $ctx->{waits} = \@waits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 901 | my $t = Game::Mahjong::Score::score($with, $w, $ctx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 901 | ▶ | return 1 if $t && $t->minimum_met; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t and $t->minimum_met
MC/DC50%1/2
$t and $t->minimum_met
$t
$t->minimum_met
Truth table66%2/3
A and B
A= $tB= $t->minimum_met
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 495 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 4265 | ▶ | sub _answer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_answer: called CC=30 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4265 | my ($view, $level, $legal, $word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 4265 | my ($pass) = grep { $_->{kind} eq 'pass' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 4265 | ▶ | return $pass if $level <= 1 || $OFF{claims}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$level <= 1 or $Game::Mahjong::Search::OFF{"claims"}
MC/DC50%1/2
$level <= 1 or $Game::Mahjong::Search::OFF{"claims"}
$level <= 1
$Game::Mahjong::Search::OFF{"claims"}
Truth table66%2/3
A or B
A= $level <= 1B= $Game::Mahjong::Search::OFF{"claims"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1484 | my $hand = $view->{hand}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1484 | my $tile = $view->{window}{tile}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1484 | my $from = $view->{window}{from}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1484 | my $now = Game::Mahjong::Shanten::shanten($hand); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1484 | ▶ | for my $claim (grep { $_->{kind} eq 'kong' || $_->{kind} eq 'pung' } @$legal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->{'kind'} eq 'kong' || $_->{'kind'} eq 'pung'
MC/DC100%2/2
$_->{'kind'} eq 'kong' || $_->{'kind'} eq 'pung'
$_->{'kind'} eq 'kong'
$_->{'kind'} eq 'pung'
Truth table100%3/3
A || B
A= $_->{'kind'} eq 'kong'B= $_->{'kind'} eq 'pung'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 582 | my $after = $hand->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 582 | ▶ | if ($claim->{kind} eq 'kong') { $after->claim_kong($tile, $from) } else { $after->claim_pung($tile, $from) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 582 | my $kept = _best_thirteen($after); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 582 | my $s = Game::Mahjong::Shanten::shanten($kept); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 582 | ▶ | next unless $s < $now; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | my $scores = Game::Mahjong::Tiles::is_dragon($tile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 215 | ▶ | || (Game::Mahjong::Tiles::is_wind($tile) && (Game::Mahjong::Tiles::wind_index($tile) == $view->{prevailing} || Game::Mahjong::Tiles::wind_index($tile) == $view->{seat_wind})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%12/12
Game::Mahjong::Tiles::is_dragon($tile) || Game::Mahjong::Tiles::is_wind($tile) && (Game::Mahjong::Tiles::wind_index($tile) == $view->{'prevailing'} || Game::Mahjong::Tiles::wind_index($tile) == $view->{'seat_wind'}) || Game::Mahjong::Tiles::is_terminal($tile)
Game::Mahjong::Tiles::is_dragon($tile) or Game::Mahjong::Tiles::is_wind($tile) and Game::Mahjong::Tiles::wind_index($tile) == $view->{"prevailing"} || Game::Mahjong::Tiles::wind_index($tile) == $view->{"seat_wind"}
Game::Mahjong::Tiles::is_wind($tile) and Game::Mahjong::Tiles::wind_index($tile) == $view->{"prevailing"} || Game::Mahjong::Tiles::wind_index($tile) == $view->{"seat_wind"}
Game::Mahjong::Tiles::wind_index($tile) == $view->{"prevailing"} or Game::Mahjong::Tiles::wind_index($tile) == $view->{"seat_wind"}
MC/DC100%5/5
Game::Mahjong::Tiles::is_dragon($tile) || Game::Mahjong::Tiles::is_wind($tile) && (Game::Mahjong::Tiles::wind_index($tile) == $view->{'prevailing'} || Game::Mahjong::Tiles::wind_index($tile) == $view->{'seat_wind'}) || Game::Mahjong::Tiles::is_terminal($tile)
Game::Mahjong::Tiles::is_dragon($tile)
Game::Mahjong::Tiles::is_wind($tile)
Game::Mahjong::Tiles::wind_index($tile) == $view->{"prevailing"}
Game::Mahjong::Tiles::wind_index($tile) == $view->{"seat_wind"}
Game::Mahjong::Tiles::is_terminal($tile)
Truth table85%6/7
A or B and C or D || E
A= Game::Mahjong::Tiles::is_dragon($tile)B= Game::Mahjong::Tiles::is_wind($tile)C= Game::Mahjong::Tiles::wind_index($tile) == $view->{"prevailing"}D= Game::Mahjong::Tiles::wind_index($tile) == $view->{"seat_wind"}E= Game::Mahjong::Tiles::is_terminal($tile)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | || Game::Mahjong::Tiles::is_terminal($tile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 215 | my $floor = Game::Mahjong::Score::floor($kept, _ctx($view, 'discard', $from)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 215 | ▶ | return $claim if $scores || $floor >= Game::Mahjong::Score::MINIMUM || ($s == 0 && _reaches_eight($view, $kept)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$scores or $floor >= 8 or $s == 0 and _reaches_eight($view, $kept)
$scores or $floor >= 8
$s == 0 and _reaches_eight($view, $kept)
MC/DC100%4/4
$scores or $floor >= 8 or $s == 0 and _reaches_eight($view, $kept)
$scores
$floor >= 8
$s == 0
_reaches_eight($view, $kept)
Truth table100%5/5
A or B or C and D
A= $scoresB= $floor >= 8C= $s == 0D= _reaches_eight($view, $kept)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 119 | ▶ | return $claim if $level >= 3 && !$OFF{planning} && $s <= 1 && _potential_after_hand($view, $kept) >= 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1 and _potential_after_hand($view, $kept) >= 6
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"}
MC/DC75%3/4
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1 and _potential_after_hand($view, $kept) >= 6
$level >= 3
not $Game::Mahjong::Search::OFF{"planning"}
$s <= 1
_potential_after_hand($view, $kept) >= 6
Truth table80%4/5
A and not(B) and C and D
A= $level >= 3B= not $Game::Mahjong::Search::OFF{"planning"}C= $s <= 1D= _potential_after_hand($view, $kept) >= 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1385 | my @chows = grep { $_->{kind} eq 'chow' } @$legal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1385 | for my $chow (@chows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1218 | my $after = $hand->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1218 | $after->claim_chow($tile, @{ $chow->{tiles} }, $from); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1218 | my $kept = _best_thirteen($after); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1218 | my $s = Game::Mahjong::Shanten::shanten($kept); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1218 | ▶ | next unless $s < $now || ($now == 0 && $s == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$s < $now or $now == 0 and $s == 0
$now == 0 and $s == 0
MC/DC100%3/3
$s < $now or $now == 0 and $s == 0
$s < $now
$now == 0
$s == 0
Truth table100%4/4
A or B and C
A= $s < $nowB= $now == 0C= $s == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 740 | ▶ | return $chow if $s == 0 && _reaches_eight($view, $kept); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$s == 0 and _reaches_eight($view, $kept)
MC/DC100%2/2
$s == 0 and _reaches_eight($view, $kept)
$s == 0
_reaches_eight($view, $kept)
Truth table100%3/3
A and B
A= $s == 0B= _reaches_eight($view, $kept)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 676 | ▶ | return $chow if $level >= 3 && !$OFF{planning} && $s <= 1 && $s < $now && Game::Mahjong::Score::floor($kept, _ctx($view, 'discard', $from)) + _potential_after_hand($view, $kept) >= Game::Mahjong::Score::MINIMUM; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1 and $s < $now and Game::Mahjong::Score::floor($kept, _ctx($view, "discard", $from)) + _potential_after_hand($view, $kept) >= 8
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1 and $s < $now
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"}
MC/DC80%4/5
$level >= 3 and not $Game::Mahjong::Search::OFF{"planning"} and $s <= 1 and $s < $now and Game::Mahjong::Score::floor($kept, _ctx($view, "discard", $from)) + _potential_after_hand($view, $kept) >= 8
$level >= 3
not $Game::Mahjong::Search::OFF{"planning"}
$s <= 1
$s < $now
Game::Mahjong::Score::floor($kept, _ctx($view, "discard", $from)) + _potential_after_hand($view, $kept) >= 8
Truth table83%5/6
A and not(B) and C and D and E
A= $level >= 3B= not $Game::Mahjong::Search::OFF{"planning"}C= $s <= 1D= $s < $nowE= Game::Mahjong::Score::floor($kept, _ctx($view, "discard", $from)) + _potential_after_hand($view, $kept) >= 8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1317 | return $pass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1800 | ▶ | sub _best_thirteen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_best_thirteen: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1800 | my ($after) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1800 | ▶ | return $after if $after->total == 13; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1754 | my ($best, $best_s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1754 | for my $k ($after->kinds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 14559 | my $s = Game::Mahjong::Shanten::after_discard($after, $k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 14559 | ▶ | next if defined $best_s && $s >= $best_s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $best_s and $s >= $best_s
MC/DC100%2/2
defined $best_s and $s >= $best_s
defined $best_s
$s >= $best_s
Truth table100%3/3
A and B
A= defined $best_sB= $s >= $best_s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2530 | ($best, $best_s) = ($k, $s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1754 | my $h = $after->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1754 | $h->remove($best); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1754 | return $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 142 | ▶ | sub _potential_after_hand { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_potential_after_hand: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 142 | my ($view, $hand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 142 | my $v = { %$view, hand => $hand }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 142 | my ($k) = $hand->kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 142 | ▶ | return $k ? _potential_after($v, $k) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 34 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||