%%%%%%%%%%%%%%%%%%%%%%%% go.sty %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  written by Hanna Kolodziejska (version 0.05 : November 1991)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\catcode`@=11

\newbox\@gobox \newdimen\@godimen

\def\gofontsize#1{
    \font\gofont=go#1 at #1truept
    \font\blackfontOne=go1bla#1 at #1truept
    \font\blackfontTwo=go2bla#1 at #1truept
    \font\whitefontOne=go1whi#1 at #1truept
    \font\whitefontTwo=go2whi#1 at #1truept
    \ifnum #1=10 \font\letterfont=cmr10 at 10truept\else        %%% <--- ???
        \ifnum #1=15 \font\letterfont=cmr10 at 14.4truept\else  %%% <--- ???
        \ifnum #1=20 \font\letterfont=cmr10 at 17.28truept\fi\fi\fi
    \setbox\@gobox=\hbox{\gofont\char0}
    \@godimen=\wd\@gobox
    }

\gofontsize{10} % initialization <---

\def\newgoline{\hfill\break}
\def\hoshi{\gofont\char0}
\def\empty{\gofont\char1}
\def\lftborder{\gofont\char2}
\def\rtborder{\gofont\char3}
\def\topborder{\gofont\char4}
\def\botborder{\gofont\char5}
\def\lfttopcorner{\gofont\char6}
\def\rttopcorner{\gofont\char7}
\def\lftbotcorner{\gofont\char8}
\def\rtbotcorner{\gofont\char9}
\def\triangle{\whitefontTwo\char127}  %%%
\def\square{\whitefontTwo\char126}    %%%


\newcount\n
\newcount\@beglet \newcount\@endlet
\newcount\@lettercount

\def\@letternumber#1{\relax
    \ifx #1a\@lettercount=1\else
    \ifx #1b\@lettercount=2\else
    \ifx #1c\@lettercount=3\else
    \ifx #1d\@lettercount=4\else
    \ifx #1e\@lettercount=5\else
    \ifx #1f\@lettercount=6\else
    \ifx #1g\@lettercount=7\else
    \ifx #1h\@lettercount=8\else
    \ifx #1i\@lettercount=9\else
    \ifx #1k\@lettercount=10\else
    \ifx #1l\@lettercount=11\else
    \ifx #1m\@lettercount=12\else
    \ifx #1n\@lettercount=13\else
    \ifx #1o\@lettercount=14\else
    \ifx #1p\@lettercount=15\else
    \ifx #1q\@lettercount=16\else
    \ifx #1r\@lettercount=17\else
    \ifx #1s\@lettercount=18\else
    \ifx #1t\@lettercount=19\else
       \errmessage{Row label must be letter!}
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \fi\fi\fi\fi\fi\fi\fi\fi\fi
    }


\def\inidiagram#1-#2:#3-#4 {\relax
    \ifnum #3>#4 \errmessage{Invalid column numbers!} \fi
    \@letternumber{#1} \@beglet=\@lettercount
    \@letternumber{#2} \@endlet=\@lettercount
    \def\@inirow##1##2{{\n=#3
      \loop
       \expandafter\let\csname @##1\romannumeral\n \endcsname=0\relax
       \edef\@@inirow{\global
            \def\csname @##1\romannumeral\n \endcsname{##2}}\@@inirow
       \ifnum \n<#4 \advance \n by 1
      \repeat
      }}\relax
    \loop
      \ifcase\@beglet\relax\or
      \@inirow{a}{\topborder}\relax
        \ifnum #3=1 \global\def\@ai{\lfttopcorner}\fi
        \ifnum #4=19 \global\def\@axix{\rttopcorner}\fi \or
      \@inirow{b}{\empty}\relax
        \ifnum #3=1 \global\def\@bi{\lftborder}\fi
        \ifnum #4=19 \global\def\@bxix{\rtborder}\fi \or
      \@inirow{c}{\empty}\relax
        \ifnum #3=1 \global\def\@ci{\lftborder}\fi
        \ifnum #4=19 \global\def\@cxix{\rtborder}\fi \or
      \@inirow{d}{\empty}\relax
        \ifnum #3=1 \global\def\@di{\lftborder}\fi
        \ifnum #3<5  \ifnum #4>3  \global\def\@div{\hoshi}\fi\fi
        \ifnum #3<11 \ifnum #4>9  \global\def\@dx{\hoshi}\fi\fi
        \ifnum #3<17 \ifnum #4>15 \global\def\@dxvi{\hoshi}\fi\fi
        \ifnum #4=19 \global\def\@dxix{\rtborder}\fi \or
      \@inirow{e}{\empty}
        \ifnum #3=1 \global\def\@ei{\lftborder}\fi
        \ifnum #4=19 \global\def\@exix{\rtborder}\fi \or
      \@inirow{f}{\empty}
        \ifnum #3=1 \global\def\@fi{\lftborder}\fi
        \ifnum #4=19 \global\def\@fxix{\rtborder}\fi \or
      \@inirow{g}{\empty}
        \ifnum #3=1 \global\def\@gi{\lftborder}\fi
        \ifnum #4=19 \global\def\@gxix{\rtborder}\fi \or
      \@inirow{h}{\empty}
        \ifnum #3=1 \global\def\@hi{\lftborder}\fi
        \ifnum #4=19 \global\def\@hxix{\rtborder}\fi \or
      \@inirow{i}{\empty}
        \ifnum #3=1 \global\def\@ii{\lftborder}\fi
        \ifnum #4=19 \global\def\@ixix{\rtborder}\fi \or
      \@inirow{k}{\empty}
        \ifnum #3=1 \global\def\@ki{\lftborder}\fi
        \ifnum #3<5  \ifnum #4>3  \global\def\@kiv{\hoshi}\fi\fi
        \ifnum #3<11 \ifnum #4>9  \global\def\@kx{\hoshi}\fi\fi
        \ifnum #3<17 \ifnum #4>15 \global\def\@kxvi{\hoshi}\fi\fi
        \ifnum #4=19 \global\def\@kxix{\rtborder}\fi \or
      \@inirow{l}{\empty}
        \ifnum #3=1 \global\def\@li{\lftborder}\fi
        \ifnum #4=19 \global\def\@lxix{\rtborder}\fi \or
      \@inirow{m}{\empty}
        \ifnum #3=1 \global\def\@mi{\lftborder}\fi
        \ifnum #4=19 \global\def\@mxix{\rtborder}\fi \or
      \@inirow{n}{\empty}
        \ifnum #3=1 \global\def\@ni{\lftborder}\fi
        \ifnum #4=19 \global\def\@nxix{\rtborder}\fi \or
      \@inirow{o}{\empty}
        \ifnum #3=1 \global\def\@oi{\lftborder}\fi
        \ifnum #4=19 \global\def\@oxix{\rtborder}\fi \or
      \@inirow{p}{\empty}
        \ifnum #3=1 \global\def\@pi{\lftborder}\fi
        \ifnum #4=19 \global\def\@pxix{\rtborder}\fi \or
      \@inirow{q}{\empty}
        \ifnum #3=1 \global\def\@qi{\lftborder}\fi
        \ifnum #3<5  \ifnum #4>3  \global\def\@qiv{\hoshi}\fi\fi
        \ifnum #3<11 \ifnum #4>9  \global\def\@qx{\hoshi}\fi\fi
        \ifnum #3<17 \ifnum #4>15 \global\def\@qxvi{\hoshi}\fi\fi
        \ifnum #4=19 \global\def\@qxix{\rtborder}\fi \or
      \@inirow{r}{\empty}
        \ifnum #3=1 \global\def\@ri{\lftborder}\fi
        \ifnum #4=19 \global\def\@rxix{\rtborder}\fi \or
      \@inirow{s}{\empty}
        \ifnum #3=1 \global\def\@si{\lftborder}\fi
        \ifnum #4=19 \global\def\@sxix{\rtborder}\fi \or
      \@inirow{t}{\botborder}
        \ifnum #3=1 \global\def\@ti{\lftbotcorner}\fi
        \ifnum #4=19 \global\def\@txix{\rtbotcorner}\fi
      \fi
      \ifnum \@beglet<\@endlet \advance \@beglet by 1
    \repeat
    }

\def\inifulldiagram{\inidiagram a-t:1-19 }

\inifulldiagram % initialization


\def\showdiagram#1-#2:#3-#4 {\vbox{\offinterlineskip\noindent
    \ifnum #3>#4 \errmessage{Invalid column numbers!} \fi
    \hsize=\@godimen
    \n=#4\advance\n by-#3\advance\n by1
    \multiply\hsize by\n
    \@letternumber{#1} \@beglet=\@lettercount
    \@letternumber{#2} \@endlet=\@lettercount
    \def\@showrow##1{{\n=#3
      \loop
        \edef\@@showrow{\csname @##1\romannumeral\n \endcsname}\@@showrow
        \ifnum \n<#4 \advance \n by 1
      \repeat
      }}\relax
    \loop
      \ifcase\@beglet\relax\or
        \@showrow{a}\or
        \@showrow{b}\or
        \@showrow{c}\or
        \@showrow{d}\or
        \@showrow{e}\or
        \@showrow{f}\or
        \@showrow{g}\or
        \@showrow{h}\or
        \@showrow{i}\or
        \@showrow{k}\or
        \@showrow{l}\or
        \@showrow{m}\or
        \@showrow{n}\or
        \@showrow{o}\or
        \@showrow{p}\or
        \@showrow{q}\or
        \@showrow{r}\or
        \@showrow{s}\or
        \@showrow{t}
      \fi
      \ifnum \@beglet<\@endlet
        \newgoline \advance \@beglet by 1
    \repeat
    }}

\def\showfulldiagram{\showdiagram a-t:1-19 }

\def\pos#1#2=#3#4{\relax
    \ifcat #1a\relax \else \errmessage{Row label must be a letter!}\fi
    \ifnum #2<1 \errmessage{Column number less than 1?}\fi
    \ifnum #2>19 \errmessage{Column number greater than 19?}\fi
    \edef\@fourth{#4}\relax
    \ifx .#4\ifx #3\empty\edef\@fourth{}\else \edef\@fourth{0}\fi\fi
    \edef\@borders{\relax
        \ifx #1a \ifnum #2=1  \gofont\char15 \else
                 \ifnum #2=19 \gofont\char16 \else
                 \gofont\char13 \fi\fi
        \else
        \ifx #1t \ifnum #2=1  \gofont\char17 \else
                 \ifnum #2=19 \gofont\char18 \else
                 \gofont\char14 \fi\fi
        \else
        \ifnum #2=1 \gofont\char11
        \else
        \ifnum #2=19 \gofont\char12
        \else
        \gofont\char10
        \fi\fi\fi\fi}\relax
    \expandafter\let\csname @#1\romannumeral#2\endcsname=0\relax
    \edef\@pos{\def\csname @#1\romannumeral#2\endcsname{#3{\@fourth}}}\@pos
    \ignorespaces
    }


\newcount\nr

\def\black#1{\relax
    \ifx \triangle#1{\let\whitefontTwo=\blackfontTwo
                     \rlap{\triangle}\@borders}\else
    \ifx \square#1{\let\whitefontTwo=\blackfontTwo
                     \rlap{\square}\@borders}\else
    \ifnum #1<0 \errmessage{Negative Black's move?}\else
    \ifnum #1>253 \errmessage{Black's move too big!}\else
    \ifnum #1<128 {\blackfontOne\rlap{\char#1}\@borders}\else
        \nr=#1
        \advance \nr by -128
        {\blackfontTwo\rlap{\char\nr}\@borders}\ignorespaces
    \fi\fi\fi\fi\fi}

\def\white#1{\relax
    \ifx \triangle#1{\rlap{\triangle}\@borders}\else
    \ifx \square#1{\rlap{\square}\@borders}\else
    \ifnum #1<0 \errmessage{Negative White's move?}\else
    \ifnum #1>253 \errmessage{White's move too big!}\else
    \ifnum #1<128 {\whitefontOne\rlap{\char#1}\@borders}\else
       \nr=#1
       \advance \nr by -128
       {\whitefontTwo\rlap{\char\nr}\@borders}\ignorespaces
    \fi\fi\fi\fi\fi}

\def\textblack#1{\def\@borders{\hskip\wd\@gobox}\relax
    \ifx .#1\lower.2\wd\@gobox\hbox{\black{0}}\else
      \lower.2\wd\@gobox\hbox{\black{#1}}\fi}

\def\textwhite#1{\def\@borders{\hskip\wd\@gobox}\relax
    \ifx .#1\lower.2\wd\@gobox\hbox{\white{0}}\else
      \lower.2\wd\@gobox\hbox{\white{#1}}\fi}


\newbox\@letterbox \newdimen\@letterdim

\def\symbol#1{\relax
    \ifcat a#1\relax\else
    \ifcat 0#1\relax\else
       \errmessage{Strange parameter of symbol macro! (#1)}
    \fi\fi
    \setbox\@letterbox=\hbox to\wd\@gobox{\hfil\letterfont #1\hfil}\relax
    \@letterdim=\wd\@gobox
    \divide \@letterdim by 24
    \multiply \@letterdim by 22
    \advance \@letterdim by -\ht\@letterbox
    {\raise.5\@letterdim\box\@letterbox}\relax
    }

\let\letter=\symbol

\catcode`@=12
