SYNOPSIS

use Games::Go::Dg2ASCII

 my $dg2ascii = B<Games::Go::Dg2ASCII-E<gt>new> (options);
 my $ascii = $dg2ascii->convertDiagram($diagram);

DESCRIPTION

A Games::Go::Dg2ASCII object converts a Games::Go::Diagram object into \s-1ASCII\s0 diagrams.

METHODS

A new Games::Go::Dg2ASCII takes the following options:

General Dg2 Converter Options:

boardSize => number

Sets the size of the board. Default: 19

doubleDigits => true | false

Numbers on stones are wrapped back to 1 after they reach 100. Numbers associated with comments and diagram titles are not affected. Default: false

coords => true | false

Generates a coordinate grid. Default: false

topLine => number (Default: 1)
bottomLine => number (Default: 19)
leftLine => number (Default: 1)
rightLine => number (Default: 19)

The edges of the board that should be displayed. Any portion of the board that extends beyond these numbers is not included in the output. This callback defines a subroutine to convert coordinates from $x, $y to whatever coordinates are used in the Games::Go::Diagram object. The default diaCoords converts 1-based $x, $y to the same coordinates used in \s-1SGF\s0 format files. You only need to define this if you're using a different coordinate system in the Diagram. Default:

    sub { my ($x, $y) = @_;
          $x = chr($x - 1 + ord('a')); # convert 1 to 'a', etc
          $y = chr($y - 1 + ord('a'));
          return(\*(L"$x$y\*(R"); },           # concatenate two letters

If file is defined, the \s-1ASCII\s0 diagram is dumped into the target. The target can be any of:

filename

The filename will be opened using IO::File->new. The filename should include the '>' or '>>' operator as described in 'perldoc IO::File'. The \s-1ASCII\s0 diagram is written into the file.

descriptor

A file descriptor as returned by IO::File->new, or a \*FILE descriptor. The \s-1ASCII\s0 diagram is written into the file.

reference to a string scalar

The \s-1ASCII\s0 diagram is concatenated to the end of the string.

reference to an array

The \s-1ASCII\s0 diagram is split on \*(L"\n\*(R" and each line is pushed onto the array.

Default: undef

A user defined subroutine to replace the default printing method. This callback is called from the print method (below) with the reference to the Dg2ASCII object and a list of lines that are part of the \s-1ASCII\s0 diagram lines. Change Dg2TeX options from values passed at new time. prints the input $text directly to file as defined at new time. Whether or not file was defined, print accumulates the $text for later retrieval with converted. Returns the entire \s-1ASCII\s0 diagram converted so far for the Dg2ASCII object. If $replacement is defined, the accumulated \s-1ASCII\s0 is replaced by $replacement. Inserts the comment character (which is nothing for \s-1ASCII\s0) in front of each line of each comment and prints it to file. Converts a Games::Go::Diagram into \s-1ASCII\s0. If file was defined in the new method, the \s-1ASCII\s0 is dumped into the file. In any case, the \s-1ASCII\s0 is returned as a string scalar. Converts $text into \s-1ASCII\s0 code - gee, that's not very hard. In fact, this method simply returns whatever is passed to it. This is really just a place-holder for more complicated converters. Returns the converted text. convertProperties takes a reference to a hash of properties as extracted from an \s-1SGF\s0 file. Each hash key is a property \s-1ID\s0 and the hash value is a reference to an array of property values: $hash->{propertyId}->[values]. The following \s-1SGF\s0 properties are recognized:

\s-1GN\s0 GameName
\s-1EV\s0 EVent
\s-1RO\s0 ROund
\s-1PW\s0 PlayerWhite
\s-1WR\s0 WhiteRank
\s-1PB\s0 PlayerBlack
\s-1BR\s0 BlackRank
\s-1DT\s0 DaTe
\s-1PC\s0 PlaCe
\s-1GC\s0 GameComment
\s-1KM\s0 KoMi
\s-1RE\s0 REsult
\s-1TM\s0 TiMe

Both long and short property names are recognized, and all unrecognized properties are ignored with no warnings. Note that these properties are all intended as game-level notations.

prints any final text to the diagram (currently none) and closes the dg2ascii object. Also closes file if appropriate.

RELATED TO Games::Go::Dg2ASCII…

sgf2dg(1)

Script to convert \s-1SGF\s0 format files to Go diagrams

BUGS

Seems unlikely.

AUTHOR

Reid Augustin, <[email protected]>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Reid Augustin

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.