Games:...g2ASCII(3pm)

πŸ“¦
version 4.252 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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: 19
  • doubleDigits => 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: 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) β€” 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, $y into whatever coordinate system your Games::Go::Sgf2Dg::Diagram object is using. the default diaCoords takes 1-based $x, $y and 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 β€” if file is defined, the ASCII diagram gets dumped into that target. the target can be any one of these:
    • filename β€” the filename gets opened using IO::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 by IO::File->new, or a \*FILE descriptor. 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 the print method (below) with a reference to the Dg2ASCII object 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 the diaCoords option (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 $text directly to file as defined at new time. and whether or not file was defined, print accumulates the $text for later retrieval with converted. multitasking queen. πŸ‘‘
  • my $ascii = $dg2ascii->converted ($replacement) β€” returns the entire ASCII diagram converted so far for the Dg2ASCII object. if $replacement is 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 a Games::Go::Sgf2Dg::Diagram into ASCII. if file was defined in the new method, 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 $text into 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 closes file if 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