summaryrefslogtreecommitdiff
path: root/obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/t-sgf.tex
diff options
context:
space:
mode:
Diffstat (limited to 'obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/t-sgf.tex')
-rw-r--r--obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/t-sgf.tex458
1 files changed, 458 insertions, 0 deletions
diff --git a/obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/t-sgf.tex b/obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/t-sgf.tex
new file mode 100644
index 0000000000..4909848d91
--- /dev/null
+++ b/obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/t-sgf.tex
@@ -0,0 +1,458 @@
+%D \module
+%D [ file=t-sgf,
+%D version=2007.09.09,
+%D title=\CONTEXT\ User Module,
+%D subtitle=Go Module,
+%D author={Zhichu Chen \& Wolfgang Schuster},
+%D date=\currentdate,
+%D copyright=Public Domain]
+
+\writestatus{loading}{Context User Module / Go Module}
+
+\unprotect
+
+%D The dead stone calculator, the board background and the
+%D stones are saved in two extra modules. The third module
+%D contains two extra conversion commands and the default setup.
+
+\usemodule[deadstone]
+\usemodule[sgf-generic]
+\usemodule[sgf-library]
+
+\useJSscripts[fld][FieldStack]
+
+\setuppagenumbering[\c!location=,\c!state=\v!stop]
+
+\setupcolors[\c!state=\v!start]
+\definecolor[boardbackground][r=1,g=.625,b=.0625]
+\definecolor[deadstonebackground][r=1,g=1,b=1]
+
+\setupinteraction
+ [\c!state=\v!start,
+ \c!focus=\v!height,
+ \c!page=\v!yes,
+ \c!openaction=\v!firstpage,
+ \c!click=\v!off]
+
+\newcounter\thegame
+\newcounter\thestep
+
+\definesymbol[\v!empty][]%
+
+\newdimen\stoneunit \stoneunit=.5632cm
+\newdimen\boardunit \boardunit=.6cm
+\newdimen\capturedunit \capturedunit=.4cm
+
+\defineoverlay[board][{\useMPgraphic{board}}]
+
+\setupinterlinespace
+ [\c!height=0,
+ \c!depth=1,
+ \c!top=0,
+ \c!bottom=0,
+ \c!line=\boardunit]
+
+%D \macros{drawboard}
+%D
+%D The main loop to draw the board with all stones and the
+%D stone numbers. The number color depends on the current
+%D stone color and on the currently placed stone.
+
+\def\drawboard
+ {\vbox{\dorecurse\boardsize
+ {\edef\boardrow{\recurselevel}%
+ \hbox{\dorecurse\boardsize
+ {\edef\boardcolumn{\recurselevel}%
+ \hbox\!!to\boardunit
+ {\hss\vbox\!!to\boardunit
+ {\vss
+ \ifcase\currentstone
+ \or\convertnumber\@@@@bdconversion\currentstone
+ \or\convertnumber\@@@@bdconversion\currentstone
+ \fi
+ \vss}\hss}%
+ \hskip-\boardunit
+ \hbox\!!to\boardunit
+ {\vbox\!!to\boardunit
+ {\hsize\boardunit
+ \vss
+ \ifhighlightlabel
+ \ifnum\currentstonenumber=\stonecount
+ \def\@@@@bdblackcolor{red}% I overload the preset values
+ \def\@@@@bdwhitecolor{red}% from the setupbaord settings!
+ \fi
+ \fi
+ \ifcase\currentstone
+ \or\hbox\!!to\hsize{\hss\doattributes{\????bd\v!black}\c!style\c!color\currentstonenumber\hss}
+ \or\hbox\!!to\hsize{\hss\doattributes{\????bd\v!white}\c!style\c!color\currentstonenumber\hss}
+ \fi
+ \vss}}}}}}}
+
+%D \macros{drawboarda,drawboardb,drawboardc}
+%D
+%D The next three macros take care of the three board alternatives
+%D and put the area for the removed stones on the left and right
+%D side or at the bottom.
+
+\def\drawboarda
+ {\increment\thestep
+ \definesymbol
+ [stone:\thegame:\thestep]
+ [{\vbox
+ {\offinterlineskip
+ \framed
+ [\c!offset=\boardunit,\c!frameoffset=\!!zeropoint,\c!strut=\v!no,
+ \c!top=\!!zeropoint,\c!bottom=\!!zeropoint,\c!depth=\!!zeropoint,
+ \c!frame=\v!off]
+ {\offinterlineskip
+ \drawboard}
+ \framed
+ [\c!frame=\v!off,
+ \c!width=\dimexpr\boardsize\boardunit+\plustwo\boardunit\relax,
+ \c!height=\numexpr\@@@@bdn*\plustwo\relax\boardunit,
+ \c!background=color,
+ \c!backgroundcolor=deadstonebackground]
+ {\vbox\!!to\vsize
+ {\vbox\!!to.5\vsize{\processdeadstones[\deadblackstones]\vfill}
+ \vbox\!!to.5\vsize{\processdeadstones[\deadwhitestones]\vfill}}}}}]}
+
+\def\drawboardb
+ {\increment\thestep
+ \definesymbol
+ [stone:\thegame:\thestep]
+ [{\hbox
+ {\framed
+ [\c!frame=\v!off,
+ \c!width=\numexpr\@@@@bdn*\plustwo\relax\boardunit,
+ \c!height=\dimexpr\boardsize\boardunit+\plustwo\boardunit\relax,
+ \c!background=color,
+ \c!backgroundcolor=deadstonebackground]%
+ {\vbox\!!to\vsize{\processdeadstones[\deadblackstones]\vfill}}%
+ \framed
+ [\c!offset=\boardunit,\c!frameoffset=\!!zeropoint,\c!strut=\v!no,
+ \c!top=\!!zeropoint,\c!bottom=\!!zeropoint,\c!depth=\!!zeropoint,
+ \c!frame=\v!off]%
+ {\offinterlineskip
+ \drawboard}%
+ \framed
+ [\c!frame=\v!off,
+ \c!width=\numexpr\@@@@bdn*\plustwo\relax\boardunit,
+ \c!height=\dimexpr\boardsize\boardunit+\plustwo\boardunit\relax,
+ \c!background=color,
+ \c!backgroundcolor=deadstonebackground]%
+ {\vbox\!!to\vsize
+ {\processdeadstones[\deadwhitestones]\vfill}}}}]}
+
+\def\drawboardc
+ {\increment\thestep
+ \definesymbol
+ [stone:\thegame:\thestep]
+ [{\framed
+ [\c!offset=\boardunit,\c!frameoffset=\!!zeropoint,\c!strut=\v!no,
+ \c!top=\!!zeropoint,\c!bottom=\!!zeropoint,\c!depth=\!!zeropoint,
+ \c!frame=\v!off]%
+ {\offinterlineskip
+ \drawboard}}]}
+
+%D \macros{processdeadstones}
+%D
+%D The removed stones in the interactive version are placed with
+%D the \tex{processdeadstones} command. It is called twice, once
+%D for the black stones and a second time for the white stones.
+
+\def\processdeadstones[#1]%
+ {\def\dodoprocessdeadstones##1:##2:##3:##4\relax
+ {\hbox\!!to\boardunit
+ {\hss\vbox\!!to\boardunit{\convertnumber\@@@@bdconversion{##3}}\hss}%
+ \hskip-\boardunit
+ \hbox\!!to\boardunit
+ {\vbox\!!to\boardunit
+ {\hsize\boardunit
+ \vss
+ \ifcase##3
+ \or\hbox\!!to\hsize{\hss\doattributes{\????bd\v!black}\c!style\c!color{##4}\hss}
+ \or\hbox\!!to\hsize{\hss\doattributes{\????bd\v!white}\c!style\c!color{##4}\hss}
+ \fi
+ \vss}}%
+ \hbox\!!to\boardunit
+ {\vbox\!!to\boardunit
+ {\vfill
+ \smallbodyfont % problems in mkiv
+ \hbox\!!to\hsize{\doattributes\????bd\c!style\c!color
+ {\sgfcharacter{##2}\Numbers{\numexpr\boardsize-##1+\plusone\relax}}\hss}
+ \vfill\vfill}}}%
+ \def\doprocessdeadstones##1%
+ {\ifdim\wd\scratchbox>\hsize
+ \hbox\!!to\hsize{\box\scratchbox\hss}%
+ \setbox\scratchbox\hbox
+ {\box\scratchbox\hbox\!!to\plustwo\boardunit{\@EA\dodoprocessdeadstones##1\relax}}%
+ \else
+ \setbox\scratchbox\hbox
+ {\box\scratchbox\hbox\!!to\plustwo\boardunit{\@EA\dodoprocessdeadstones##1\relax}}%
+ \fi}%
+ \processcommacommand[#1]\doprocessdeadstones
+ \hbox\!!to\hsize{\box\scratchbox\hss}}
+
+%D \macros{flushboard}
+%D
+%D After \tex{drawboard} with its three alternatives had drawn a board
+%D and saved it in a field we flush it with the \tex{flushboard} command.
+
+\def\flushboard
+ {\ifnum\thestep=\@@fdstart\relax
+ \definefield
+ [\v!game:\thegame:\thestep][\s!check][\v!game:\thegame]
+ [\v!stone:\thegame:\thestep,\v!empty]
+ [\v!stone:\thegame:\thestep]%
+ \else
+ \definefield
+ [\v!game:\thegame:\thestep][\s!check][\v!game:\thegame]
+ [\v!stone:\thegame:\thestep,\v!empty][\v!empty]%
+ \fi
+ \removeunwantedspaces
+ \vbox\!!to\!!zeropoint
+ {\vskip-\plusone\points\hbox\!!to\!!zeropoint{\fitfield[\v!game:\thegame:\thestep]\hss}\vss}%
+ \vskip-\baselineskip}
+
+\def\clearoverlapstatus
+ {\dorecurse\boardsize
+ {\edef\boardrow{\recurselevel}%
+ \dorecurse\boardsize
+ {\edef\boardcolumn{\recurselevel}%
+ \presetcurrentstatus{\zerocount}}}%
+ \global\let\overlaplist\empty}
+
+\def\presetcurrentstatus#1%
+ {\setxvalue{status:\boardrow:\boardcolumn}{#1}%
+ \resetvalue{overlap:\boardrow:\boardcolumn}}
+
+\def\makeoverlaplist#1%
+ {\appendtocommalist{#1}\overlaplist}
+
+\def\stonecolor#1%
+ {\@EA\@EA\@EA\@EA\@EA\@EA\@EA\firstofcurrentstone\getvalue{field:#1}\relax}
+
+\def\stonestep#1%
+ {\@EA\@EA\@EA\@EA\@EA\@EA\@EA\secondofcurrentstone\getvalue{field:#1}\relax}
+
+\def\currentstatus
+ {\getvalue{status:\boardrow:\boardcolumn}}
+
+\def\setstatus#1#2%
+ {\setevalue{status:\number#1:\number#2}}
+
+\def\setcurrentstatus
+ {\setstatus\boardrow\boardcolumn}
+
+\def\currentoverlap
+ {\getvalue{overlap:\boardrow:\boardcolumn}}
+
+\def\setoverlap#1#2%
+ {\setevalue{overlap:\number#1:\number#2}}
+
+\def\setcurrentoverlap
+ {\setoverlap\boardrow\boardcolumn}
+
+\def\dummystonebox
+ {\hbox\!!to\boardunit
+ {\hss\vbox\!!to\boardunit
+ {\vss
+ \ifcase\currentstone
+ \or\convertnumber\@@@@bdconversion\currentstone
+ \or\convertnumber\@@@@bdconversion\currentstone
+ \fi
+ \vss}%
+ \hss}%
+ \hskip-\boardunit
+ \hbox\!!to\boardunit
+ {\vbox\!!to\boardunit
+ {\hsize\boardunit
+ \vss
+ \ifcase\currentstone
+ \or\hbox\!!to\hsize{\hss\doattributes{\????bd\v!black}{\c!style}{\c!color}{\currentstonenumber}\hss}
+ \or\hbox\!!to\hsize{\hss\doattributes{\????bd\v!white}{\c!style}{\c!color}{\currentstonenumber}\hss}
+ \fi
+ \vss}}}
+
+%D \macros{adddummystone}
+%D
+%D This is a alternative for the \tex{addstone} command in the
+%D dead stone calculator. It saves only the position and states
+%D of every field in a macro and make a listentry if there is
+%D already a stone on the position and we replace it.
+
+\def\adddummystone(#1:#2:#3)%
+ {\global\advance\stonecount\plusone
+ \edef\boardrow{\number#1}%
+ \edef\boardcolumn{\number#2}%
+ \ifcase\currentstatus
+ \setcurrentstatus{\plusone}%
+ \or
+ \setcurrentstatus{\plustwo}%
+ \makeoverlaplist\currentstonenumber
+ \setvalue{overlaplist:\currentstonenumber}{\csname overlap:#1:#2\endcsname}%
+ \setcurrentoverlap{\dummystonebox}%
+ \else
+ \setcurrentstatus{\plusthree}%
+ \fi
+ \setevalue{field:\number#1:\number#2}%
+ {\ifx#3B
+ \plusone
+ \else\ifx#3W
+ \plustwo
+ \fi\fi:\number\stonecount}%
+ \ifcase\currentstatus\or\else
+ \setcurrentoverlap
+ {\hbox
+ {\currentoverlap
+ \vbox\!!to\boardunit{\vss\hbox\!!to\boardunit{\hss$\mathstrut{}={}$\hss}\vss}%
+ \dummystonebox}}%
+ \fi}
+
+%D \macros{processoverlappedstones}
+%D
+%D This is the alternative to \tex{processdeadstones} for the printable
+%D version. The stones are sorted from the lowest number to the highest.
+
+\def\processoverlappedstones
+ {\scratchdimen\hsize
+ \def\doprocessoverlappedstones##1%
+ {\setbox\globalscratchbox\hbox{\getvalue{overlaplist:##1}}%
+ \ifdim\wd\globalscratchbox>\scratchdimen
+ \scratchdimen\dimexpr\hsize-\wd\globalscratchbox\relax
+ \hbox\!!to\hsize{\box\scratchbox\hfill}%
+ \box\scratchbox\box\globalscratchbox
+ \else
+ \scratchdimen\dimexpr\scratchdimen-\wd\globalscratchbox-\@@@@bddistance\relax
+ \setbox\scratchbox\hbox{\box\scratchbox\box\globalscratchbox\hskip\@@@@bddistance}%
+ \fi}%
+ \sortcommacommand[\overlaplist]\donumericcompare
+ \processcommacommand[\sortedcommalist]\doprocessoverlappedstones
+ \hbox\!!to\hsize{\box\scratchbox\hss}}
+
+\bgroup
+\catcode`\;=13
+\gdef\dostartSGFbox
+ {\setupboard[\c!alternative=\v!c]%
+ \switchtobodyfont[\the\dimexpr.45\boardunit\relax]%
+ \doglobal\increment\thegame
+ \clearboard\clearoverlapstatus
+ \doglobal\let\thestep\zerocountervalue
+ \global\stonecount\!!zerocount
+ \def;##1[##2##3]%
+ {\adddummystone(\charactertonumber##2:\charactertonumber##3:##1)}%
+ \catcode`\^^M=\@@ignore}
+\egroup
+
+\def\stopSGFbox
+ {\framed
+ [\c!offset=\v!overlay,\c!strut=\v!no,
+ \c!top=\!!zeropoint,\c!bottom=\!!zeropoint,\c!depth=\!!zeropoint,
+ \c!frame=\v!on]
+ {\vbox
+ {\offinterlineskip
+ \framed
+ [\c!offset=\boardunit,\c!frameoffset=\!!zeropoint,\c!strut=\v!no,
+ \c!top=\!!zeropoint,\c!bottom=\!!zeropoint,\c!depth=\!!zeropoint,
+ \c!width=\dimexpr\boardsize\boardunit+2\boardunit\relax,
+ \c!frame=\v!on,\c!background={color,board},
+ \c!backgroundcolor=boardbackground]%
+ {\dontcomplain
+ \offinterlineskip
+ \highlightlabelfalse
+ \drawboard}
+ \framed
+ [\c!frame=\v!on,
+ \c!width=\dimexpr\boardsize\boardunit+\plustwo\boardunit\relax,
+ \c!height=\numexpr\@@@@bdn*\plustwo\relax\boardunit,
+ \c!offset=.2\boardunit]%
+ {\vbox\!!to\vsize{\processoverlappedstones}}}}}
+
+\bgroup
+\catcode`\;=13
+\gdef\dostartSGFpage
+ {\startTEXpage
+ [\c!width=\dimexpr\boardsize\boardunit
+ \if\@@@@bdalternative\v!a
+ +\plustwo\boardunit
+ \else\if\@@@@bdalternative\v!b
+ +\numexpr\@@@@bdn*\plusfour+\plustwo\relax\boardunit
+ \else
+ +\plustwo\boardunit
+ \fi\fi\relax,
+ \c!height=\dimexpr\boardsize\boardunit
+ \if\@@@@bdalternative\v!a
+ +\numexpr\@@@@bdn*\plustwo+\plustwo\relax\boardunit
+ \else\if\@@@@bdalternative\v!b
+ +\plustwo\boardunit
+ \else
+ +\plustwo\boardunit
+ \fi\fi\relax,
+ \c!background={color,board},
+ \c!backgroundcolor=boardbackground]%
+ \switchtobodyfont[\the\dimexpr.45\boardunit\relax]%
+ \doglobal\increment\thegame
+ \clearboard
+ \getparameters[\??fd][\c!start=1,\c!width=\v!fit,\c!height=\c!fit,\c!offset=\v!overlay,\c!frame=\v!off]%
+ \doglobal\let\thestep\zerocountervalue
+ \global\stonecount\!!zerocount
+ \setupfield
+ [\v!game:\thegame]
+ [\v!reset]%
+ \setupfield
+ [\v!game:\thegame]
+ [\c!option=\v!readonly,
+ \c!frameoffset=\!!zeropoint,
+ \c!strut=\v!no,
+ \c!top=\!!zeropoint,
+ \c!bottom=\!!zeropoint,
+ \c!depth=\!!zeropoint,
+ \c!width=\v!fit,
+ \c!height=\v!fit,
+ \c!offset=\v!overlay,
+ \c!frame=\v!off]%
+ \definefield
+ [\v!game:\thegame:\thestep][\s!check][\v!game:\thegame]
+ [\v!empty,\v!empty][\v!empty]%
+ \cleardeadstonelist
+ \executeifdefined{drawboard\@@@@bdalternative}\drawboarda
+ \flushboard
+ \def;##1[##2##3]%
+ {\addstone(\charactertonumber##2:\charactertonumber##3:##1)%
+ \doif\@@@@bdcalculate\v!yes\processtones
+ \executeifdefined{drawboard\@@@@bdalternative}\drawboarda
+ \flushboard}%
+ \catcode`\^^M=\@@ignore}
+\egroup
+
+%D \macros{starSGF,stopSGF}
+%D
+%D The two macros \tex{startSGF} and \tex{stopSGF} begin and end
+%D the parser for the go stones saved with the \type{sgf} syntax.
+
+\def\stopSGFpage
+ {\startoverlay{\overlaybutton{JS(Walk_Field{\v!game:\thegame})}}\stopoverlay
+ \stopTEXpage}
+
+\def\startSGF
+ {\bgroup
+ \catcode`\;=13
+ \dosingleempty\dostartSGF}
+
+\def\dostartSGF[#1]%
+ {\iffirstargument
+ \setupboard[#1]%
+ \fi
+ \doif\@@@@bdcalculate\v!no
+ {\setupboard[\c!alternative=\v!c]}%
+ \doifelse\@@@@bdprintable\v!no
+ \dostartSGFpage
+ \dostartSGFbox}
+
+\def\stopSGF
+ {\doifelse\@@@@bdprintable\v!no
+ \stopSGFpage
+ \stopSGFbox
+ \egroup}
+
+\protect \endinput