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.9 by root, Wed Jun 25 20:11:33 2008 UTC vs.
Revision 1.13 by elmex, Thu Jul 24 08:50:53 2008 UTC

100 100
101sub new { 101sub new {
102 my $class = shift; 102 my $class = shift;
103 my $size = shift; 103 my $size = shift;
104 104
105 unless ($size > 0) {
106 Carp::croak ("no board size given!");
107 }
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],
109 captures => [0, 0], # captures 113 captures => [0, 0], # captures
110 #timer => [], 114 #timer => [],
111 #score => [], 115 #score => [],
112 @_, 116 @_,
113 unmark => [],
114 }, $class 117 }, $class
115} 118}
116 119
117# inefficient and primitive, I hear you say? 120# inefficient and primitive, I hear you say?
118# well... you are right :) 121# well... you are right :)
220 223
221 for (@$path) { 224 for (@$path) {
222 my ($x, $y, $clr, $set, $label) = @$_; 225 my ($x, $y, $clr, $set, $label) = @$_;
223 226
224 if (!defined $x) { 227 if (!defined $x) {
228 $$_ &= ~$mark_symbols for @{ delete $self->{unmark} || [] };
225 # pass 229 # pass
226 230
227 } elsif ($x == MOVE_HANDICAP) { 231 } elsif ($x == MOVE_HANDICAP) {
232 $$_ &= ~$mark_symbols for @{ delete $self->{unmark} || [] };
233
228 # $y = #handicap stones 234 # $y = #handicap stones
229 my $c = $HANDICAP_COORD{$self->{size}} 235 my $c = $HANDICAP_COORD{$self->{size}}
230 or Carp::croak "$self->{size}: illegal board size for handicap"; 236 or Carp::croak "$self->{size}: illegal board size for handicap";
231 my $h = $HANDICAP_XY{$y} 237 my $h = $HANDICAP_XY{$y}
232 or Carp::croak "$y: illegal number of handicap stones"; 238 or Carp::croak "$y: illegal number of handicap stones";
242 $$space = $$space & ~$clr | $set; 248 $$space = $$space & ~$clr | $set;
243 249
244 $self->{label}[$x][$y] = $label if $set & MARK_LABEL; 250 $self->{label}[$x][$y] = $label if $set & MARK_LABEL;
245 251
246 if ($set & MARK_MOVE) { 252 if ($set & MARK_MOVE) {
247 $$_ &= ~$mark_symbols for @{ $self->{unmark} }; 253 $$_ &= ~$mark_symbols for @{ $self->{unmark} || [] };
248 @{ $self->{unmark} } = $space; 254 @{ $self->{unmark} } = $space;
249 255
250 unless (${ $_->[5] ||= \my $hint }) { 256 unless (${ $_->[5] ||= \my $hint }) {
251 my ($own, $opp) = 257 my ($own, $opp) =
252 $set & MARK_B 258 $set & MARK_B
270 276
271 $suicide += $self->capture ($own, $x, $y); 277 $suicide += $self->capture ($own, $x, $y);
272 278
273 ${ $_->[5] } ||= !(@capture || $suicide); 279 ${ $_->[5] } ||= !(@capture || $suicide);
274 280
281 if ($suicide) {
282 $self->{board}[$x][$y] = 0
283
275 if (!$suicide && @capture == 1) { 284 } elsif (!$suicide && @capture == 1) {
276 # possible ko. now check liberties on placed stone 285 # possible ko. now check liberties on placed stone
277 286
278 my $libs; 287 my $libs;
279 288
280 $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp); 289 $libs++ if $x > 0 && !($board->[$x-1][$y] & $opp);
309sub is_valid_move { 318sub is_valid_move {
310 my ($self, $colour, $x, $y, $may_suicide) = @_; 319 my ($self, $colour, $x, $y, $may_suicide) = @_;
311 320
312 my $board = $self->{board}; 321 my $board = $self->{board};
313 322
314 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);
315 325
316 if ($may_suicide) { 326 if ($may_suicide) {
317 return 1; 327 return 1;
318 } else { 328 } else {
319 my ($own, $opp) = $colour == COLOUR_BLACK 329 my ($own, $opp) = $colour == COLOUR_BLACK

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines