… | |
… | |
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; |
… | |
… | |
251 | |
252 | |
252 | if ($set & MARK_MOVE) { |
253 | if ($set & MARK_MOVE) { |
253 | $$_ &= ~$mark_symbols for @{ $self->{unmark} || [] }; |
254 | $$_ &= ~$mark_symbols for @{ $self->{unmark} || [] }; |
254 | @{ $self->{unmark} } = $space; |
255 | @{ $self->{unmark} } = $space; |
255 | |
256 | |
|
|
257 | # remark the space, in case the move was on the same spot as the |
|
|
258 | # old mark |
|
|
259 | $$space |= $set; |
|
|
260 | |
256 | unless (${ $_->[5] ||= \my $hint }) { |
261 | unless (${ $_->[5] ||= \my $hint }) { |
257 | my ($own, $opp) = |
262 | my ($own, $opp) = |
258 | $set & MARK_B |
263 | $set & MARK_B |
259 | ? (MARK_B, MARK_W) |
264 | ? (MARK_B, MARK_W) |
260 | : (MARK_W, MARK_B); |
265 | : (MARK_W, MARK_B); |
261 | |
266 | |
262 | my (@capture, $suicide); |
267 | my (@capture, @suicide); |
263 | |
268 | |
264 | push @capture, $self->capture ($opp, $x-1, $y) if $x > 0 && $board->[$x-1][$y] & $opp; |
269 | 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; |
270 | 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; |
271 | 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; |
272 | push @capture, $self->capture ($opp, $x, $y+1) if $y < $self->{max} && $board->[$x][$y+1] & $opp; |
… | |
… | |
272 | # remove captured stones |
277 | # remove captured stones |
273 | $self->{captures}[$own == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @capture; |
278 | $self->{captures}[$own == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @capture; |
274 | $self->{board}[$_->[0]][$_->[1]] = 0 |
279 | $self->{board}[$_->[0]][$_->[1]] = 0 |
275 | for @capture; |
280 | for @capture; |
276 | |
281 | |
277 | $suicide += $self->capture ($own, $x, $y); |
282 | push @suicide, $self->capture ($own, $x, $y); |
278 | |
283 | |
279 | ${ $_->[5] } ||= !(@capture || $suicide); |
284 | ${ $_->[5] } ||= !(@capture || @suicide); |
280 | |
285 | |
281 | if ($suicide) { |
286 | if (@suicide) { |
282 | $self->{board}[$x][$y] = 0 |
287 | $self->{board}[$_->[0]][$_->[1]] = 0 |
|
|
288 | for @suicide; |
|
|
289 | # count suicides as other sides stones |
|
|
290 | $self->{captures}[$opp == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @suicide; |
283 | |
291 | |
284 | } elsif (!$suicide && @capture == 1) { |
292 | } elsif (!@suicide && @capture == 1) { |
285 | # possible ko. now check liberties on placed stone |
293 | # possible ko. now check liberties on placed stone |
286 | |
294 | |
287 | my $libs; |
295 | my $libs; |
288 | |
296 | |
289 | $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp); |
297 | $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp); |