%D \module
%D   [       file=t-deadstone,
%D        version=2007.07.31,
%D          title=\CONTEXT\ User Module,
%D       subtitle=Dead stone calculator for go,
%D         author=Wolfgang Schuster,
%D          email=schuster.wolfgang@googlemail.com,
%D           date=\currentdate,
%D      copyright=Public Domain]


\writestatus{loading}{Context User Module / Dead stone calculator for go}

\unprotect

\newcount\boardsize
\newcount\deadcount
\newcount\stonecount

\chardef\plussix  =6
\chardef\plusseven=7

\boardsize=19
\deadcount=2

%D \macros{placeboard,placeterminalboard}
%D
%D The following two commands can be used to draw a simple board with
%D the current state, \tex{placeboard} is only used for testing the module
%D and let me see the current values of every node.
%D
%D The second board is intended for tracing the output and calculations
%D of my macros on the terminal and will also appear in the log file
%D if the user has it enabled. It use a symbols instead of numeric values
%D for the output.
%D
%D Only meant for my test files and not for real output. I need another
%D name to prevent a clash with another modules.

\def\intersctionfield{.}   % was previously 0
\def\blackfield      {X}   % was previously 1
\def\whitefield      {O}   % was previously 2
\def\fieldstyle      {\tt}

\def\placeboard
  {\dorecurse{\the\boardsize}
     {\edef\boardrow{\recurselevel}%
      \hbox{\dorecurse{\the\boardsize}
        {\edef\boardcolumn{\recurselevel}%
         \hbox\!!to1em
            {\hss\fieldstyle % switched from roman to mono
             \ifcase\currentstone\relax
             \intersctionfield\or
             \blackfield      \or
             \whitefield      \or
             3\ignorespaces   \or
             4\ignorespaces   \or
             5\ignorespaces   \or
             6\ignorespaces   \or
             7\ignorespaces   \fi\hss}}}}}

%D Todo:
%D
%D \startitemize[intro]
%D \item header above every board
%D \item empty line before and after every board
%D \item frame for the baord on all four sides
%D \stopitemize

\def\placeterminalboard
  {\newlinechar=`\^^J
   \message{^^J}% start a new line before we place the board
   \dorecurse{\the\boardsize}
     {\edef\boardrow{\recurselevel}%
      \edef\zahl{ }% put a space to the left of the line
      \dorecurse{\the\boardsize}
        {\edef\boardcolumn{\recurselevel}%
         \edef\zahl
           {\zahl
            \ifcase\currentstone
            \intersctionfield\space\or
            \blackfield      \space\or
            \whitefield      \space\fi}}
         \message{\zahl^^J}}} % place the current line and move to the next

%D Loading of the mkii and mkiv files.

\loadmarkfile{deadstone}

\protect \endinput
