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.3 by root, Mon Jun 23 20:41:16 2008 UTC vs.
Revision 1.6 by root, Tue Jun 24 23:19:24 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines