ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Games-Go-SimpleBoard/SimpleBoard.pm
(Generate patch)

Comparing Games-Go-SimpleBoard/SimpleBoard.pm (file contents):
Revision 1.10 by root, Wed Jun 25 20:49:38 2008 UTC vs.
Revision 1.13 by elmex, Thu Jul 24 08:50:53 2008 UTC

99=cut 99=cut
100 100
101sub new { 101sub new {
102 my $class = shift; 102 my $class = shift;
103 my $size = shift; 103 my $size = shift;
104
105 unless ($size > 0) {
106 Carp::croak ("no board size given!");
107 }
104 108
105 bless { 109 bless {
106 max => $size - 1, 110 max => $size - 1,
107 size => $size, 111 size => $size,
108 board => [map [(0) x $size], 1 .. $size], 112 board => [map [(0) x $size], 1 .. $size],
272 276
273 $suicide += $self->capture ($own, $x, $y); 277 $suicide += $self->capture ($own, $x, $y);
274 278
275 ${ $_->[5] } ||= !(@capture || $suicide); 279 ${ $_->[5] } ||= !(@capture || $suicide);
276 280
281 if ($suicide) {
282 $self->{board}[$x][$y] = 0
283
277 if (!$suicide && @capture == 1) { 284 } elsif (!$suicide && @capture == 1) {
278 # possible ko. now check liberties on placed stone 285 # possible ko. now check liberties on placed stone
279 286
280 my $libs; 287 my $libs;
281 288
282 $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp); 289 $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp);
311sub is_valid_move { 318sub is_valid_move {
312 my ($self, $colour, $x, $y, $may_suicide) = @_; 319 my ($self, $colour, $x, $y, $may_suicide) = @_;
313 320
314 my $board = $self->{board}; 321 my $board = $self->{board};
315 322
316 return if $board->[$x][$y] & (MARK_B | MARK_W | MARK_KO); 323 return if $board->[$x][$y] & (MARK_B | MARK_W | MARK_KO)
324 && !($board->[$x][$y] & MARK_GRAYED);
317 325
318 if ($may_suicide) { 326 if ($may_suicide) {
319 return 1; 327 return 1;
320 } else { 328 } else {
321 my ($own, $opp) = $colour == COLOUR_BLACK 329 my ($own, $opp) = $colour == COLOUR_BLACK

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines