%% psgomanual.tex
%% Copyright 2001 V. Bos
%
% This program may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% This program consists of the files:
%
%   psgo.sty
%   psgomanual.tex
%   psgomanual.ps
%
% RCS-ID: $Id: psgomanual.tex,v 1.1 2001/10/13 11:27:27 vbos Exp vbos $
%
\documentclass[a4paper]{article}

\usepackage{psgo}
\newcommand{\pstricks}{\textsf{PSTricks}}

\newcommand{\commandname}[1]{{\ttfamily\symbol{'134}#1}}

\title{\psgo\\{\normalfont\normalsize Typesetting Go Diagrams with \pstricks}}
\author{Victor Bos\\email: v.bos@tue.nl}
\date{October 3, 2001}


\setgounit{0.4cm}

\begin{document}
\maketitle


\section{Introduction}

The \psgo{} package provides functionality to typeset Go diagrams in
\LaTeXe. It is built on top of the \pstricks{} package, which is
nowadays available in many \LaTeX{} distributions. Although \psgo{}
does not understand the \emph{Smart Game Format} (SGF), it has support
for all graphical markup properties of SGF FF[4], see
\verb|http://www.red-bean.com/sgf/|.

\section{Download and installation}

The \psgo{} package can be downloaded from my website:

\medskip
\verb|http://members.chello.nl/~v.bos01/|

\medskip\noindent
To install the package, download the files \texttt{psgo.sty} and
\texttt{psgomanual.tex} and put them in a directory where \LaTeX{}
can find them. After that, test the installation by running \LaTeX{}
on \texttt{psgomanual.tex}.
 
\section{Go boards}

The interface of \psgo{} is based on how Go diagrams are usually
displayed in books. That is, the rows of a $19\times19$ board are
indexed by $1,2,\ldots,19$ and the columns are indexed by $A, B,
\ldots, T$ (skipping $I$). Further, the lower left corner has index
$(A, 1)$ and the upper right corner has index
$(T,19)$. Figure~\ref{fig:empty:boards} shows a $19\times 19$ board
and a $9\times9$ board. Note that the sizes of the boards are reduced
in order to fit in one figure. To re-size a Go board, the command
\verb|\setgounit| can be used. This command takes the desired
horizontal unit distance as an argument. The default horizontal unit
distance is~$0.6$cm. The vertical unit distance is computed by the
\psgo{} package. For the diagrams in this document, except for the
diagrams of Figure~\ref{fig:empty:boards}, we have set the horizontal
unit distance to~$0.4$cm (\verb|\setgounit{0.4cm}|).

\begin{figure}
\setgounit{0.3cm}
\begin{center}
\begin{tabular}{cc}
\begin{psgoboard}
\end{psgoboard} &
\begin{psgoboard}[9]
\end{psgoboard}
\end{tabular}
\caption{Different size Go boards}
\label{fig:empty:boards}
\end{center}
\end{figure}

Go boards are defined in the \verb|psboard| environment of \psgo. This
environment takes~1 optional parameter which indicates the size of the
board (default size is~19). For instance, the boards of
Figure~\ref{fig:empty:boards} were defined by:

\begin{verbatim}
\begin{psgoboard}
\end{psgoboard}
\begin{psgoboard}[9]
\end{psgoboard}
\end{verbatim}

If the indexes are not desired, the starred version \verb|psgoboard*|
of the environment should be used, as in
\begin{verbatim}
\begin{psgoboard*}
\end{psgoboard*}
\begin{psgoboard*}[9]
\end{psgoboard*}
\end{verbatim}

\section{Stones and moves}

There are two commands to put stones on the board. The first one is
\verb|\stone| which takes three parameters: the color, the column, and
the row of the stone. For example, \verb|\stone{black}{c}{4}| puts a
black stone at position~$(C,4)$ (note that in the \LaTeX{} code, the
columns are indicated by lower case characters). The \verb|\stone|
command can be used to setup a particular configuration. For instance,
the configuration of Figure~\ref{fig:ko:configuration} is defined as
follows.

\begin{verbatim}
\begin{psgoboard}[9]
\stone{white}{c}{3}
\stone{white}{e}{3}
\stone{white}{d}{2}
\stone{white}{d}{4}
\stone{black}{f}{3}
\stone{black}{e}{2}
\stone{black}{e}{4}
\end{psgoboard}
\end{verbatim}

\begin{figure}
\begin{center}
\begin{psgoboard}[9]
\stone{white}{c}{3}
\stone{white}{e}{3}
\stone{white}{d}{2}
\stone{white}{d}{4}
\stone{black}{f}{3}
\stone{black}{e}{2}
\stone{black}{e}{4}
\end{psgoboard}
\caption{Setting up a configuration}
\label{fig:ko:configuration}
\end{center}
\end{figure}


The second command is \verb|move| which takes two parameters: the
column and the row of the next move. Moves are usually numbered. The
counter that keeps track of the move number is
called~\verb|gomove|. This is a normal \LaTeX{} counter and can be
changed using ordinary \LaTeX-counter commands. The color of the
stones placed by the \verb|\move| command alternates between
successive moves. For example, \verb|\move{b}{3}| puts a stone on
position~$(B, 3)$. If this was a black move, the stone is black,
otherwise it is white. It is time for an example. The following code
generates a $9\times 9$ board with six moves. The result is depicted
in Figure~\ref{fig:9x9:example}(a).

\begin{verbatim}
\begin{psgoboard}[9]
\move{c}{3}
\move{g}{7}
\move{g}{4}
\move{c}{7}
\move{e}{7}
\end{psgoboard}
\end{verbatim}


As can be seen, the move numbers are displayed on the stones. The
\verb|gomove| counter is never reset by the \psgo{} package. So, the
move numbers just continue in subsequent diagrams. Of course, it is
possible to reset the value of~\verb|gomove| manually. In that case,
one should know that the \verb|\move| command increases the
\verb|gomove| counter \emph{before} it draws the stone. So, if a
diagram should start with move~0, one should issue the command
\verb|\setcounter{gomove}{-1}| just before the diagram.

If a diagram continues another diagram, the numbers on the stones
played so far are usually not desirable. Therefore, \psgo{} has
defined a starred version the move command: \verb|\move*|.  This
command does not decorate stones with move numbers and it does not
increase the \verb|gomove| counter.  For instance, if the game of
Figure~\ref{fig:9x9:example}(a) is continued, all we have to do is
copy\&paste the game played so far, replace the existing \verb|\move|
commands by \verb|\move*|, and add some new \verb|\move| (unstarred!)
commands to it. The code is given below and the result displayed in
Figure~\ref{fig:9x9:example}(b).
\begin{verbatim}
\begin{psgoboard}[9]
\move*{c}{3} % old \move commands replaced by \move*
\move*{g}{7}
\move*{g}{4}
\move*{c}{7}
\move*{e}{7}
\move{f}{6}  % new \move commands
\move{e}{6}
\move{c}{5}
\end{psgoboard}
\end{verbatim}

\begin{figure}
\begin{center}
\begin{tabular}{cc}
\begin{psgoboard}[9]
\move{c}{3}
\move{g}{7}
\move{g}{4}
\move{c}{7}
\move{e}{7}
\end{psgoboard}
&
\begin{psgoboard}[9]
\move*{c}{3}
\move*{g}{7}
\move*{g}{4}
\move*{c}{7}
\move*{e}{7}
\move{f}{6}
\move{e}{6}
\move{c}{5}
\end{psgoboard}\\
(a) First 5 moves.
&
(b) Successive moves.
\end{tabular}
\caption{Moves on a board}
\label{fig:9x9:example}
\end{center}
\end{figure}


\section{Markers}

Empty positions on the board can be marked with the command
\verb|\markpos|. This command takes three parameters, being, the
marker, the column, and the row. Available markers and the commands to
generate them are listed in Table~\ref{tbl:markers}. Each marker is
illustrated at position~$(B,2)$ on a~$3\times3$ board. Note that the
label marker command, \verb|\marklb|, takes one argument, being the
label. It is possible, though not advisable, to add more than one
marker to an empty position.

\begin{table}
\begin{center}
\begin{tabular}{|c|l|l|l|}
\hline
Diagram & \psgo{} Command & Description & Example\\
\hline\hline 
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\markma}{b}{2}\end{psgoboard*}} &
\commandname{markma}& Cross &
{\ttfamily\commandname{markpos}\{\commandname{markma}\}\{b\}\{2\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\marktr}{b}{2}\end{psgoboard*}} &
\commandname{marktr}& Triangle &
{\ttfamily\commandname{markpos}\{\commandname{marktr}\}\{b\}\{2\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\markcr}{b}{2}\end{psgoboard*}} &
\commandname{markcr}& Circle &
{\ttfamily\commandname{markpos}\{\commandname{markcr}\}\{b\}\{2\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\marksq}{b}{2}\end{psgoboard*}} &
\commandname{marksq}& Open square &
{\ttfamily\commandname{markpos}\{\commandname{marksq}\}\{b\}\{2\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\marklb{A}}{b}{2}\end{psgoboard*}} &
\commandname{marklb\{\#1}\}& Label &
{\ttfamily\commandname{markpos}\{\commandname{marklb}\{A\}\}\{b\}\{2\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\marksl}{b}{2}\end{psgoboard*}} &
\commandname{marksl}& Filled square &
{\ttfamily\commandname{markpos}\{\commandname{marksl}\}\{b\}\{2\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[3]\markpos{\markdd}{b}{2}\end{psgoboard*}} &
\commandname{markdd}& Hatched lines &
{\ttfamily\commandname{markpos}\{\commandname{markdd}\}\{b\}\{2\}}\\\hline
\end{tabular}
\caption{Markers on empty positions}
\label{tbl:markers}
\end{center}
\end{table}

Stones can be marked too. To this end, the commands \verb|\stone| and
\verb|\move| take an optional parameter representing the marker of the
stone.  For example, \verb|\stone[\markma]{black}{b}{4}| puts a black
stone marked with a cross at
position~$(B,4)$. Table~\ref{tbl:stone:markers} shows how stones can
be marked. It is possible, though not advisable, to add more than one
marker to a stone or to add markers to numbered stones.

\begin{table}
\begin{center}
\begin{tabular}{|c|l|l|p{0.5\linewidth}|}
\hline
Diagram & \psgo{} Command & Description & Example\\
\hline\hline 
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\markma]{black}{b}{2}\stone[\markma]{white}{c}{3}\end{psgoboard*}} &
\commandname{markma}& Cross &
{\ttfamily\commandname{stone}[\commandname{markma}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{markma}]\{white\}\{c\}\{3\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\marktr]{black}{b}{2}\stone[\marktr]{white}{c}{3}\end{psgoboard*}} &
\commandname{marktr}& Triangle &
{\ttfamily\commandname{stone}[\commandname{marktr}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{marktr}]\{white\}\{c\}\{3\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\markcr]{black}{b}{2}\stone[\markcr]{white}{c}{3}\end{psgoboard*}} &
\commandname{markcr}& Circle &
{\ttfamily\commandname{stone}[\commandname{markcr}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{markcr}]\{white\}\{c\}\{3\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\marksq]{black}{b}{2}\stone[\marksq]{white}{c}{3}\end{psgoboard*}} &
\commandname{marksq}& Open square &
{\ttfamily\commandname{stone}[\commandname{marksq}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{marksq}]\{white\}\{c\}\{3\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\marklb{A}]{black}{b}{2}\stone[\marklb{B}]{white}{c}{3}\end{psgoboard*}} &
\commandname{marklb\{\#1}\}& Label &
{\ttfamily\commandname{stone}[\commandname{marklb}\{A\}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{marklb}\{B\}]\{white\}\{c\}\{3\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\marksl]{black}{b}{2}\stone[\marksl]{white}{c}{3}\end{psgoboard*}} &
\commandname{marksl}& Filled square &
{\ttfamily\commandname{stone}[\commandname{marksl}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{marksl}]\{white\}\{c\}\{3\}}\\\hline
%
\raisebox{-0.5\height}{\begin{psgoboard*}[4]\stone[\markdd]{black}{b}{2}\stone[\markdd]{white}{c}{3}\end{psgoboard*}} &
\commandname{markdd}& Hatched lines &
{\ttfamily\commandname{stone}[\commandname{markdd}]\{black\}\{b\}\{2\}
          \commandname{stone}[\commandname{markdd}]\{white\}\{c\}\{3\}}\\\hline
\end{tabular}
\caption{Markers on stones}
\label{tbl:stone:markers}
\end{center}
\end{table}

\section{Lines and arrows}

In addition to markers, it is possible to add lines and arrows to the
diagrams. The command \verb|\goline| draws a line and the command
\verb|\goarrow| draws an arrow. Both commands take four parameters
indicating the column and the row of the start position and the column
and the row of the end position. That is, \verb|\goline{a}{1}{c}{5}|
draws a line from position~$(A,1)$ to position~$(C,5)$ and
\verb|\goarrow{e}{3}{b}{2}| draws an arrow from position~$(E,3)$ to
position~$(B,2)$, as illustrated in Figure~\ref{fig:more:features}(a).

\section{Stones in text}

In comments on a Go diagram, one often sees graphical representations
of the stones on the board. Therefore, \psgo{} has facilities to
include stones in running text. For instance, we can refer to stone
\stone[4]{black} of Figure~\ref{fig:9x9:example}(a) with the
command~\verb|\stone[4]{black}|. As can be seen, in running text
(i.e., outside the \verb|psgoboard| environment), \verb|\stone| takes
two parameters. The first one is optional and denotes a number or a
marker to be placed on the stone. The second parameter denotes the
color of the stone. As another example, here is a list of various stones:
\stone[\markma]{black}, \stone[\markma]{white},
\stone[\marktr]{black}, \stone[\marktr]{white},
\stone[\markcr]{black}, \stone[\markcr]{white},
\stone[\marksq]{black}, \stone[\marksq]{white},
\stone[\marklb{A}]{black}, \stone[\marklb{A}]{white},
\stone[\marksl]{black}, \stone[\marksl]{white},
\stone[\markdd]{black}, \stone[\markdd]{white}.
This list was generated by the following code:
\begin{verbatim}
\stone[\markma]{black}, \stone[\markma]{white},
\stone[\marktr]{black}, \stone[\marktr]{white},
\stone[\markcr]{black}, \stone[\markcr]{white},
\stone[\marksq]{black}, \stone[\marksq]{white},
\stone[\marklb{A}]{black}, \stone[\marklb{A}]{white},
\stone[\marksl]{black}, \stone[\marksl]{white},
\stone[\markdd]{black}, \stone[\markdd]{white}.
\end{verbatim}


It is possible to attach ordinary \LaTeX{} labels to \emph{moves}
on a board. For instance, the digram of Figure~\ref{fig:more:features}(b) was
generated by the following code:

\begin{verbatim}
\begin{psgoboard}[5]
\move{b}{2}
\move{d}{3}\label{funny:go:move}
\end{psgoboard}
\end{verbatim}
As can be seen, a label \verb|{funny:go:move}| is defined after the
second move. To refer in the text to this move, the ordinary \LaTeX{}
\verb|\ref| command can be used. In this case, we type
\verb|\stone[\ref{funny:go:move}]{white}|, which results in the
stone~\stone[\ref{funny:go:move}]{white}, as expected. Of course, the
color should still be defined manually.

\begin{figure}
\begin{center}

\begin{tabular}{cc}
\begin{psgoboard}[5]
\goline{a}{1}{c}{5}
\goarrow{e}{3}{b}{2}
\end{psgoboard}
&
\setcounter{gomove}{-1}
\begin{psgoboard}[5]
\move{b}{2}
\move{d}{3}\label{funny:go:move}
\end{psgoboard}\\
(a) Lines and arrows &
(b) Labeling stones
\end{tabular}

\caption{More \psgo{} features: lines, arrows, and labels}
\label{fig:more:features}
\end{center}
\end{figure}


\end{document}
