… | |
… | |
14 | |
14 | |
15 | =head2 EXPORTED CONSTANTS |
15 | =head2 EXPORTED CONSTANTS |
16 | |
16 | |
17 | Marker types for each board position (ORed together): |
17 | Marker types for each board position (ORed together): |
18 | |
18 | |
19 | MARK_TRIANGLE # triangle mark |
19 | MARK_TRIANGLE # triangle mark |
20 | MARK_SQUARE # square mark |
20 | MARK_SQUARE # square mark |
21 | MARK_CIRCLE # circle mark |
21 | MARK_CIRCLE # circle mark |
22 | MARK_CROSS # cross mark |
22 | MARK_CROSS # cross mark |
23 | MARK_SMALL_B # small stone, used for scoring or marking |
23 | MARK_SMALL_B # small stone, used for scoring or marking |
24 | MARK_SMALL_W # small stone, used for scoring or marking |
24 | MARK_SMALL_W # small stone, used for scoring or marking |
25 | MARK_B # normal black stone |
25 | MARK_B # normal black stone |
26 | MARK_W # normal whit stone |
26 | MARK_W # normal whit stone |
27 | MARK_GRAYED # in conjunction with MARK_[BW], grays the stone |
27 | MARK_GRAYED # in conjunction with MARK_[BW], grays the stone |
|
|
28 | MARK_SMALL_GRAYED # in conjunction with MARK_SMALL_[BW], grays the stone |
28 | MARK_LABEL # a text label |
29 | MARK_LABEL # a text label |
29 | MARK_HOSHI # this is a hoshi point (not used much) |
30 | MARK_HOSHI # this is a hoshi point (not used much) |
30 | MARK_MOVE # this is a regular move |
31 | MARK_MOVE # this is a regular move |
31 | MARK_KO # this is a ko position |
32 | MARK_KO # this is a ko position |
32 | MARK_REDRAW # ignored, can be used for your own purposes |
33 | MARK_REDRAW # ignored, can be used for your own purposes |
33 | |
34 | |
34 | COLOUR_WHITE # guarenteed to be 0 |
35 | COLOUR_WHITE # guarenteed to be 0 |
35 | COLOUR_BLACK # guarenteed to be 1 |
36 | COLOUR_BLACK # guarenteed to be 1 |
36 | |
37 | |
37 | MOVE_HANDICAP # used as "x-coordinate" for handicap moves |
38 | MOVE_HANDICAP # used as "x-coordinate" for handicap moves |
38 | MOVE_PASS # can be used as "x-coordinate" for pass moves |
39 | MOVE_PASS # can be used as "x-coordinate" for pass moves |
39 | |
40 | |
40 | =head2 METHODS |
41 | =head2 METHODS |
41 | |
42 | |
42 | =over 4 |
43 | =over 4 |
43 | |
44 | |
… | |
… | |
52 | |
53 | |
53 | our $VERSION = '1.0'; |
54 | our $VERSION = '1.0'; |
54 | |
55 | |
55 | our @EXPORT = qw( |
56 | our @EXPORT = qw( |
56 | MARK_TRIANGLE MARK_SQUARE MARK_CIRCLE MARK_SMALL_B MARK_SMALL_W MARK_B |
57 | MARK_TRIANGLE MARK_SQUARE MARK_CIRCLE MARK_SMALL_B MARK_SMALL_W MARK_B |
57 | MARK_W MARK_GRAYED MARK_MOVE MARK_LABEL MARK_HOSHI MARK_KO MARK_CROSS |
58 | MARK_W MARK_GRAYED MARK_SMALL_GRAYED MARK_MOVE MARK_LABEL MARK_HOSHI MARK_KO MARK_CROSS |
58 | MARK_REDRAW |
59 | MARK_REDRAW |
59 | COLOUR_BLACK COLOUR_WHITE |
60 | COLOUR_BLACK COLOUR_WHITE |
60 | MOVE_HANDICAP MOVE_PASS |
61 | MOVE_HANDICAP MOVE_PASS |
61 | ); |
62 | ); |
62 | |
63 | |
63 | # marker types for each board position (ORed together) |
64 | # marker types for each board position (ORed together) |
64 | |
65 | |
65 | sub MARK_TRIANGLE (){ 0x0001 } |
66 | sub MARK_TRIANGLE (){ 0x0001 } |
66 | sub MARK_SQUARE (){ 0x0002 } |
67 | sub MARK_SQUARE (){ 0x0002 } |
67 | sub MARK_CIRCLE (){ 0x0004 } |
68 | sub MARK_CIRCLE (){ 0x0004 } |
68 | sub MARK_SMALL_B (){ 0x0008 } # small stone, used for scoring or marking |
69 | sub MARK_SMALL_B (){ 0x0008 } # small stone, used for scoring or marking |
69 | sub MARK_SMALL_W (){ 0x0010 } # small stone, used for scoring or marking |
70 | sub MARK_SMALL_W (){ 0x0010 } # small stone, used for scoring or marking |
70 | sub MARK_B (){ 0x0020 } # normal black stone |
71 | sub MARK_B (){ 0x0020 } # normal black stone |
71 | sub MARK_W (){ 0x0040 } # normal whit stone |
72 | sub MARK_W (){ 0x0040 } # normal whit stone |
72 | sub MARK_GRAYED (){ 0x0080 } # in conjunction with MARK_[BW], grays the stone |
73 | sub MARK_GRAYED (){ 0x0080 } # in conjunction with MARK_[BW], grays the stone |
|
|
74 | sub MARK_SMALL_GRAYED (){ 0x0100 } |
73 | sub MARK_LABEL (){ 0x0100 } |
75 | sub MARK_LABEL (){ 0x0200 } |
74 | sub MARK_HOSHI (){ 0x0200 } # this is a hoshi point (not used much) |
76 | sub MARK_HOSHI (){ 0x0400 } # this is a hoshi point (not used much) |
75 | sub MARK_MOVE (){ 0x0400 } # this is a regular move |
77 | sub MARK_MOVE (){ 0x0800 } # this is a regular move |
76 | sub MARK_KO (){ 0x0800 } # this is a ko position |
78 | sub MARK_KO (){ 0x1000 } # this is a ko position |
77 | sub MARK_CROSS (){ 0x1000 } |
79 | sub MARK_CROSS (){ 0x2000 } |
78 | sub MARK_REDRAW (){ 0x8000 } |
80 | sub MARK_REDRAW (){ 0x8000 } |
79 | |
81 | |
80 | sub COLOUR_WHITE (){ 0 } |
82 | sub COLOUR_WHITE (){ 0 } |
81 | sub COLOUR_BLACK (){ 1 } |
83 | sub COLOUR_BLACK (){ 1 } |
82 | |
84 | |
83 | sub MOVE_PASS (){ undef } |
85 | sub MOVE_PASS (){ undef } |
84 | sub MOVE_HANDICAP (){ -2 } |
86 | sub MOVE_HANDICAP (){ -2 } |
85 | |
87 | |
86 | =item my $board = new $size |
88 | =item my $board = new $size |
87 | |
89 | |
88 | Creates a new empty board of the given size. |
90 | Creates a new empty board of the given size. |
89 | |
91 | |
… | |
… | |
252 | |
254 | |
253 | if ($set & MARK_MOVE) { |
255 | if ($set & MARK_MOVE) { |
254 | $$_ &= ~$mark_symbols for @{ $self->{unmark} || [] }; |
256 | $$_ &= ~$mark_symbols for @{ $self->{unmark} || [] }; |
255 | @{ $self->{unmark} } = $space; |
257 | @{ $self->{unmark} } = $space; |
256 | |
258 | |
|
|
259 | # remark the space, in case the move was on the same spot as the |
|
|
260 | # old mark |
|
|
261 | $$space |= $set; |
|
|
262 | |
257 | unless (${ $_->[5] ||= \my $hint }) { |
263 | unless (${ $_->[5] ||= \my $hint }) { |
258 | my ($own, $opp) = |
264 | my ($own, $opp) = |
259 | $set & MARK_B |
265 | $set & MARK_B |
260 | ? (MARK_B, MARK_W) |
266 | ? (MARK_B, MARK_W) |
261 | : (MARK_W, MARK_B); |
267 | : (MARK_W, MARK_B); |
… | |
… | |
280 | ${ $_->[5] } ||= !(@capture || @suicide); |
286 | ${ $_->[5] } ||= !(@capture || @suicide); |
281 | |
287 | |
282 | if (@suicide) { |
288 | if (@suicide) { |
283 | $self->{board}[$_->[0]][$_->[1]] = 0 |
289 | $self->{board}[$_->[0]][$_->[1]] = 0 |
284 | for @suicide; |
290 | for @suicide; |
|
|
291 | # count suicides as other sides stones |
|
|
292 | $self->{captures}[$opp == MARK_B ? COLOUR_BLACK : COLOUR_WHITE] += @suicide; |
285 | |
293 | |
286 | } elsif (!@suicide && @capture == 1) { |
294 | } elsif (!@suicide && @capture == 1) { |
287 | # possible ko. now check liberties on placed stone |
295 | # possible ko. now check liberties on placed stone |
288 | |
296 | |
289 | my $libs; |
297 | my $libs; |