3

I'm trying to draw diagrams for the board game Go in TikZ. To reuse board positions in subsequent variations I need a way to store the current board position. I learned from this question that two of my options are using \csname ... \endcsname or pgfkeys. As I am using pgfkeys for other things anyways, my question is:

How would one implement a two-dimensional array with pgfkeys?

I'm open towards solutions not using pgfkeys, if you think that's a bad idea. However I would prefer not to use expl3, as one of my end goals is to be compatible to Plain TeX, LaTeX and ConTeXt (just like TikZ is)

mdm
  • 229
  • 1
  • 4
  • 2
    Not directly related to the question, but it's worth mentioning that expl3 is usable with plain and ConTeXt as well as with LaTeX. – Joseph Wright Apr 30 '17 at 15:52
  • 1
    I would use expl3. pgfkeys is ok for user interface but imho not to implement a low-level data structure. Are you sure that a two-dimensional is enough and that you don't need something to store move numbers and perhaps markers? – Ulrike Fischer Apr 30 '17 at 15:58
  • @UlrikeFischer I plan to have two "arrays". One mapping coordinates to stone color and one mapping coordinates to markers/move numbers. I personally dislike the expl3 syntax, but I will give it another look. – mdm Apr 30 '17 at 16:14
  • I think you will begin to love when you start to write commands to loop over your arrays. expl3 has so many useful tools there. I wished it existed already in the current form when I wrote chessboard and xskak. – Ulrike Fischer Apr 30 '17 at 16:42
  • I would just like to point out that 'sgf2dg' is a very powerful tool to draw Go diagrams. It does not exactly do what you ask about here, but it will surely be easier to start from there. – fborchers Feb 02 '20 at 18:56
  • @fborchers I was using this mainly as an excuse to get deeper into TeX programming. sgf2dg is great. – mdm Feb 18 '20 at 17:57

1 Answers1

7

Although you gave a preference for pgfkeys, I suspect that is overkill here even if you have pgf loaded for other reasons.

This makes a log of

A1 is black and B14 is white

from the plain tex

\def\setpos#1#2#3{\expandafter\def\csname GO-#1-#2-\endcsname{#3}}
\def\getpos#1#2{\csname GO-#1-#2-\endcsname}

\setpos{A}{1}{black}
\setpos{B}{14}{white}

\immediate\write20{A1 is \getpos{A}{1} and B14 is \getpos{B}{14}}

\bye
David Carlisle
  • 757,742