Games:...:Dg2SL(3pm)
π Games::Go::Sgf2Dg::Dg2SL π
okay bestie, so this is a Perl thing from the Games:...:Dg2SL corner of the user-contributed Perl docs, and it's literally the glow-up machine that turns Games::Go::Sgf2Dg::Diagrams into Sensei's Library format. let's get into it π«Ά
β¨ NAME β¨
Games::Go::Sgf2Dg::Dg2SL β a Perl extension to convert Games::Go::Sgf2Dg::Diagrams to Sensei's Library format. no cap, that's the whole job description π
πΈ SYNOPSIS πΈ
use Games::Go::Sgf2Dg::Dg2SL
my $dg2sl = Games::Go::Sgf2Dg::Dg2SL->new (options);
my $sl = $dg2sl->convertDiagram($diagram);
π¦ DESCRIPTION π¦
A Games::Go::Sgf2Dg::Dg2SL object converts a Games::Go::Sgf2Dg::Diagram object into Sensei's Library diagrams (peep http://senseis.xmp.net/ if you wanna see the vibes π).
β οΈ Sensei's Library diagrams only support move numbers from 1-10, so make sure you call sgf2dg with arguments that specify a maximum of 10 moves per diagram and starting each diagram with move number 1. Example:
sgf2dg -converter SL -m 10 -n foo.sgf
Sensei's Library also doesn't support labelled stones. like, at all. so don't come for it π
An initial setup diagram is printed if the initial board isn't empty and doesn't have a handicap setup β i.e., only black stones, all of which are on hoshi points. β¨
Diagrams' extents are limited to the stones actually played, plus a margin. That is, if there are only stones in one corner, only that corner is printed, not the whole diagram. This is useful for analyses of local positions, but if the first ten moves of a real game are all in one corner β however unlikely that may be β it would produce undesirable results. π consider yourself warned.
π NEW π
my $dg2sl = Games::Go::Sgf2Dg::Dg2SL->new (?options?)
A new Games::Go::Sgf2Dg::Dg2SL takes the following options, bestie:
boardSize => numberβ Sets the size of the board. Default: 19 πcoords => true | falseβ Generates a coordinate grid. Default: falsetopLine => 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. so if you're only about that corner life, this is your moment π
diaCoords => sub { # convert $x, $y to Games::Go::Sgf2Dg::Diagram coordinates }β This callback defines a subroutine to convert coordinates from$x,$yto whatever coordinates are used in theGames::Go::Sgf2Dg::Diagramobject. 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
See also the diaCoords method below. π
file => 'filename' | $descriptor | \$string | \@arrayβ Iffileis defined, the Sensei's Library 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 Sensei's Library diagram is written into the file. ποΈ - descriptor β A file descriptor as returned by
IO::File->new, or a\*FILEdescriptor. The Sensei's Library diagram is written into the file. - reference to a string scalar β The Sensei's Library diagram is concatenated to the end of the string.
- reference to an array β The Sensei's Library diagram is split on
"\n"and each line is pushed onto the array.
- filename β The filename will be opened using
Default: undef
print => sub { my ($dg2sl, @lines) = @_; ... }β A user defined subroutine to replace the default printing method. This callback is called from theprintmethod (below) with the reference to theDg2SLobject and a list of lines that are part of the Sensei's Library diagram lines. π
π METHODS π
$dg2sl->configure (option => value, ?...?)β ChangeDg2SLoptions from values passed at new time.my $coord = $dg2mp->diaCoords ($x, $y)β Provides access to thediaCoordsoption (see above). Returns coordinates in the converter's coordinate system for board coordinates ($x,$y). For example, to get a specific intersection structure:
my $int = $diagram->get($dg2mp->diaCoords(3, 4));
$dg2sl->print ($text ? , ... ?)β prints the input$textdirectly to file as defined at new time. Whether or notfilewas defined,printaccumulates the$textfor later retrieval withconverted. π¨οΈβ¨my $sl = $dg2sl->converted ($replacement)β Returns the entire Sensei's Library diagram converted so far for theDg2SLobject. If$replacementis defined, the accumulated Sensei's Library is replaced by$replacement.$dg2sl->comment ($comment ? , ... ?)β Inserts the comment character (which is nothing for Sensei's Library π«₯) in front of each line of each comment and prints it to file.my $dg2sl->convertDiagram ($diagram)β Converts aGames::Go::Sgf2Dg::Diagraminto Sensei's Library. Iffilewas defined in the new method, the Sensei's Library is dumped into the file. In any case, the Sensei's Library is returned as a string scalar. π₯my $sl = $dg2sl->convertText ($text)β Converts$textinto Sensei's Library 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. iconic minimalism honestly
$title = $dg2sl->convertGameProps (\%sgfHash)βconvertGamePropstakes 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:GNGameNameEVEVentROROundDTDaTePWPlayerWhiteWRWhiteRankPBPlayerBlackBRBlackRankPCPlaCeKMKoMiRURUlesTMTiMeOTOverTime (byo-yomi)REREsultANANnotatorSOSourceUSUSer (entered by)CPCoPyrightGCGameComment
Both long and short property names are recognized, and all unrecognized properties are ignored with no warnings. silent treatment fr fr Note that these properties are all intended as game-level notations.
$dg2sl->closeβ prints any final text to the diagram (currently none) and closes thedg2slobject. Also closesfileif appropriate. πͺβ¨
π SEE ALSO π
sgf2dg(1)β Script to convert SGF format files to Go diagrams
π BUGS π
Seems likely. π (that's it. that's the whole bug report. she's honest.)
π AUTHOR π
Marcel Gruenauer, <marcel@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright (C) 2007 by Marcel Gruenauer.
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.
and that's the whole page bestie, slay π this was perl v5.30.0, dated 2019-10-27, from the User Contributed Perl Documentation for Games:...:Dg2SL(3pm) β go forth and diagram, you absolute main character ππ¦
π¦ 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