| 1 | package Games::Go::Cinderblock::State; | ||||||||||
| 2 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use Games::Go::Cinderblock::MoveResult; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | # basilisk::state, | ||||||||||
| 7 | # long overdue. | ||||||||||
| 8 | # describes board pos, turn, caps, etc. | ||||||||||
| 9 | # serializable & deserializable. | ||||||||||
| 10 | # doesn't serialize ruleset...; dunno how to handle that. if at all. | ||||||||||
| 11 | 6 | has rulemap => ( | |||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | isa => 'Games::Go::Cinderblock::Rulemap', | ||||||||||
| 14 | required => 1, | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 6 | has board => ( | |||||||||
| 18 | isa => 'ArrayRef', | ||||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | ); | ||||||||||
| 21 | 6 | has turn => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | isa => 'Str', | ||||||||||
| 24 | ); | ||||||||||
| 25 | has _captures => ( | ||||||||||
| 26 | isa => 'HashRef', | ||||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | 9 | ▶ | default => sub{{w=>0,b=>0}}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 6 | ); | |||||||||
| 30 | |||||||||||
| 31 | 14 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 32 | 14 | my $orig = shift; | |||||||||
| 33 | 14 | my $class = shift; | |||||||||
| 34 | 14 | my %args = @_; | |||||||||
| 35 | 14 | ▶ | if($args{captures}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 5 | $args{_captures} = delete $args{captures}; | |||||||||
| 37 | } | ||||||||||
| 38 | 14 | return $class->$orig(%args); | |||||||||
| 39 | 6 | }; | |||||||||
| 40 | |||||||||||
| 41 | 14 | ▶ | sub attempt_move{ | ||||||||
|
Subroutine
attempt_move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | 14 | my $self = shift; | |||||||||
| 43 | 14 | my %args = @_; | |||||||||
| 44 | 14 | my $success = 1; | |||||||||
| 45 | my $attempt = Games::Go::Cinderblock::MoveAttempt->new( | ||||||||||
| 46 | basis_state => $self, | ||||||||||
| 47 | rulemap => $self->rulemap, | ||||||||||
| 48 | node => $args{node}, | ||||||||||
| 49 | color => $args{color}, | ||||||||||
| 50 | 14 | move_attempt => \%args, | |||||||||
| 51 | ); | ||||||||||
| 52 | 14 | my $result = $self->rulemap->evaluate_move_attempt($attempt); | |||||||||
| 53 | 10 | return $result; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 3 | ▶ | sub scorable{ #new? args? scorable_from_json? | ||||||||
|
Subroutine
scorable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 3 | my $self = shift; | |||||||||
| 58 | 3 | my $scorable = Games::Go::Cinderblock::Scorable->new( | |||||||||
| 59 | state => $self, | ||||||||||
| 60 | rulemap => $self->rulemap, | ||||||||||
| 61 | ); | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 223 | ▶ | sub at_node{ | ||||||||
|
Subroutine
at_node: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 65 | 223 | my ($self,$node) = @_; | |||||||||
| 66 | 223 | return $self->rulemap->stone_at_node($self->board,$node); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 24 | ▶ | sub floodfill{ | ||||||||
|
Subroutine
floodfill: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 70 | 24 | my ($self, $cond, $progenitor) = @_; | |||||||||
| 71 | 24 | my $set = $self->rulemap->nodeset($progenitor); | |||||||||
| 72 | 24 | my $seen = $self->rulemap->nodeset($progenitor); | |||||||||
| 73 | 24 | my @q = $self->rulemap->adjacent_nodes($progenitor); | |||||||||
| 74 | 24 | my $unseen = $self->rulemap->nodeset(@q); | |||||||||
| 75 | 24 | local($_); | |||||||||
| 76 | 24 | ▶ | while($unseen->count){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 110 | my $node = $unseen->choose; | |||||||||
| 78 | 110 | $unseen->remove($node); | |||||||||
| 79 | 110 | $seen->add($node); | |||||||||
| 80 | #next if $seen->has_node($node); | ||||||||||
| 81 | #$seen->add($node); | ||||||||||
| 82 | 110 | $_ = $self->at_node($node); | |||||||||
| 83 | #warn ($_ ? @$_ : ''); | ||||||||||
| 84 | #Carp::confess; | ||||||||||
| 85 | 110 | ▶ | next unless $cond->($node); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 49 | $set->add($node); | |||||||||
| 87 | 49 | for my $n ( $self->rulemap->adjacent_nodes($node)) { | |||||||||
| 88 | 126 | ▶ | next if ($seen->has_node($n)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 56 | $unseen->add($n); | |||||||||
| 90 | } | ||||||||||
| 91 | # push @q, $self->rulemap->adjacent_nodes($node); | ||||||||||
| 92 | } | ||||||||||
| 93 | 24 | return $set; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | |||||||||||
| 97 | 9 | ▶ | sub grep_nodeset{ | ||||||||
|
Subroutine
grep_nodeset: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 98 | 9 | my ($self,$cond,$ns) = @_; | |||||||||
| 99 | 9 | my $new_ns = $self->rulemap->nodeset; | |||||||||
| 100 | 9 | local($_); | |||||||||
| 101 | 9 | for my $node ($ns->nodes){ | |||||||||
| 102 | 45 | my $at = $self->at_node($node); | |||||||||
| 103 | 45 | $_ = $at; | |||||||||
| 104 | 45 | ▶ | if($cond->()){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 21 | $new_ns->add($node); | |||||||||
| 106 | } | ||||||||||
| 107 | } | ||||||||||
| 108 | 9 | return $new_ns; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | sub num_colors_in_nodeset{ | ||||||||
|
Subroutine
num_colors_in_nodeset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 113 | 0 | my $self = shift; | |||||||||
| 114 | 0 | return scalar ($self->colors_in_nodeset(@_)); | |||||||||
| 115 | } | ||||||||||
| 116 | 11 | ▶ | sub colors_in_nodeset{ | ||||||||
|
Subroutine
colors_in_nodeset: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 117 | 11 | my ($self, $nodeset) = @_; | |||||||||
| 118 | 11 | my %colors; | |||||||||
| 119 | 11 | for my $node ($nodeset->nodes){ | |||||||||
| 120 | 25 | my $stone = $self->at_node($node); | |||||||||
| 121 | 25 | ▶ | next unless $stone; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 25 | $colors{$stone}++; | |||||||||
| 123 | } | ||||||||||
| 124 | 11 | return keys %colors; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 36 | ▶ | sub captures{ | ||||||||
|
Subroutine
captures: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 128 | 36 | my ($self,$color) = @_; | |||||||||
| 129 | 36 | ▶ | if($color){return $self->_captures->{$color} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 8 | return $self->_captures; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 4 | ▶ | sub delta_to{ | ||||||||
|
Subroutine
delta_to: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 134 | 4 | my ($self, $to) = @_; | |||||||||
| 135 | 4 | my $delta = $self->rulemap->delta($self,$to); | |||||||||
| 136 | 4 | return $delta; | |||||||||
| 137 | # my %changes; | ||||||||||
| 138 | # {board}, {turn}, {captures} | ||||||||||
| 139 | } | ||||||||||
| 140 | 1 | ▶ | sub delta_from{ | ||||||||
|
Subroutine
delta_from: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 141 | 1 | my ($self,$from) = @_; | |||||||||
| 142 | 1 | return $from->delta_to($self); | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 6 | 1; | |||||||||
| 146 | |||||||||||
| 147 | __END__ | ||||||||||