--- Games-Go-SimpleBoard/SimpleBoard.pm 2008/07/23 19:19:31 1.12 +++ Games-Go-SimpleBoard/SimpleBoard.pm 2008/07/29 10:09:53 1.18 @@ -16,26 +16,30 @@ Marker types for each board position (ORed together): - MARK_TRIANGLE # triangle mark - MARK_SQUARE # square mark - MARK_CIRCLE # circle mark - MARK_CROSS # cross mark - MARK_SMALL_B # small stone, used for scoring or marking - MARK_SMALL_W # small stone, used for scoring or marking - MARK_B # normal black stone - MARK_W # normal whit stone - MARK_GRAYED # in conjunction with MARK_[BW], grays the stone - MARK_LABEL # a text label - MARK_HOSHI # this is a hoshi point (not used much) - MARK_MOVE # this is a regular move - MARK_KO # this is a ko position - MARK_REDRAW # ignored, can be used for your own purposes + MARK_B # normal black stone + MARK_W # normal whit stone + MARK_GRAYED # in conjunction with MARK_[BW], grays the stone + + MARK_SMALL_B # small stone, used for scoring or marking + MARK_SMALL_W # small stone, used for scoring or marking + MARK_SMALL_GRAYED # in conjunction with MARK_SMALL_[BW], grays the stone + + MARK_TRIANGLE # triangle mark + MARK_SQUARE # square mark + MARK_CIRCLE # circle mark + MARK_CROSS # cross mark + + MARK_LABEL # a text label + MARK_HOSHI # this is a hoshi point (not used much) + MARK_MOVE # this is a regular move + MARK_KO # this is a ko position + MARK_REDRAW # ignored, can be used for your own purposes - COLOUR_WHITE # guarenteed to be 0 - COLOUR_BLACK # guarenteed to be 1 + COLOUR_WHITE # guaranteed to be 0 + COLOUR_BLACK # guaranteed to be 1 - MOVE_HANDICAP # used as "x-coordinate" for handicap moves - MOVE_PASS # can be used as "x-coordinate" for pass moves + MOVE_HANDICAP # used as "x-coordinate" for handicap moves + MOVE_PASS # can be used as "x-coordinate" for pass moves =head2 METHODS @@ -50,11 +54,11 @@ use base Exporter::; -our $VERSION = '1.0'; +our $VERSION = '1.01'; our @EXPORT = qw( MARK_TRIANGLE MARK_SQUARE MARK_CIRCLE MARK_SMALL_B MARK_SMALL_W MARK_B - MARK_W MARK_GRAYED MARK_MOVE MARK_LABEL MARK_HOSHI MARK_KO MARK_CROSS + MARK_W MARK_GRAYED MARK_SMALL_GRAYED MARK_MOVE MARK_LABEL MARK_HOSHI MARK_KO MARK_CROSS MARK_REDRAW COLOUR_BLACK COLOUR_WHITE MOVE_HANDICAP MOVE_PASS @@ -62,26 +66,30 @@ # marker types for each board position (ORed together) -sub MARK_TRIANGLE (){ 0x0001 } -sub MARK_SQUARE (){ 0x0002 } -sub MARK_CIRCLE (){ 0x0004 } -sub MARK_SMALL_B (){ 0x0008 } # small stone, used for scoring or marking -sub MARK_SMALL_W (){ 0x0010 } # small stone, used for scoring or marking -sub MARK_B (){ 0x0020 } # normal black stone -sub MARK_W (){ 0x0040 } # normal whit stone -sub MARK_GRAYED (){ 0x0080 } # in conjunction with MARK_[BW], grays the stone -sub MARK_LABEL (){ 0x0100 } -sub MARK_HOSHI (){ 0x0200 } # this is a hoshi point (not used much) -sub MARK_MOVE (){ 0x0400 } # this is a regular move -sub MARK_KO (){ 0x0800 } # this is a ko position -sub MARK_CROSS (){ 0x1000 } -sub MARK_REDRAW (){ 0x8000 } +sub MARK_TRIANGLE (){ 0x0001 } +sub MARK_SQUARE (){ 0x0002 } +sub MARK_CIRCLE (){ 0x0004 } +sub MARK_CROSS (){ 0x0008 } + +sub MARK_SMALL_B (){ 0x0010 } # small stone, used for scoring or marking +sub MARK_SMALL_W (){ 0x0020 } # small stone, used for scoring or marking +sub MARK_SMALL_GRAYED (){ 0x0040 } + +sub MARK_B (){ 0x0080 } # normal black stone +sub MARK_W (){ 0x0100 } # normal whit stone +sub MARK_GRAYED (){ 0x0200 } # in conjunction with MARK_[BW], grays the stone + +sub MARK_LABEL (){ 0x0400 } +sub MARK_HOSHI (){ 0x0800 } # this is a hoshi point (not used much) +sub MARK_MOVE (){ 0x1000 } # this is a regular move +sub MARK_KO (){ 0x2000 } # this is a ko position +sub MARK_REDRAW (){ 0x8000 } -sub COLOUR_WHITE (){ 0 } -sub COLOUR_BLACK (){ 1 } +sub COLOUR_WHITE (){ 0 } +sub COLOUR_BLACK (){ 1 } -sub MOVE_PASS (){ undef } -sub MOVE_HANDICAP (){ -2 } +sub MOVE_PASS (){ undef } +sub MOVE_HANDICAP (){ -2 } =item my $board = new $size @@ -132,6 +140,7 @@ while (@nodes) { my ($x, $y) = @{pop @nodes}; + unless ($seen{$x,$y}++) { if ($board->[$x][$y] & $mark) { push @found, [$x, $y]; @@ -253,13 +262,17 @@ $$_ &= ~$mark_symbols for @{ $self->{unmark} || [] }; @{ $self->{unmark} } = $space; + # remark the space, in case the move was on the same spot as the + # old mark + $$space |= $set; + unless (${ $_->[5] ||= \my $hint }) { my ($own, $opp) = $set & MARK_B ? (MARK_B, MARK_W) : (MARK_W, MARK_B); - my (@capture, $suicide); + my (@capture, @suicide); push @capture, $self->capture ($opp, $x-1, $y) if $x > 0 && $board->[$x-1][$y] & $opp; push @capture, $self->capture ($opp, $x+1, $y) if $x < $self->{max} && $board->[$x+1][$y] & $opp; @@ -274,11 +287,17 @@ $self->{board}[$_->[0]][$_->[1]] = 0 for @capture; - $suicide += $self->capture ($own, $x, $y); + push @suicide, $self->capture ($own, $x, $y); - ${ $_->[5] } ||= !(@capture || $suicide); + ${ $_->[5] } ||= !(@capture || @suicide); - if (!$suicide && @capture == 1) { + if (@suicide) { + $self->{board}[$_->[0]][$_->[1]] = 0 + for @suicide; + # count suicides as other sides stones + $self->{captures}[$opp == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @suicide; + + } elsif (!@suicide && @capture == 1) { # possible ko. now check liberties on placed stone my $libs;