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

File Contents

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