… | |
… | |
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_SMALL_B # small stone, used for scoring or marking |
23 | MARK_SMALL_B # small stone, used for scoring or marking |
23 | MARK_SMALL_W # small stone, used for scoring or marking |
24 | MARK_SMALL_W # small stone, used for scoring or marking |
24 | MARK_B # normal black stone |
25 | MARK_B # normal black stone |
25 | MARK_W # normal whit stone |
26 | MARK_W # normal whit stone |
26 | MARK_GRAYED # in conjunction with MARK_[BW], grays the stone |
27 | MARK_GRAYED # in conjunction with MARK_[BW], grays the stone |
… | |
… | |
71 | sub MARK_GRAYED (){ 0x0080 } # in conjunction with MARK_[BW], grays the stone |
72 | sub MARK_GRAYED (){ 0x0080 } # in conjunction with MARK_[BW], grays the stone |
72 | sub MARK_LABEL (){ 0x0100 } |
73 | sub MARK_LABEL (){ 0x0100 } |
73 | sub MARK_HOSHI (){ 0x0200 } # this is a hoshi point (not used much) |
74 | sub MARK_HOSHI (){ 0x0200 } # this is a hoshi point (not used much) |
74 | sub MARK_MOVE (){ 0x0400 } # this is a regular move |
75 | sub MARK_MOVE (){ 0x0400 } # this is a regular move |
75 | sub MARK_KO (){ 0x0800 } # this is a ko position |
76 | sub MARK_KO (){ 0x0800 } # this is a ko position |
|
|
77 | sub MARK_CIRCLE (){ 0x1000 } |
76 | sub MARK_REDRAW (){ 0x8000 } |
78 | sub MARK_REDRAW (){ 0x8000 } |
77 | |
79 | |
78 | sub COLOUR_BLACK (){ 0 } |
80 | sub COLOUR_BLACK (){ 0 } |
79 | sub COLOUR_WHITE (){ 1 } |
81 | sub COLOUR_WHITE (){ 1 } |
80 | |
82 | |
… | |
… | |
149 | =item $hint = $board->update ([update-structures...]) |
151 | =item $hint = $board->update ([update-structures...]) |
150 | |
152 | |
151 | Each update-structure itself is also an array-ref: |
153 | Each update-structure itself is also an array-ref: |
152 | |
154 | |
153 | [$x, $y, $clr, $set, $label, $hint] # update or move |
155 | [$x, $y, $clr, $set, $label, $hint] # update or move |
154 | [MOVE_HANDICAP, $handicap] # black move, set handicap |
156 | [MOVE_HANDICAP, $handicap] # black move, setup handicap |
155 | [MOVE_PASS] # pass |
157 | [MOVE_PASS] # pass |
156 | [] # also pass |
158 | [] # also pass (deprecated!) |
157 | |
159 | |
158 | It changes the board or executes a move, by first clearing the bits |
160 | It changes the board or executes a move, by first clearing the bits |
159 | specified in C<$clr>, then setting bits specified in C<$set>. |
161 | specified in C<$clr>, then setting bits specified in C<$set>. |
160 | |
162 | |
161 | If C<$set> includes C<MARK_LABEL>, the label text must be given in |
163 | If C<$set> includes C<MARK_LABEL>, the label text must be given in |
162 | C<$label>. |
164 | C<$label>. |
163 | |
165 | |
164 | If C<$set> contains C<MARK_MOVE>, then a circle symbol will be placed on |
166 | If C<$set> contains C<MARK_MOVE>, then a circle symbol will be placed |
165 | this coordinate only if this is the last move done (which is useful for a |
167 | at this coordinate. Also, surrounded stones will be removed from the |
166 | move marker). |
168 | board and (simple) Kos are detected and marked with square symbols and |
|
|
169 | C<MARK_KO>. The circle and square markings are removed with the next |
|
|
170 | update that uses C<MARK_MOVE>, so this flag is suited well for marking, |
|
|
171 | well, moves. Note that you can make invalid "moves" (such as suicide) and |
|
|
172 | C<update> will try to cope with it. You can use C<is_valid_move> to avoid |
|
|
173 | making illegal moves. |
167 | |
174 | |
168 | For handicap "moves", currently only board sizes 9, 13 and 19 are |
175 | For handicap "moves", currently only board sizes 9, 13 and 19 are |
169 | supported and only handicap values from 2 to 9. The placement follows the |
176 | supported and only handicap values from 2 to 9. The placement follows the |
170 | IGS rules, if you want other placements, you have to set it up yourself. |
177 | IGS rules, if you want other placements, you have to set it up yourself. |
171 | |
178 | |
172 | This function modifies the hint member of the specified path to speed up |
179 | This function modifies the C<$hint> member of the specified structure |
173 | repeated board generation and updates with the same update structures. |
180 | to speed up repeated board generation and updates with the same update |
|
|
181 | structures. |
174 | |
182 | |
175 | If the hint member is a reference the scalar pointed to by the reference |
183 | If the hint member is a reference the scalar pointed to by the reference |
176 | is updated instead. |
184 | is updated instead. |
177 | |
185 | |
178 | If all this hint member thing is unclear, just ignore it and specify it |
186 | If all this hint member thing is confusing, just ignore it and specify |
179 | as C<undef> or leave it out of the array entirely. Do make sure that you |
187 | it as C<undef> or leave it out of the array entirely. Do make sure that |
180 | keep your update structures around, however, as regenerating a full board |
188 | you keep your update structures around as long as previous updates don't |
181 | position from hinted update structures is I<much> faster then recreating |
189 | change, however, as regenerating a full board position from hinted |
182 | it from fresh update structures. |
190 | update structures is I<much> faster then recreating it from fresh update |
|
|
191 | structures. |
183 | |
192 | |
184 | Example, make two silly moves: |
193 | Example, make two silly moves: |
185 | |
194 | |
186 | $board->update ([[0, 18, -1, MARK_B|MARK_MOVE], |
195 | $board->update ([[0, 18, -1, MARK_B | MARK_MOVE], |
187 | [0, 17, -1, MARK_W|MARK_MOVE]]); |
196 | [0, 17, -1, MARK_W | MARK_MOVE]]); |
188 | |
197 | |
189 | =cut |
198 | =cut |
190 | |
199 | |
191 | our %HANDICAP_COORD = ( |
200 | our %HANDICAP_COORD = ( |
192 | 9 => [2, 4, 6], |
201 | 9 => [2, 4, 6], |
193 | 13 => [3, 6, 9], |
202 | 13 => [3, 6, 9], |
194 | 19 => [3, 9, 15], |
203 | 19 => [3, 9, 15], |
195 | ); |
204 | ); |
196 | our %HANDICAP_XY = ( |
205 | our %HANDICAP_XY = ( |
197 | 2 => [qw(0,2 2,0 )], |
206 | 2 => [qw(0,2 2,0 )], |
198 | 3 => [qw(0,2 2,0 2,2 )], |
207 | 3 => [qw(0,2 2,0 0,0 )], |
199 | 4 => [qw(0,2 2,0 2,2 0,0 )], |
208 | 4 => [qw(0,2 2,0 0,0 2,2 )], |
200 | 5 => [qw(0,2 2,0 2,2 0,0 1,1)], |
209 | 5 => [qw(0,2 2,0 0,0 2,2 1,1)], |
201 | 6 => [qw(0,2 2,0 2,2 0,0 0,1 2,1 )], |
210 | 6 => [qw(0,2 2,0 0,0 2,2 0,1 2,1 )], |
202 | 7 => [qw(0,2 2,0 2,2 0,0 0,1 2,1 1,1)], |
211 | 7 => [qw(0,2 2,0 0,0 2,2 0,1 2,1 1,1)], |
203 | 8 => [qw(0,2 2,0 2,2 0,0 0,1 2,1 1,0 1,2 )], |
212 | 8 => [qw(0,2 2,0 0,0 2,2 0,1 2,1 1,0 1,2 )], |
204 | 9 => [qw(0,2 2,0 2,2 0,0 0,1 2,1 1,0 1,2 1,1)], |
213 | 9 => [qw(0,2 2,0 0,0 2,2 0,1 2,1 1,0 1,2 1,1)], |
205 | ); |
214 | ); |
206 | |
215 | |
207 | sub update { |
216 | sub update { |
208 | my ($self, $path) = @_; |
217 | my ($self, $path) = @_; |
209 | |
218 | |
… | |
… | |
293 | } |
302 | } |
294 | |
303 | |
295 | =item $board->is_valid_move ($colour, $x, $y[, $may_suicide]) |
304 | =item $board->is_valid_move ($colour, $x, $y[, $may_suicide]) |
296 | |
305 | |
297 | Returns true if the move of the given colour on the given coordinates is |
306 | Returns true if the move of the given colour on the given coordinates is |
298 | valid or not. |
307 | valid or not. Kos are taken into account as long as they are marked with |
|
|
308 | C<MARK_KO>. Suicides are invalid unless C<$may_suicide> is true (e.g. for |
|
|
309 | new zealand rules) |
299 | |
310 | |
300 | =cut |
311 | =cut |
301 | |
312 | |
302 | sub is_valid_move { |
313 | sub is_valid_move { |
303 | my ($self, $colour, $x, $y, $may_suicide) = @_; |
314 | my ($self, $colour, $x, $y, $may_suicide) = @_; |