Games::Go::Dg2ASCII3pm
Perl extension to convert games::go::diagrams to ascii diagrams
Usage
use Games::Go::Dg2ASCII
my $dg2ascii = B<Games::Go::Dg2ASCII-E<gt>new> (options);my $ascii = $dg2ascii->convertDiagram($diagram);
Overview
A Games::Go::Dg2ASCII object converts a Games::Go::Diagram object into ASCII diagrams.
Methods
- my $dg2ascii =
Games::Go::Dg2ASCII->new(?options?) -
A
newGames::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.
diaCoords=> sub { # convert $x, $y to Games::Go::Diagram coordinates }-
This callback defines a subroutine to convert coordinates from
$x,$yto whatever coordinates are used in the Games::Go::Diagram object. The defaultdiaCoordsconverts 1-based$x,$yto the same coordinates used in SGF 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("$x$y"); }, # concatenate two letters
file=> 'filename' | $descriptor | \$string | \@array-
If
fileis defined, the ASCII 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 ASCII diagram is written into the file.
- descriptor
-
A file descriptor as returned by IO::File->new, or a \*FILE descriptor. The ASCII diagram is written into the file.
- reference to a string scalar
-
The ASCII diagram is concatenated to the end of the string.
- reference to an array
-
The ASCII diagram is split on "\n" and each line is pushed onto the array.
Default: undef
print=> sub { my ($dg2ascii, @lines) = @_; ... }-
A user defined subroutine to replace the default printing method. This callback is called from the
printmethod (below) with the reference to theDg2ASCIIobject and a list of lines that are part of the ASCII diagram lines.
- $dg2tex->
configure(option => value, ?...?) -
Change Dg2TeX options from values passed at
newtime.
- $dg2ascii->
print($text ? , ... ?) -
prints the input$textdirectly tofileas defined atnewtime. Whether or notfilewas defined,printaccumulates the$textfor later retrieval withconverted.
- my $ascii = $dg2ascii->
converted($replacement) -
Returns the entire ASCII diagram converted so far for the
Dg2ASCIIobject. If$replacementis defined, the accumulated ASCII is replaced by$replacement.
- $dg2ascii->
comment($comment ? , ... ?) -
Inserts the comment character (which is nothing for ASCII) in front of each line of each comment and
prints it tofile.
- my $dg2ascii->
convertDiagram($diagram) -
Converts a Games::Go::Diagram into ASCII. If
filewas defined in thenewmethod, the ASCII is dumped into thefile. In any case, the ASCII is returned as a string scalar.
- my $ascii = $dg2ascii->
convertText($text) -
Converts
$textinto ASCII 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.
- $title = $dg2ascii->
convertProperties(\%sgfHash) -
convertPropertiestakes a reference to a hash of properties as extracted from an SGF file. Each hash key is a property ID and the hash value is a reference to an array of property values:$hash->{propertyId}->[values]. The following SGF properties are recognized:- GN GameName
- EV EVent
- RO ROund
- PW PlayerWhite
- WR WhiteRank
- PB PlayerBlack
- BR BlackRank
- DT DaTe
- PC PlaCe
- GC GameComment
- KM KoMi
- RE REsult
- TM 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.
- $dg2ascii->
close -
prints any final text to the diagram (currently none) and closes the dg2ascii object. Also closesfileif appropriate.
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.
Releases
7 releases since Debian 4.0 (Etch); the text changed 2 times.