summaryrefslogtreecommitdiff
path: root/obsolete/macros/context/contrib/context-sgf/tex/context/third/sgf/deadstone.mkiv
blob: 6b0513fb38b23ddfa09ed03a392914a11901ef24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%D \module
%D   [       file=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]

\unprotect

%D This is the \MKIV\ part of the dead stone calculator, it was
%D written to get rid of tex \TEX\ workarounds used in the \MKII\
%D version. If you want to understand how the algoritm works you
%D should use the \LUA\ implementation.
%D
%D The functions to calculate the current state of the stones are
%D saved in a seperate \LUA\ file, loading this file is the first
%D thing we do here.

\ctxloadluafile{deadstone}{}

%D The \tex{clearboard} command is only a call to the \LUA\
%D implementation and no longer a \TEX\ loop as in the first version.

\def\clearboard{\ctxlua{clearboard()}}

\def\processtones{\ctxlua{processtones()}}

%D \macros{addstone}
%D
%D The \tex{addstone} macro is shorter as in the \MKII\ version because
%D I can now use \tex{doifelse} and can avoid the low level \tex{ifx}
%D test as needed before. I can now also pass laststone as argument for
%D \tex{ctxlua} and prevent a extra \tex{ifx} as before.

\def\addstone(#1:#2:#3)%
  {\global\advance\stonecount\plusone
   \doifelse{#3}{B}
     {\ctxlua{field[#1][#2] = { 1, tex.count.stonecount }; laststone = 1}}
     {\doif{#3}{W}
        {\ctxlua{field[#1][#2] = { 2, tex.count.stonecount }; laststone = 2}}}}

\def\currentstone
  {\ctxlua{tex.print(field[\boardrow][\boardcolumn][1])}}

\def\currentstonenumber
  {\ctxlua{tex.print(field[\boardrow][\boardcolumn][2])}}

%D \macros{cleardeadstonelist}
%D
%D This is the only pure \TEX\ command I use in this module, all other
%D commands are only wrappers for the \LUA\ part but I need this because
%D the two commands \tex{deadblackstones} and \tex{deadwhitestones} can
%D be used by other macros and this seems to be the best solution I found
%D for the moment.

\def\cleardeadstonelist
  {\let\deadblackstones\empty
   \let\deadwhitestones\empty}

\protect