… | |
… | |
149 | =item $hint = $board->update ([update-structures...]) |
149 | =item $hint = $board->update ([update-structures...]) |
150 | |
150 | |
151 | Each update-structure itself is also an array-ref: |
151 | Each update-structure itself is also an array-ref: |
152 | |
152 | |
153 | [$x, $y, $clr, $set, $label, $hint] # update or move |
153 | [$x, $y, $clr, $set, $label, $hint] # update or move |
154 | [MOVE_HANDICAP, $handicap] # black move, set handicap |
154 | [MOVE_HANDICAP, $handicap] # black move, setup handicap |
155 | [MOVE_PASS] # pass |
155 | [MOVE_PASS] # pass |
156 | [] # also pass |
156 | [] # also pass (deprecated!) |
157 | |
157 | |
158 | It changes the board or executes a move, by first clearing the bits |
158 | 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>. |
159 | specified in C<$clr>, then setting bits specified in C<$set>. |
160 | |
160 | |
161 | If C<$set> includes C<MARK_LABEL>, the label text must be given in |
161 | If C<$set> includes C<MARK_LABEL>, the label text must be given in |
162 | C<$label>. |
162 | C<$label>. |
163 | |
163 | |
164 | If C<$set> contains C<MARK_MOVE>, then a circle symbol will be placed on |
164 | 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 |
165 | at this coordinate. Also, surrounded stones will be removed from the |
166 | move marker). |
166 | board and (simple) Kos are detected and marked with square symbols and |
|
|
167 | C<MARK_KO>. The circle and square markings are removed with the next |
|
|
168 | update that uses C<MARK_MOVE>, so this flag is suited well for marking, |
|
|
169 | well, moves. Note that you can make invalid "moves" (such as suicide) and |
|
|
170 | C<update> will try to cope with it. You can use C<is_valid_move> to avoid |
|
|
171 | making illegal moves. |
167 | |
172 | |
168 | For handicap "moves", currently only board sizes 9, 13 and 19 are |
173 | 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 |
174 | 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. |
175 | IGS rules, if you want other placements, you have to set it up yourself. |
171 | |
176 | |
172 | This function modifies the hint member of the specified path to speed up |
177 | This function modifies the C<$hint> member of the specified structure |
173 | repeated board generation and updates with the same update structures. |
178 | to speed up repeated board generation and updates with the same update |
|
|
179 | structures. |
174 | |
180 | |
175 | If the hint member is a reference the scalar pointed to by the reference |
181 | If the hint member is a reference the scalar pointed to by the reference |
176 | is updated instead. |
182 | is updated instead. |
177 | |
183 | |
178 | If all this hint member thing is unclear, just ignore it and specify it |
184 | 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 |
185 | 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 |
186 | 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 |
187 | change, however, as regenerating a full board position from hinted |
182 | it from fresh update structures. |
188 | update structures is I<much> faster then recreating it from fresh update |
|
|
189 | structures. |
183 | |
190 | |
184 | Example, make two silly moves: |
191 | Example, make two silly moves: |
185 | |
192 | |
186 | $board->update ([[0, 18, -1, MARK_B|MARK_MOVE], |
193 | $board->update ([[0, 18, -1, MARK_B | MARK_MOVE], |
187 | [0, 17, -1, MARK_W|MARK_MOVE]]); |
194 | [0, 17, -1, MARK_W | MARK_MOVE]]); |
188 | |
195 | |
189 | =cut |
196 | =cut |
190 | |
197 | |
191 | our %HANDICAP_COORD = ( |
198 | our %HANDICAP_COORD = ( |
192 | 9 => [2, 4, 6], |
199 | 9 => [2, 4, 6], |
… | |
… | |
293 | } |
300 | } |
294 | |
301 | |
295 | =item $board->is_valid_move ($colour, $x, $y[, $may_suicide]) |
302 | =item $board->is_valid_move ($colour, $x, $y[, $may_suicide]) |
296 | |
303 | |
297 | Returns true if the move of the given colour on the given coordinates is |
304 | Returns true if the move of the given colour on the given coordinates is |
298 | valid or not. |
305 | valid or not. Kos are taken into account as long as they are marked with |
|
|
306 | C<MARK_KO>. Suicides are invalid unless C<$may_suicide> is true (e.g. for |
|
|
307 | new zealand rules) |
299 | |
308 | |
300 | =cut |
309 | =cut |
301 | |
310 | |
302 | sub is_valid_move { |
311 | sub is_valid_move { |
303 | my ($self, $colour, $x, $y, $may_suicide) = @_; |
312 | my ($self, $colour, $x, $y, $may_suicide) = @_; |