ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Games-Go-SGF-Grove/Grove.pm
Revision: 1.1
Committed: Sun Jul 20 19:21:28 2008 UTC (15 years, 11 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Games::Go::SGF::Grove - SGF I/O
4
5 =head1 SYNOPSIS
6
7 use Games::Go::SGF::Grove;
8 # to be written
9
10 =head1 DESCRIPTION
11
12 # to be written
13
14 =over 4
15
16 =cut
17
18 package Games::Go::SGF::Grove;
19
20 use base Exporter;
21
22 use utf8;
23
24 $VERSION = 0.1;
25
26 no warnings;
27
28 package Games::Go::SGF::Grove::Parser;
29
30 my $ws = qr{[\x00-\x20]*}s;
31 my $property; # property => propertyinfo
32
33 sub new {
34 my $class = shift;
35 bless { @_ }, $class;
36 }
37
38 sub error {
39 my ($self, $error) = @_;
40
41 my $tail = substr $self->{sgf}, pos $self->{sgf}, 32;
42 $tail =~ s/[\x00-\x1f]+/ /g;
43
44 die "$error (at '$tail')";
45 }
46
47 sub parse {
48 my ($self, $sgf) = @_;
49
50 # correct lines
51 if ($sgf =~ /[^\015\012]\015/) {
52 $sgf =~ s/\015\012?/\n/g;
53 } else {
54 $sgf =~ s/\012\015?/\n/g;
55 }
56
57 $self->{sgf} = $sgf;
58
59 $self->{FF} = 1;
60 $self->{CA} = 'ISO-8859-1';
61 $self->{GM} = 1;
62
63 my @trees;
64
65 eval {
66 while ($self->{sgf} =~ /\G$ws(?=\()/sgoc) {
67 push @trees, $self->GameTree;
68 }
69 };
70
71 die $@ if $@;
72
73 \@trees
74 }
75
76 sub GameTree {
77 my ($self) = @_;
78
79 $self->{sgf} =~ /\G$ws\(/sgoc
80 or $self->error ("GameTree does not start with '('");
81
82 my $nodes = $self->Sequence;
83
84 while ($self->{sgf} =~ /\G$ws(?=\()/sgoc) {
85 push @{$nodes->[-1]{children}}, $self->GameTree;
86 }
87 $self->{sgf} =~ /\G$ws\)/sgoc
88 or $self->error ("GameTree does not end with ')'");
89
90 $nodes
91 }
92
93 sub Sequence {
94 my ($self) = @_;
95
96 my (@nodes, $node, $name, $value);
97
98 while ($self->{sgf} =~ /\G$ws;/goc) {
99 push @nodes, $node = {};
100 # Node
101 while ($self->{sgf} =~ /\G$ws([A-Z]+)/goc) {
102 # Property
103 $name = $1;
104
105 while ($self->{sgf} =~ /\G$ws\[((?:[^\\\]]*|\\.)*)\]/sgoc) {
106 # PropValue
107 $value = $1;
108 if (defined (my $prop = $property->{$name})) {
109 my (@val) = $prop->{in}->($self, $value, $prop);
110
111 if ($prop->{is_list}) {
112 push @{$node->{$name}}, @val
113 } else {
114 $node->{$name} = $val[0];
115 }
116 } else {
117 warn "unknown property '$name', will be saved unchanged.";
118 $node->{$name} = $value;
119 }
120 }
121 }
122 }
123
124 \@nodes
125 }
126
127 #############################################################################
128
129 =head2 Property Type Structure
130
131 A property type is a hash like this:
132
133 {
134 name => "SQ",
135 group => {
136 name => "Markup properties",
137 restrictions => "CR, MA, SL, SQ and TR points must be unique, ...",
138 },
139 related => "TR, CR, LB, SL, AR, MA, LN",
140 function => "Marks the given points with a square.\nPoints must be unique.",
141 propertytype => "-",
142 propvalue => "list of point"
143 is_list => 1,
144 }
145
146 =cut
147
148
149 {
150 my ($group, $name, $value, $prop);
151
152 my (%char2coord, %coord2char);
153
154 {
155 my @coord = ("a" .. "z", "A" .. "Z");
156 for (0.. $#coord) {
157 $char2coord{ $coord[$_] } = $_;
158 $coord2char{ $_ } = $coord[$_];
159 }
160 }
161
162 sub _parsetype {
163 for (shift) {
164 if (s/e?list of //) {
165 $prop->{is_list} = 1;
166 return _parsetype($_);
167 } elsif (s/composed (\S+)\s+(?:':'\s+)?(\S+)//) {
168 my ($i, $o) = ($1, $2);
169 my ($i1, $o1, $i2, $o2) = (_parsetype($i), _parsetype($o));
170 return (
171 sub {
172 if ($_[1] =~ /^((?:[^\\:]+|\\.)*)(?::(.*))$/s) {
173 # or $_[0]->error ("'Compose' ($i:$o) expected, got '$_[1]'");
174 my ($l, $r) = ($1, $2);
175
176 [
177 $i1->($_[0], $l),
178 defined $r ? $i2->($_[0], $r) : undef,
179 ],
180 } else {
181 # yes, this is not according to standard, but lets handle it somehow anyway
182 [ $i1->($_[0], $l) ]
183 }
184 },
185 sub {
186 $o1->($_[0], $_[1][0])
187 . (defined $_[1][1]
188 ? ":" . $o1->($_[0], $_[1][0])
189 : ""),
190 },
191 );
192 } elsif (s/double//) {
193 return (
194 sub {
195 $_[1] =~ /^[12]$/
196 or $self->error ("'Double' (1|2) expected, got '$_[1]'");
197 $_[1]
198 },
199 sub {
200 $_[1]
201 },
202 );
203 } elsif (s/color//) {
204 return (
205 sub {
206 $_[1] =~ /^[BW]$/i
207 or $self->error ("'Color' (B|W) expected, got '$_[1]'");
208 lc $_[1]
209 },
210 sub {
211 uc $_[1]
212 },
213 );
214 } elsif (s/none//) {
215 return (
216 sub {
217 $_[1] =~ /^$/i
218 or $self->error ("'None' expected, got '$_[1]'");
219 undef
220 },
221 sub {
222 "",
223 },
224 );
225 } elsif (s/point// || s/move// || s/stone//) {
226 return (
227 sub {
228 if ($_[2]->{is_list}) {
229 if ($_[1] =~ /^([^:]+):(.*)$/) {
230 my ($ul, $dr) = ($1, $2);
231 my ($x1, $y1) = map $char2coord{$_}, split //, $ul;
232 my ($x2, $y2) = map $char2coord{$_}, split //, $dr;
233 my @stones;
234 for (my $d = $x1; $d < $x2; $d++) {
235 for (my $i = $y1; $i < $y2; $i++) {
236 push @stones, [$d, $i];
237 }
238 }
239 return @stones;
240 }
241 }
242 $_[1] =~ /^(.)(.)$/
243 ? [ $char2coord{$1}, $char2coord{$2} ]
244 : []
245 },
246 sub {
247 die;
248 },
249 );
250 } elsif (s/real//) {
251 return (
252 sub {
253 $_[1] =~ /^[+-]?[0-9]*\.?[0-9]*$/i
254 or $self->error ("'Real' expected, got '$_[1]'");
255 $_[1]+0,
256 },
257 sub {
258 $_[1]+0,
259 },
260 );
261 } elsif (s/number//) {
262 return (
263 sub {
264 $_[1] =~ /^[+-]?[0-9]*$/i
265 or $self->error ("'Number' expected, got '$_[1]'");
266 $_[1]+0,
267 },
268 sub {
269 int $_[1],
270 },
271 );
272 } elsif (s/text//) {
273 return (
274 sub {
275 $_[1],
276 },
277 sub {
278 die;
279 },
280 );
281 } elsif (s/simpletext//i) {
282 return (
283 sub {
284 $_[1],
285 },
286 sub {
287 die;
288 },
289 );
290 } else {
291 die "FATAL: garbled DATA section, unknown type '$_'";
292
293 }
294 }
295 }
296
297 while (<DATA>) {
298 if (/^(\S+):\t(.*)/) {
299 if ($name eq "Restrictions") {
300 $group->{restrictions} = $value;
301 } elsif ($name eq "Property") {
302 $property->{$value} =
303 $prop = {
304 name => $value,
305 group => $group,
306 };
307 } elsif ($name ne "") {
308 $prop->{lc $name} = $value;
309 if ($name eq "Propvalue") {
310 ($prop->{in}, $prop->{out}) = _parsetype $value;
311 }
312 }
313 $name = $1;
314 $value = $2;
315 } elsif (/^\t\t(.*)/) {
316 $value .= "\n$1";
317 } elsif (/(\S.*)/) {
318 $group = {
319 name => $1,
320 };
321 } elsif (/^$/) {
322 # nop
323 } else {
324 die "FATAL: DATA section garbled\n";
325 }
326 }
327 }
328
329 1;
330
331 =back
332
333 =head1 AUTHOR
334
335 Marc Lehmann <schmorp@schmorp.de>
336 Robin Redeker <elmex@ta-sa.org>
337
338 =cut
339
340 # now node descriptions follow
341
342 __DATA__
343 Move properties
344
345 Property: B
346 Propvalue: move
347 Propertytype: move
348 Function: Execute a black move. This is one of the most used properties
349 in actual collections. As long as
350 the given move is syntactically correct it should be executed.
351 It doesn't matter if the move itself is illegal
352 (e.g. recapturing a ko in a Go game).
353 Have a look at how to execute a Go-move.
354 B and W properties must not be mixed within a node.
355 Related: W, KO
356
357 Property: KO
358 Propvalue: none
359 Propertytype: move
360 Function: Execute a given move (B or W) even it's illegal. This is
361 an optional property, SGF viewers themselves should execute
362 ALL moves. It's purpose is to make it easier for other
363 applications (e.g. computer-players) to deal with illegal
364 moves. A KO property without a black or white move within
365 the same node is illegal.
366 Related: W, B
367
368 Property: MN
369 Propvalue: number
370 Propertytype: move
371 Function: Sets the move number to the given value, i.e. a move
372 specified in this node has exactly this move-number. This
373 can be useful for variations or printing.
374 Related: B, W, FG, PM
375
376 Property: W
377 Propvalue: move
378 Propertytype: move
379 Function: Execute a white move. This is one of the most used properties
380 in actual collections. As long as
381 the given move is syntactically correct it should be executed.
382 It doesn't matter if the move itself is illegal
383 (e.g. recapturing a ko in a Go game).
384 Have a look at how to execute a Go-move.
385 B and W properties must not be mixed within a node.
386 Related: B, KO
387
388 Setup properties
389 Restrictions: AB, AW and AE must have unique points, i.e. it is illegal to place different colors on the same point within one node.
390 AB, AW and AE values which don't change the board, e.g. placing a black stone with AB[] over a black stone that's already there, is bad style. Applications may want to delete these values and issue a warning.
391
392 Property: AB
393 Propvalue: list of stone
394 Propertytype: setup
395 Function: Add black stones to the board. This can be used to set up
396 positions or problems. Adding is done by 'overwriting' the
397 given point with black stones. It doesn't matter what
398 was there before. Adding a stone doesn't make any prisoners
399 nor any other captures (e.g. suicide). Thus it's possible
400 to create illegal board positions.
401 Points used in stone type must be unique.
402 Related: AW, AE, PL
403
404 Property: AE
405 Propvalue: list of point
406 Propertytype: setup
407 Function: Clear the given points on the board. This can be used
408 to set up positions or problems. Clearing is done by
409 'overwriting' the given points, so that they contain no
410 stones. It doesn't matter what was there before.
411 Clearing doesn't count as taking prisoners.
412 Points must be unique.
413 Related: AB, AW, PL
414
415 Property: AW
416 Propvalue: list of stone
417 Propertytype: setup
418 Function: Add white stones to the board. This can be used to set up
419 positions or problems. Adding is done by 'overwriting' the
420 given points with white stones. It doesn't matter what
421 was there before. Adding a stone doesn't make any prisoners
422 nor any other captures (e.g. suicide). Thus it's possible
423 to create illegal board positions.
424 Points used in stone type must be unique.
425 Related: AB, AE, PL
426
427 Property: PL
428 Propvalue: color
429 Propertytype: setup
430 Function: PL tells whose turn it is to play. This can be used when
431 setting up positions or problems.
432 Related: AE, AB, AW
433
434 Node annotation properties
435
436 Property: C
437 Propvalue: text
438 Propertytype: -
439 Function: Provides a comment text for the given node. The purpose of
440 providing both a node name and a comment is to have a short
441 identifier like "doesn't work" or "Dia. 15" that can be
442 displayed directly with the properties of the node, even if
443 the comment is turned off or shown in a separate window.
444 See text-type for more info.
445 Related: N, ST, V, UC, DM, HO
446
447 Property: DM
448 Propvalue: double
449 Propertytype: -
450 Function: The position is even. SGF viewers should display a
451 message. This property may indicate main variations in
452 opening libraries (joseki) too. Thus DM[2] indicates an
453 even result for both players and that this is a main
454 variation of this joseki/opening.
455 This property must not be mixed with UC, GB or GW
456 within a node.
457 Related: UC, GW, GB
458
459 Property: GB
460 Propvalue: double
461 Propertytype: -
462 Function: Something good for black. SGF viewers should display a
463 message. The property is not related to any specific place
464 on the board, but marks the whole node instead.
465 GB must not be mixed with GW, DM or UC within a node.
466 Related: GW, C, UC, DM
467
468 Property: GW
469 Propvalue: double
470 Propertytype: -
471 Function: Something good for white. SGF viewers should display a
472 message. The property is not related to any specific place
473 on the board, but marks the whole node instead.
474 GW must not be mixed with GB, DM or UC within a node.
475 Related: GB, C, UC, DM
476
477 Property: HO
478 Propvalue: double
479 Propertytype: -
480 Function: Node is a 'hotspot', i.e. something interesting (e.g.
481 node contains a game-deciding move).
482 SGF viewers should display a message.
483 The property is not related to any specific place
484 on the board, but marks the whole node instead.
485 Sophisticated applications could implement the navigation
486 command next/previous hotspot.
487 Related: GB, GW, C, UC, DM
488
489 Property: N
490 Propvalue: simpletext
491 Propertytype: -
492 Function: Provides a name for the node. For more info have a look at
493 the C-property.
494 Related: C, ST, V
495
496 Property: UC
497 Propvalue: double
498 Propertytype: -
499 Function: The position is unclear. SGF viewers should display a
500 message. This property must not be mixed with DM, GB or GW
501 within a node.
502 Related: DM, GW, GB
503
504 Property: V
505 Propvalue: real
506 Propertytype: -
507 Function: Define a value for the node. Positive values are good for
508 black, negative values are good for white.
509 The interpretation of particular values is game-specific.
510 In Go, this is the estimated score.
511 Related: C, N, RE
512
513 Move annotation properties
514 Restrictions: Move annotation properties without a move (B[] or W[]) within the same node are senseless and therefore illegal. Applications should delete such properties and issue a warning.
515 BM, TE, DO and IT are mutual exclusive, i.e. they must not be mixed within a single node.
516
517 Property: BM
518 Propvalue: double
519 Propertytype: move
520 Function: The played move is bad.
521 Viewers should display a message.
522 Related: TE, DO, IT
523
524 Property: DO
525 Propvalue: none
526 Propertytype: move
527 Function: The played move is doubtful.
528 Viewers should display a message.
529 Related: BM, TE, IT
530
531 Property: IT
532 Propvalue: none
533 Propertytype: move
534 Function: The played move is interesting.
535 Viewers should display a message.
536 Related: BM, DO, TE
537
538 Property: TE
539 Propvalue: double
540 Propertytype: move
541 Function: The played move is a tesuji (good move).
542 Viewers should display a message.
543 Related: BM, DO, IT
544
545 Markup properties
546 Restrictions: CR, MA, SL, SQ and TR points must be unique, i.e. it's illegal to have two or more of these markups on the same point within a node.
547
548 Property: AR
549 Propvalue: list of composed point point
550 Propertytype: -
551 Function: Viewers should draw an arrow pointing FROM the first point
552 TO the second point.
553 It's illegal to specify the same arrow twice,
554 e.g. (Go) AR[aa:bb][aa:bb]. Different arrows may have the same
555 starting or ending point though.
556 It's illegal to specify a one point arrow, e.g. AR[cc:cc]
557 as it's impossible to tell into which direction the
558 arrow points.
559 Related: TR, CR, LB, SL, MA, SQ, LN
560
561 Property: CR
562 Propvalue: list of point
563 Propertytype: -
564 Function: Marks the given points with a circle.
565 Points must be unique.
566 Related: TR, MA, LB, SL, AR, SQ, LN
567
568 Property: DD
569 Propvalue: elist of point
570 Propertytype: inherit
571 Function: Dim (grey out) the given points.
572 DD[] clears any setting, i.e. it undims everything.
573 Related: VW
574
575 Property: LB
576 Propvalue: list of composed point simpletext
577 Propertytype: -
578 Function: Writes the given text on the board. The text should be
579 centered around the given point. Note: there's no longer
580 a restriction to the length of the text to be displayed.
581 Have a look at the FF4 example file on possibilities
582 to display long labels (pictures five and six).
583 Points must be unique.
584 Related: TR, CR, MA, SL, AR, SQ, LN
585
586 Property: LN
587 Propvalue: list of composed point point
588 Propertytype: -
589 Function: Applications should draw a simple line form one point
590 to the other.
591 It's illegal to specify the same line twice,
592 e.g. (Go) LN[aa:bb][aa:bb]. Different lines may have the same
593 starting or ending point though.
594 It's illegal to specify a one point line, e.g. LN[cc:cc].
595 Related: TR, CR, MA, SL, AR, SQ, LB
596
597
598 Property: MA
599 Propvalue: list of point
600 Propertytype: -
601 Function: Marks the given points with an 'X'.
602 Points must be unique.
603 Related: TR, CR, LB, SL, AR, SQ, LN
604
605 Property: SL
606 Propvalue: list of point
607 Propertytype: -
608 Function: Selected points. Type of markup unknown
609 (though SGB inverts the colors of the given points).
610 Points must be unique.
611 Related: TR, CR, LB, MA, AR, LN
612
613 Property: SQ
614 Propvalue: list of point
615 Propertytype: -
616 Function: Marks the given points with a square.
617 Points must be unique.
618 Related: TR, CR, LB, SL, AR, MA, LN
619
620 Property: TR
621 Propvalue: list of point
622 Propertytype: -
623 Function: Marks the given points with a triangle.
624 Points must be unique.
625 Related: MA, CR, LB, SL, AR, LN
626
627 Root properties
628
629 Property: AP
630 Propvalue: composed simpletext simpletext
631 Propertytype: root
632 Function: Provides the name and version number of the application used
633 to create this gametree.
634 The name should be unique and must not be changed for
635 different versions of the same program.
636 The version number itself may be of any kind, but the format
637 used must ensure that by using an ordinary string-compare,
638 one is able to tell if the version is lower or higher
639 than another version number.
640 Here's the list of known applications and their names:
641
642 Application System Name
643 --------------------------- ----------- --------------------
644 [CGoban:1.6.2] Unix CGoban
645 [Hibiscus:2.1] Windows 95 Hibiscus Go Editor
646 [IGS:5.0] Internet Go Server
647 [Many Faces of Go:10.0] Windows 95 The Many Faces of Go
648 [MGT:?] DOS/Unix MGT
649 [NNGS:?] Unix No Name Go Server
650 [Primiview:3.0] Amiga OS3.0 Primiview
651 [SGB:?] Macintosh Smart Game Board
652 [SmartGo:1.0] Windows SmartGo
653
654 Related: FF, GM, SZ, ST, CA
655
656 Property: CA
657 Propvalue: simpletext
658 Propertytype: root
659 Function: Provides the used charset for SimpleText and Text type.
660 Default value is 'ISO-8859-1' aka 'Latin1'.
661 Only charset names (or their aliases) as specified in RFC 1345
662 (or updates thereof) are allowed.
663 Basically this field uses the same names as MIME messages in
664 their 'charset=' field (in Content-Type).
665 RFC's can be obtained via FTP from DS.INTERNIC.NET,
666 NIS.NSF.NET, WUARCHIVE.WUSTL.EDU, SRC.DOC.IC.AC.UK
667 or FTP.IMAG.FR.
668 Related: FF, C, text type
669
670 Property: FF
671 Propvalue: number (range: 1-4)
672 Propertytype: root
673 Function: Defines the used file format. For difference between those
674 formats have a look at the history of SGF.
675 Default value: 1
676 Applications must be able to deal with different file formats
677 within a collection.
678 Related: GM, SZ, ST, AP, CA
679
680 Property: GM
681 Propvalue: number (range: 1-16)
682 Propertytype: root
683 Function: Defines the type of game, which is stored in the current
684 gametree. The property should help applications
685 to reject games, they cannot handle.
686 Valid numbers are: Go = 1, Othello = 2, chess = 3,
687 Gomoku+Renju = 4, Nine Men's Morris = 5, Backgammon = 6,
688 Chinese chess = 7, Shogi = 8, Lines of Action = 9,
689 Ataxx = 10, Hex = 11, Jungle = 12, Neutron = 13,
690 Philosopher's Football = 14, Quadrature = 15, Trax = 16,
691 Tantrix = 17, Amazons = 18, Octi = 19, Gess = 20.
692 Default value: 1
693 Different kind of games may appear within a collection.
694 Related: FF, SZ, ST, AP, CA
695
696 Property: ST
697 Propvalue: number (range: 0-3)
698 Propertytype: root
699 Function: Defines how variations should be shown (this is needed to
700 synchronize the comments with the variations). If ST is omitted
701 viewers should offer the possibility to change the mode online.
702 Basically most programs show variations in two ways:
703 as markup on the board (if the variation contains a move)
704 and/or as a list (in a separate window).
705 The style number consists two options.
706 1) show variations of successor node (children) (value: 0)
707 show variations of current node (siblings) (value: 1)
708 affects markup & list
709 2) do board markup (value: 0)
710 no (auto-) board markup (value: 2)
711 affects markup only.
712 Using no board markup could be used in problem collections
713 or if variations are marked by subsequent properties.
714 Viewers should take care, that the automatic variation
715 board markup DOESN'T overwrite any markup of other
716 properties.
717 The final number is calculated by adding the values of each
718 option. Example: 3 = no board markup/variations of current node
719 1 = board markup/variations of current node
720 Default value: 0
721 Related: C, FF, GM, SZ, AP, CA
722
723 Property: SZ
724 Propvalue: composed number number
725 Propertytype: root
726 Function: Defines the size of the board. If only a single value
727 is given, the board is a square; with two numbers given,
728 rectangular boards are possible.
729 If a rectangular board is specified, the first number specifies
730 the number of columns, the second provides the number of rows.
731 Square boards must not be defined using the compose type
732 value: e.g. SZ[19:19] is illegal.
733 The valid range for SZ is any size greater or equal to 1x1.
734 For Go games the maximum size is limited to 52x52.
735 Default value: game specific
736 for Go: 19 (square board)
737 for Chess: 8 (square board)
738 Different board sizes may appear within a collection.
739 See move-/point-type for more info.
740 Related: FF, GM, ST, AP, CA
741
742 Game info properties
743
744 Property: AN
745 Propvalue: simpletext
746 Propertytype: game-info
747 Function: Provides the name of the person, who made the annotations
748 to the game.
749 Related: US, SO, CP
750
751 Property: BR
752 Propvalue: simpletext
753 Propertytype: game-info
754 Function: Provides the rank of the black player.
755 For Go (GM[1]) the following format is recommended:
756 "..k" or "..kyu" for kyu ranks and
757 "..d" or "..dan" for dan ranks.
758 Go servers may want to add '?' for an uncertain rating and
759 '*' for an established rating.
760 Related: PB, BT, WR
761
762 Property: BT
763 Propvalue: simpletext
764 Propertytype: game-info
765 Function: Provides the name of the black team, if game was part of a
766 team-match (e.g. China-Japan Supermatch).
767 Related: PB, PW, WT
768
769 Property: CP
770 Propvalue: simpletext
771 Propertytype: game-info
772 Function: Any copyright information (e.g. for the annotations) should
773 be included here.
774 Related: US, SO, AN
775
776 Property: DT
777 Propvalue: simpletext
778 Propertytype: game-info
779 Function: Provides the date when the game was played.
780 It is MANDATORY to use the ISO-standard format for DT.
781 Note: ISO format implies usage of the Gregorian calendar.
782 Syntax:
783 "YYYY-MM-DD" year (4 digits), month (2 digits), day (2 digits)
784 Do not use other separators such as "/", " ", "," or ".".
785 Partial dates are allowed:
786 "YYYY" - game was played in YYYY
787 "YYYY-MM" - game was played in YYYY, month MM
788 For games that last more than one day: separate other dates
789 by a comma (no spaces!); following shortcuts may be used:
790 "MM-DD" - if preceded by YYYY-MM-DD, YYYY-MM, MM-DD, MM or DD
791 "MM" - if preceded by YYYY-MM or MM
792 "DD" - if preceded by YYYY-MM-DD, MM-DD or DD
793 Shortcuts acquire the last preceding YYYY and MM (if
794 necessary).
795 Note: interpretation is done from left to right.
796 Examples:
797 1996-05,06 = played in May,June 1996
798 1996-05-06,07,08 = played on 6th,7th,8th May 1996
799 1996,1997 = played in 1996 and 1997
800 1996-12-27,28,1997-01-03,04 = played on 27th,28th
801 of December 1996 and on 3rd,4th January 1997
802 Note: it's recommended to use shortcuts whenever possible,
803 e.g. 1997-05-05,06 instead of 1997-05-05,1997-05-06
804 Related: EV, RO, PC, RU, RE, TM
805
806 Property: EV
807 Propvalue: simpletext
808 Propertytype: game-info
809 Function: Provides the name of the event (e.g. tournament).
810 Additional information (e.g. final, playoff, ..)
811 shouldn't be included (see RO).
812 Related: GC, RO, DT, PC, RU, RE, TM
813
814 Property: GN
815 Propvalue: simpletext
816 Propertytype: game-info
817 Function: Provides a name for the game. The name is used to
818 easily find games within a collection.
819 The name should therefore contain some helpful information
820 for identifying the game. 'GameName' could also be used
821 as the file-name, if a collection is split into
822 single files.
823 Related: GC, EV, DT, PC, RO, ID
824
825 Property: GC
826 Propvalue: text
827 Propertytype: game-info
828 Function: Provides some extra information about the following game.
829 The intend of GC is to provide some background information
830 and/or to summarize the game itself.
831 Related: GN, ON, AN, CP
832
833 Property: ON
834 Propvalue: simpletext
835 Propertytype: game-info
836 Function: Provides some information about the opening played
837 (e.g. san-ren-sei, Chinese fuseki, etc.).
838 Related: GN, GC
839
840 Property: OT
841 Propvalue: simpletext
842 Propertytype: game-info
843 Function: Describes the method used for overtime (byo-yomi).
844 Examples: "5 mins Japanese style, 1 move / min",
845 "25 moves / 10 min".
846 Related: TM, BL, WL, OB, OW
847
848 Property: PB
849 Propvalue: simpletext
850 Propertytype: game-info
851 Function: Provides the name of the black player.
852 Related: PW, BT, WT
853
854 Property: PC
855 Propvalue: simpletext
856 Propertytype: game-info
857 Function: Provides the place where the games was played.
858 Related: EV, DT, RO, RU, RE, TM
859
860 Property: PW
861 Propvalue: simpletext
862 Propertytype: game-info
863 Function: Provides the name of the white player.
864 Related: PB, BT, WT
865
866 Property: RE
867 Propvalue: simpletext
868 Propertytype: game-info
869 Function: Provides the result of the game. It is MANDATORY to use the
870 following format:
871 "0" (zero) or "Draw" for a draw (jigo),
872 "B+" ["score"] for a black win and
873 "W+" ["score"] for a white win
874 Score is optional (some games don't have a score e.g. chess).
875 If the score is given it has to be given as a real value,
876 e.g. "B+0.5", "W+64", "B+12.5"
877 Use "B+R" or "B+Resign" and "W+R" or "W+Resign" for a win by
878 resignation. Applications must not write "Black resigns".
879 Use "B+T" or "B+Time" and "W+T" or "W+Time" for a win on time,
880 "B+F" or "B+Forfeit" and "W+F" or "W+Forfeit" for a win by
881 forfeit,
882 "Void" for no result or suspended play and
883 "?" for an unknown result.
884
885 Related: EV, DT, PC, RO, RU, TM
886
887 Property: RO
888 Propvalue: simpletext
889 Propertytype: game-info
890 Function: Provides round-number and type of round. It should be
891 written in the following way: RO[xx (tt)], where xx is the
892 number of the round and (tt) the type:
893 final, playoff, league, ...
894 Related: EV, DT, PC, RU, RE, TM
895
896 Property: RU
897 Propvalue: simpletext
898 Propertytype: game-info
899 Function: Provides the used rules for this game.
900 Because there are many different rules, SGF requires
901 mandatory names only for a small set of well known rule sets.
902 Note: it's beyond the scope of this specification to give an
903 exact specification of these rule sets.
904 Mandatory names for Go (GM[1]):
905 "AGA" (rules of the American Go Association)
906 "GOE" (the Ing rules of Goe)
907 "Japanese" (the Nihon-Kiin rule set)
908 "NZ" (New Zealand rules)
909
910 Related: EV, DT, PC, RO, RE, TM
911
912 Property: SO
913 Propvalue: simpletext
914 Propertytype: game-info
915 Function: Provides the name of the source (e.g. book, journal, ...).
916 Related: US, AN, CP
917
918 Property: TM
919 Propvalue: real
920 Propertytype: game-info
921 Function: Provides the time limits of the game.
922 The time limit is given in seconds.
923 Related: EV, DT, PC, RO, RU, RE
924
925 Property: US
926 Propvalue: simpletext
927 Propertytype: game-info
928 Function: Provides the name of the user (or program), who entered
929 the game.
930 Related: SO, AN, CP
931
932 Property: WR
933 Propvalue: simpletext
934 Propertytype: game-info
935 Function: Provides the rank of the white player. For recommended
936 format see BR.
937 Related: PW, WT, BR
938
939 Property: WT
940 Propvalue: simpletext
941 Propertytype: game-info
942 Function: Provide the name of the white team, if game was part of a
943 team-match (e.g. China-Japan Supermatch).
944 Related: PB, PW, BT
945
946 Timing properties
947
948 Property: BL
949 Propvalue: real
950 Propertytype: move
951 Function: Time left for black, after the move was made.
952 Value is given in seconds.
953 Related: TM, OT, WL, OB, OW
954
955 Property: OB
956 Propvalue: number
957 Propertytype: move
958 Function: Number of black moves left (after the move of this node was
959 played) to play in this byo-yomi period.
960 Related: TM, OT, BL, WL, OW
961
962 Property: OW
963 Propvalue: number
964 Propertytype: move
965 Function: Number of white moves left (after the move of this node was
966 played) to play in this byo-yomi period.
967 Related: TM, OT, BL, WL, OB
968
969 Property: WL
970 Propvalue: real
971 Propertytype: move
972 Function: Time left for white after the move was made.
973 Value is given in seconds.
974 Related: TM, OT, BL, OB, OW
975
976 Miscellaneous properties
977
978 Property: FG
979 Propvalue: composed number SimpleText
980 Propertytype: -
981 Function: The figure property is used to divide a game into
982 different figures for printing: a new figure starts at the
983 node containing a figure property.
984 If the value is not empty then
985 - Simpletext provides a name for the diagram
986 - Number specifies some flags (for printing).
987 These flags are:
988 - coordinates on/off (value: 0/1)
989 - diagram name on/off (value: 0/2)
990 - list moves not shown in figure on/off (value: 0/4)
991 Some moves can't be shown in a diagram (e.g. ko
992 captures in Go) - these moves may be listed as text.
993 - remove captured stones on/off (value: 0/256)
994 'remove off' means: keep captured stones in the
995 diagram and don't overwrite stones played earlier -
996 this is the way diagrams are printed in books.
997 'remove on' means: capture and remove the stones from
998 the display - this is the usual viewer mode.
999 This flag is specific to Go (GM[1]).
1000 - hoshi dots on/off (value: 0/512)
1001 This flag is specific to Go (GM[1]).
1002 - Ignore flags on/off (value: 32768)
1003 If on, then all other flags should be ignored and
1004 the application should use its own defaults.
1005 The final number is calculated by summing up all flag values.
1006 E.g. 515 = coordinates and diagram name off, remove captured
1007 stones, list unshown moves, hoshi dots off;
1008 257 = coordinates off, diagram name on, list unshown moves,
1009 don't remove captured stones, hoshi dots on.
1010 (this is how diagrams are printed in e.g. Go World)
1011 Note: FG combined with VW, MN and PM are mighty tools to print
1012 and compile diagrams.
1013 Related: MN, PM, VW
1014
1015 Property: PM
1016 Propvalue: number
1017 Propertytype: inherit
1018 Function: This property is used for printing.
1019 It specifies how move numbers should be printed.
1020 0 ... don't print move numbers
1021 1 ... print move numbers as they are
1022 2 ... print 'modulo 100' move numbers
1023 This mode is usually used in books or magazines.
1024 Note: Only the first move number is calculated
1025 'modulo 100' and the obtained number is increased
1026 for each move in the diagram.
1027 E.g. A figure containing moves
1028 32-78 is printed as moves 32-78
1029 102-177 is printed as moves 2-77
1030 67-117 is printed as moves 67-117
1031 154-213 is printed as moves 54-113
1032 Default value: 1
1033 Related: MN, FG
1034
1035 Property: VW
1036 Propvalue: elist of point
1037 Propertytype: inherit
1038 Function: View only part of the board. The points listed are
1039 visible, all other points are invisible.
1040 Note: usually the point list is given in compressed
1041 format (see 'point' type)!
1042 Points have to be unique.
1043 Have a look at the picture to get an idea.
1044 VW[] clears any setting, i.e. the whole board is
1045 visible again.
1046 Related: DD, PM, FG
1047
1048 Go properties
1049 Restrictions: TW and TB points must be unique, i.e. it's illegal to list the same point in TB and TW within the same node.
1050 Gametype: 1
1051
1052 Property: HA
1053 Propvalue: number
1054 Propertytype: game-info
1055 Function: Defines the number of handicap stones (>=2).
1056 If there is a handicap, the position should be set up with
1057 AB within the same node.
1058 HA itself doesn't add any stones to the board, nor does
1059 it imply any particular way of placing the handicap stones.
1060 Related: KM, RE, RU
1061
1062 Property: KM
1063 Propvalue: real
1064 Propertytype: game-info
1065 Function: Defines the komi.
1066 Related: HA, RE, RU
1067
1068 Property: TB
1069 Propvalue: elist of point
1070 Propertytype: -
1071 Function: Specifies the black territory or area (depends on
1072 rule set used).
1073 Points must be unique.
1074 Related: TW
1075
1076 Property: TW
1077 Propvalue: elist of point
1078 Propertytype: -
1079 Function: Specifies the white territory or area (depends on
1080 rule set used).
1081 Points must be unique.
1082 Related: TB
1083
1084 Octi properties
1085 Gametype: 19
1086
1087 Property: RU (rules)
1088 Propvalue: simpletext
1089 Propertytype: game-info
1090 Function: Valid values are one major variation ("full", "fast",
1091 or "kids") followed by a colon and a comma separated
1092 elist of variations ("edgeless", "superprong", etc.).
1093
1094 The colon may be omitted if either side is empty.
1095 The default is 2-player full, no variations.
1096 The 4-player game is not currently available.
1097
1098 Property: BO (black octisquares)
1099 Propvalue: list of point
1100 Propertytype: game-info
1101 Function: The position of Black's octi squares. Black will be
1102 setup with one empty pod on each of these points.
1103 It is illegal to list the same point twice.
1104 Traditionally, Black sits at the south end of the board.
1105 Related: WO
1106
1107 Property: WO (white octisquares)
1108 Propvalue: list of point
1109 Propertytype: game-info
1110 Function: The position of White's octi squares. White will be
1111 setup with one empty pod on each of these points.
1112 It is illegal to list the same point twice.
1113 Traditionally, White sits at the north end of the board.
1114 Related: BO
1115
1116 Property: NP (number of prongs)
1117 Propvalue: number
1118 Propertytype: game-info
1119 Function: This is the number of prongs each players has at the
1120 start of the game.
1121 The default will be derived from the rules.
1122 Related: NR
1123
1124 Property: NR (number of reserve)
1125 Propvalue: number
1126 Propertytype: game-info
1127 Function: This is the number of pods in each players reserve at
1128 the start of the game.
1129 The default will be derived from the rules.
1130 Related: NP, NS
1131
1132 Property: NS (number of superprongs)
1133 Propvalue: number
1134 Propertytype: game-info
1135 Function: This is the number of superprongs each players has at
1136 the start of the game.
1137 The default will be derived from the rules.
1138 Related: NR
1139
1140 Property: AS (arrow stone)
1141 Propvalue: list of composed stone ':' point
1142 Propertytype: -
1143 Function: Most of the same restriction from AR apply.
1144 The same arrow must not occur twice; however, two arrows
1145 from different stones at the same point may have arrows
1146 to the same destination. Single point arrows are also
1147 illegal.
1148 Related: AR
1149
1150 Property: CS (circle stone)
1151 Propvalue: list of stone
1152 Propertytype: -
1153 Function: Marks the given stones, each with a circle.
1154 Related: CR
1155
1156 Property: MS (mark stone)
1157 Propvalue: list of stone
1158 Propertytype: -
1159 Function: Marks the given stones, each with an ex.
1160 Related: MA
1161
1162 Property: SS (square stone)
1163 Propvalue: list of stone
1164 Propertytype: -
1165 Function: Marks the given stones, each with a square.
1166 Related: SQ
1167
1168 Property: TS (triangle stone)
1169 Propvalue: list of stone
1170 Propertytype: -
1171 Function: Marks the given stones, each with a triangle.
1172 Related: TR
1173
1174 Property: RP (remove pod)
1175 Propvalue: list of stone
1176 Propertytype: setup
1177 Function: Removes a stone from the board.
1178 More selective than AddEmpty.
1179 Related: AE
1180
1181 Backgammon properties
1182 Gametype: 6
1183
1184 Property: CO
1185 Propvalue: simpletext
1186 Propertytype: setup
1187 Function: Set the position of the doubling cube. The value
1188 should be `b' (black), `w' (white), `c' (centred), or `n'
1189 (none -- for cubeless or Crawford games).
1190 Related: CV
1191
1192 Property: CV
1193 Propvalue: number
1194 Propertytype: setup
1195 Function: Set the value of the doubling cube. This value
1196 defaults to 1 at the beginning of the game, but a CV property
1197 should be added when setting up a position where a double has
1198 been made, or at the beginning of a money game if automatic
1199 doubles occur.
1200 Related: CP
1201
1202 Property: DI
1203 Propvalue: number
1204 Propertytype: setup
1205 Function: Set the dice without moving (this could be useful for
1206 creating problem positions, e.g. DI[31])
1207 Related: CO
1208
1209 Property: MI
1210 Propvalue: list of composed simpletext ':' simpletext
1211 Propertytype: game-info
1212 Function: Specifies information about the match the game belongs to.
1213 This property should specify a list of tag/value pairs, where
1214 the allowable tags are case-insensitive, and include:
1215
1216 length - the match length (number of points); value should
1217 be a number
1218 game - the number of this game within the match (the
1219 first game is 1); value should be a number
1220 bs - the score for Black at the start of the game;
1221 value should be a number
1222 ws - the score for White at the start of the game;
1223 value should be a number
1224
1225 Unknown tags should be ignored (a warning may be produced).
1226 The order of tags in the list is not significant. An example
1227 MI property is:
1228 MI[length:7][game:3][ws:2][bs:1]
1229 Related: EV, GN, RE, RO
1230
1231 Property: RE
1232 Propvalue: simpletext
1233 Propertytype: game-info
1234 Function: The general RE property has the following
1235 modification in backgammon games: in the case of a
1236 resignation, the value should also specify the number of
1237 points before the R(esign). Here are three example RE
1238 properties:
1239
1240 RE[B+6R] -- White resigns a backgammon on a 2
1241 cube (worth 6 points).
1242 RE[W+2Resign] -- Black resigns a gammon on a 1 cube
1243 (worth 2 points).
1244 RE[W+4] -- Black drops a redouble to 8 (note
1245 this is considered a normal loss, not
1246 a resignation).
1247 Related: RE
1248
1249 Property: RU
1250 Propvalue: simpletext
1251 Propertytype: game-info
1252 Function: Backgammon-specific values for the general RU property
1253 include the following:
1254
1255 [Crawford] -- the Crawford rule is being used in this match,
1256 although this is not the Crawford game.
1257 [Crawford:CrawfordGame] -- this IS the Crawford game.
1258 [Jacoby] -- the Jacoby rule is in use for this game.
1259 Related: RU
1260
1261 Lines of Action properties
1262 Gametype: 9
1263
1264 Property: AS
1265 Propvalue: SimpleText
1266 Propertytype: -
1267 Function: Adding stones - the color of the player who is adding
1268 stones to the board. The valid strings are 'Black', 'White'
1269 or 'None'. The puropse of this property is to define a
1270 board position where the human is expected to continue placing
1271 stones on the board through some user interface.
1272
1273 Property: IP
1274 Propvalue: SimpleText
1275 Propertytype: game-info
1276 Function: Designates the initial position in the game to be
1277 displayed by the viewer.
1278 The only value currently supported is 'End', which causes
1279 the viewer to initially display the final position of the game.
1280 The default is to display the position after setup but before
1281 any moves.
1282
1283 Property: IY
1284 Propvalue: SimpleText
1285 Propertytype: game-info
1286 Function: Invert Y axis. Values are 'true' or 'false'.
1287 If 'true', the board should be displayed with numbers
1288 increasing in value from bottom to top of the screen.
1289 Default: 'false'
1290
1291 Property: SE
1292 Propvalue: point
1293 Propertytype: -
1294 Function: Mark the given point and up to 8 additional points,
1295 depending on where the provided point (stone) could legally
1296 move.
1297
1298 Property: SU
1299 Propvalue: SimpleText
1300 Propertytype: game-info
1301 Function: Setup type - designates the intial placement of pieces,
1302 and also the implicitly the variation on the basic rules to be
1303 employed. The currently valid values include the following
1304 strings:
1305 'Standard', 'Scrambled-eggs', 'Parachute', 'Gemma' and 'Custom'
1306 (the initial board is empty, AB and AW properties
1307 will be used to establish the starting position).
1308 Default: 'Standard'
1309 For details on the setups and rule variations, consult the
1310 LOA home pages.
1311
1312 Hex properties
1313 Gametype: 11
1314
1315 Property: IS
1316 Propvalue: list of composed SimpleText ':' SimpleText
1317 Propertytype: root
1318 Function: This property allows applications to store and read
1319 an initial viewer setting. The property value is a list of
1320 "keyword followed by ':' followed by either 'on' or 'off'".
1321 Valid keywords are:
1322 'tried' - identify future moves that have been tried?
1323 'marked' - show good/bad move markings?
1324 'lastmove' - identify the last cell played?
1325 'headings' - display column/row headings (a b.., 1 2..)?
1326 'lock' - lock the game against new moves (for analysis)?
1327 This property is allowed in the root node only.
1328 Example: IS[tried:on][lock:off][marked:off]
1329
1330 Property: IP
1331 Propvalue: SimpleText
1332 Propertytype: game-info
1333 Function: Designates the initial position that the viewer
1334 should display. It will most frequently indicate the
1335 current position of play in the game. This is necessary
1336 because future possible moves may have been explored,
1337 and the user must be able to distinguish real moves
1338 actually made from exploratory moves. More than one IP[]
1339 property in a game is illegal, and the behaviour undefined.
1340 The property value should be empty (""); it is specified
1341 as SimpleText for compatibility.
1342
1343 Amazons properties
1344 Gametype: 18
1345
1346 Property: AA
1347 Propvalue: list of point
1348 Propertytype: setup
1349 Function: Adding arrows to the board. This can be used to set up
1350 positions or problems.
1351
1352 End: this marks the end
1353