… | |
… | |
130 | |
130 | |
131 | my $max = $self->{max}; |
131 | my $max = $self->{max}; |
132 | |
132 | |
133 | while (@nodes) { |
133 | while (@nodes) { |
134 | my ($x, $y) = @{pop @nodes}; |
134 | my ($x, $y) = @{pop @nodes}; |
|
|
135 | |
135 | unless ($seen{$x,$y}++) { |
136 | unless ($seen{$x,$y}++) { |
136 | if ($board->[$x][$y] & $mark) { |
137 | if ($board->[$x][$y] & $mark) { |
137 | push @found, [$x, $y]; |
138 | push @found, [$x, $y]; |
138 | |
139 | |
139 | push @nodes, [$x-1, $y] unless $seen{$x-1, $y} || $x <= 0; |
140 | push @nodes, [$x-1, $y] unless $seen{$x-1, $y} || $x <= 0; |
… | |
… | |
257 | my ($own, $opp) = |
258 | my ($own, $opp) = |
258 | $set & MARK_B |
259 | $set & MARK_B |
259 | ? (MARK_B, MARK_W) |
260 | ? (MARK_B, MARK_W) |
260 | : (MARK_W, MARK_B); |
261 | : (MARK_W, MARK_B); |
261 | |
262 | |
262 | my (@capture, $suicide); |
263 | my (@capture, @suicide); |
263 | |
264 | |
264 | push @capture, $self->capture ($opp, $x-1, $y) if $x > 0 && $board->[$x-1][$y] & $opp; |
265 | push @capture, $self->capture ($opp, $x-1, $y) if $x > 0 && $board->[$x-1][$y] & $opp; |
265 | push @capture, $self->capture ($opp, $x+1, $y) if $x < $self->{max} && $board->[$x+1][$y] & $opp; |
266 | push @capture, $self->capture ($opp, $x+1, $y) if $x < $self->{max} && $board->[$x+1][$y] & $opp; |
266 | push @capture, $self->capture ($opp, $x, $y-1) if $y > 0 && $board->[$x][$y-1] & $opp; |
267 | push @capture, $self->capture ($opp, $x, $y-1) if $y > 0 && $board->[$x][$y-1] & $opp; |
267 | push @capture, $self->capture ($opp, $x, $y+1) if $y < $self->{max} && $board->[$x][$y+1] & $opp; |
268 | push @capture, $self->capture ($opp, $x, $y+1) if $y < $self->{max} && $board->[$x][$y+1] & $opp; |
… | |
… | |
272 | # remove captured stones |
273 | # remove captured stones |
273 | $self->{captures}[$own == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @capture; |
274 | $self->{captures}[$own == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @capture; |
274 | $self->{board}[$_->[0]][$_->[1]] = 0 |
275 | $self->{board}[$_->[0]][$_->[1]] = 0 |
275 | for @capture; |
276 | for @capture; |
276 | |
277 | |
277 | $suicide += $self->capture ($own, $x, $y); |
278 | push @suicide, $self->capture ($own, $x, $y); |
278 | |
279 | |
279 | ${ $_->[5] } ||= !(@capture || $suicide); |
280 | ${ $_->[5] } ||= !(@capture || @suicide); |
280 | |
281 | |
281 | if ($suicide) { |
282 | if (@suicide) { |
282 | $self->{board}[$x][$y] = 0 |
283 | $self->{board}[$_->[0]][$_->[1]] = 0 |
|
|
284 | for @suicide; |
283 | |
285 | |
284 | } elsif (!$suicide && @capture == 1) { |
286 | } elsif (!@suicide && @capture == 1) { |
285 | # possible ko. now check liberties on placed stone |
287 | # possible ko. now check liberties on placed stone |
286 | |
288 | |
287 | my $libs; |
289 | my $libs; |
288 | |
290 | |
289 | $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp); |
291 | $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp); |