Games:...g2ASCII(3pm)
π NAME π
okay so listen β Games::Go::Sgf2Dg::Dg2ASCII is a lil Perl module that takes Games::Go::Sgf2Dg::Diagram objects and turns them into ASCII diagrams. that's the whole gig, and it ate. π
β¨ SYNOPSIS β¨
use Games::Go::Sgf2Dg::Dg2ASCII
my $dg2ascii = Games::Go::Sgf2Dg::Dg2ASCII-E<gt>new (options);
my $ascii = $dg2ascii->convertDiagram($diagram);
πΈ DESCRIPTION πΈ
A Games::Go::Sgf2Dg::Dg2ASCII object converts a Games::Go::Sgf2Dg::Diagram object into ASCII diagrams. no cap, that is literally the entire description, and honestly? respect. π
π NEW π
my $dg2ascii = Games::Go::Sgf2Dg::Dg2ASCII->new (?options?)
A new Games::Go::Sgf2Dg::Dg2ASCII takes the following options, bestie β read them all, there's no skipping: π«Ά
boardSizeX => number,boardSizeY => numberβ sets the size of the board. Default:19doubleDigits => true | falseβ numbers on stones get wrapped back to 1 once they hit 100. numbers that belong to comments and diagram titles? not affected, they do their own thing. Default:falsecoords => true | falseβ generates a coordinate grid. Default:falsetopLine => number(Default:1),bottomLine => number(Default:19),leftLine => number(Default:1),rightLine => number(Default:19) β these are the edges of the board that actually get displayed. any part of the board hanging off past these numbers is simply not in the output, bye. πdiaCoords => sub { # convert $x, $y to Games::Go::Sgf2Dg::Diagram coordinates }β this callback is a subroutine you define to convert coordinates from$x,$yinto whatever coordinate system yourGames::Go::Sgf2Dg::Diagramobject is using. the defaultdiaCoordstakes 1-based$x,$yand maps them to the same coordinates SGF format files use. you only need to define this if your Diagram is on a different coordinate system, iykyk. 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
also go peek at the diaCoords method down below. π
file => 'filename' | $descriptor | \$string | \@arrayβ iffileis defined, the ASCII diagram gets dumped into that target. the target can be any one of these:filenameβ the filename gets opened usingIO::File->new. it 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 byIO::File->new, or a\*FILEdescriptor. the ASCII diagram is written into the file.- reference to a string scalar β the ASCII diagram gets concatenated onto the end of the string.
- reference to an array β the ASCII diagram is split on
"\n"and each line gets pushed onto the array.
Default: undef
print => sub { my ($dg2ascii, @lines) = @_; ... }β your own user defined subroutine to swap out the default printing method. this callback gets called from theprintmethod (below) with a reference to theDg2ASCIIobject and a list of lines that are part of the ASCII diagram lines. π
π METHODS π
$dg2tex->configure (option => value, ?...?)β change Dg2TeX options from values passed at new time.my $coord = $dg2mp->diaCoords ($x, $y)β gives you access to thediaCoordsoption (see above π). returns coordinates in the converter's coordinate system for board coordinates$x,$y. so like, say you want a specific intersection structure:
my $int = $diagram->get($dg2mp->diaCoords(3, 4));
$dg2ascii->print ($text ? , ... ?)β prints the input$textdirectly to file as defined at new time. and whether or notfilewas defined,printaccumulates the$textfor later retrieval withconverted. multitasking queen. πmy $ascii = $dg2ascii->converted ($replacement)β returns the entire ASCII diagram converted so far for theDg2ASCIIobject. if$replacementis defined, the accumulated ASCII gets replaced by$replacement.$dg2ascii->comment ($comment ? , ... ?)β inserts the comment character (which for ASCII is literally nothing) in front of each line of each comment, then prints it to file.my $dg2ascii->convertDiagram ($diagram)β converts aGames::Go::Sgf2Dg::Diagraminto ASCII. iffilewas defined in thenewmethod, the ASCII gets dumped into the file. either way, the ASCII comes back as a string scalar.
heads up bestie: labels are restricted to one character β anything after the first character just gets discarded. ποΈ
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, no notes. it's really just a place-holder for more complicated converters.
Returns the converted text. β¨
$dg2ascii->closeβ prints any final text to the diagram (currently none, so, nothing) and closes the dg2ascii object. also closesfileif appropriate. clean exit energy. π¦
π SEE ALSO π
sgf2dg(1)β Script to convert SGF format files to Go diagrams
π BUGS π
Seems unlikely. π
and that's the whole page, babe. this gem is documented as perl v5.30.0, dated 2019-10-27 β so go forth and ASCII-ify some Go boards, fr fr. ππ
π¦ where this page comes from
- debian bookworm: sgf2dg 4.252-1
- debian trixie: sgf2dg 4.252-1
- ubuntu jammy: sgf2dg 4.252-1
- ubuntu noble: sgf2dg 4.252-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms