Debian Codegraph @

texmf-dist/source/latex/havannah/havannah.dtx

raw
1 % \iffalse
2 %<*driver>
3
4 \ProvidesFile{havannah.dtx}
5 \documentclass{ltxdoc}
6 \usepackage{havannah}
7 \usepackage[scaled=0.92]{helvet}
8 \usepackage{lstdoc}
9 \usepackage{mathpazo}
10 \usetikzlibrary{decorations.pathmorphing}
11 \EnableCrossrefs
12 \CodelineIndex
13 \RecordChanges
14 \begin{document}
15 \DocInput{havannah.dtx}
16 \PrintChanges
17 \PrintIndex
18 \end{document}
19
20 %</driver>
21 % \fi
22 %
23 % \newcommand\package{\texttt}
24 %
25 % \title{The \LaTeX\ \package{havannah} package}
26 % \author{Marcin Ciura\thanks{\texttt{[email protected]}}}
27 % \date{2015-02-21}
28 % \maketitle
29 %
30 % \begin{abstract}
31 % The \package{havannah} package defines macros for typesetting
32 % diagrams of board positions in the games of Havannah and Hex.
33 % \end{abstract}
34 %
35 % \begin{center}
36 % \begin{HavannahBoard}[board size=8,coordinate style=little golem]
37 % \HGame{
38 % i12,h13,l7,m4,h12,g12,g11,f11,f10,e10,i13,h14,i14,h15,e9,
39 % d9,a8,d8,e8,d7,d4,e6,f5,c4,h10,e7,c3,b3,b2,a2,a1,f8,g7,
40 % h9,i7,i9,i10,g9,k9,j7,j11,g10,j9,h11,j8,i8,k7,l8,k10,i11,
41 % k6,j6,l4,d5,m3,c6,c5,b6,a4,b7,c8,b8,c9,b9,c10,j5,n1,j4,
42 % l5,j3,m5,m6,n3,n4,o2,j2,o1}
43 % \end{HavannahBoard}
44 %
45 % A Havannah game between Maciej Celuch and Mirko Rahn\\
46 % played on \texttt{http://www.littlegolem.net} from 2009-07-05 to 2009-07-29
47 % \end{center}
48 %
49 % \section{Usage}
50 %
51 % Put |\usepackage{havannah}| in the preamble of your document.
52 %
53 % This package defines four environments, three commands,
54 % and several hooks that allow for the customization of its output.
55 %
56 % \DescribeEnv{HavannahBoard}
57 % The |HavannahBoard| environment typesets a Havannah board.
58 % It accepts the following keys:
59 % \begin{itemize}
60 % \item |board size|: an integer from 1 to 13, default: |10|,
61 % \item |coordinate style|: |little golem |or| classical|,
62 % default: |classical|,
63 % \item |hex height|: a length, default: |17.5pt|,
64 % \item |show coordinates|: a Boolean, default: |true|,
65 % \item |show hexes|: a Boolean, default: |true|.
66 % \end{itemize}
67 % Sample effects of setting these keys are shown below.
68 %
69 % \vbox{\begin{lstsample}{}{}
70 % \begin{HavannahBoard}[board size=2]
71 % \end{HavannahBoard}
72 %
73 % \begin{HavannahBoard}[board size=3]
74 % \end{HavannahBoard}
75 %
76 % \begin{HavannahBoard}[board size=4]
77 % \end{HavannahBoard}
78 % \end{lstsample}}
79 %
80 % \noindent\hrulefill
81 %
82 % \vbox{\begin{lstsample}{}{}
83 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
84 % \HGame{d3,c2}
85 % \end{HavannahBoard}
86 % \begin{HavannahBoard}[board size=3,coordinate style=classical]
87 % \HGame{d3,c2}
88 % \end{HavannahBoard}
89 % \end{lstsample}}
90 %
91 % \noindent\hrulefill
92 %
93 % \vbox{\begin{lstsample}{}{}
94 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
95 % \HGame{d3,c2}
96 % \end{HavannahBoard}
97 % \begin{HavannahBoard}[
98 % board size=3,coordinate style=little golem,hex height=1cm]
99 % \HGame{d3,c2}
100 % \end{HavannahBoard}
101 % \end{lstsample}}
102 %
103 % \noindent\hrulefill
104 %
105 % \vbox{\begin{lstsample}{}{}
106 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
107 % \HGame{d3,c2}
108 % \end{HavannahBoard}
109 % \begin{HavannahBoard}[
110 % board size=3,coordinate style=little golem,show coordinates=false]
111 % \HGame{d3,c2}
112 % \end{HavannahBoard}
113 % \end{lstsample}}
114 %
115 % \noindent\hrulefill
116 %
117 % \vbox{\begin{lstsample}{}{}
118 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
119 % \HGame{d3,c2}
120 % \end{HavannahBoard}
121 % \begin{HavannahBoard}[
122 % board size=3,coordinate style=little golem,show hexes=false]
123 % \HGame{d3,c2}
124 % \end{HavannahBoard}
125 % \end{lstsample}}
126 %
127 % \noindent\hrulefill
128 %
129 % \DescribeEnv{HexBoard}
130 % The |HexBoard| environment typesets a Hex board.
131 % It accepts the following keys:
132 % \begin{itemize}
133 % \item |board size|: an integer from 1 to 26, default: 11,
134 % \item |top left color|: either |white| or |black|,
135 % default: |black|,
136 % \item |hex height|: a length, default: |17.5pt|,
137 % \item |show coordinates|: a Boolean, default: |true|,
138 % \item |show hexes|: a Boolean, default: |true|.
139 % \end{itemize}
140 % Sample effects of setting these keys are show below.
141 %
142 % \vbox{\begin{lstsample}{}{}
143 % \begin{HexBoard}[board size=2]
144 % \end{HexBoard}
145 %
146 % \begin{HexBoard}[board size=3]
147 % \end{HexBoard}
148 %
149 % \begin{HexBoard}[board size=4]
150 % \end{HexBoard}
151 % \end{lstsample}}
152 %
153 % \noindent\hrulefill
154 %
155 % \vbox{\begin{lstsample}{}{}
156 % \begin{HexBoard}[board size=3]
157 % \HGame{a3,c2}
158 % \end{HexBoard}
159 %
160 % \begin{HexBoard}[board size=3,
161 % top left color=white]
162 % \HGame{a3,c2}
163 % \end{HexBoard}
164 % \end{lstsample}}
165 %
166 % \noindent\hrulefill
167 %
168 % \vbox{\begin{lstsample}{}{}
169 % \begin{HexBoard}[board size=3]
170 % \HGame{a3,c2}
171 % \end{HexBoard}
172 %
173 % \begin{HexBoard}[board size=3,
174 % hex height=1cm]
175 % \HGame{a3,c2}
176 % \end{HexBoard}
177 % \end{lstsample}}
178 %
179 % \noindent\hrulefill
180 %
181 % \vbox{\begin{lstsample}{}{}
182 % \begin{HexBoard}[board size=3]
183 % \HGame{a3,c2}
184 % \end{HexBoard}
185 %
186 % \begin{HexBoard}[board size=3,
187 % show coordinates=false]
188 % \HGame{a3,c2}
189 % \end{HexBoard}
190 % \end{lstsample}}
191 %
192 % \noindent\hrulefill
193 %
194 % \vbox{\begin{lstsample}{}{}
195 % \begin{HexBoard}[board size=3]
196 % \HGame{a3,c2}
197 % \end{HexBoard}
198 %
199 % \begin{HexBoard}[board size=3,
200 % show hexes=false]
201 % \HGame{a3,c2}
202 % \end{HexBoard}
203 % \end{lstsample}}
204 %
205 % \noindent\hrulefill
206 %
207 % \DescribeEnv{InnerHavannahBoard}
208 % The |InnerHavannahBoard| environment typesets a Havannah board
209 % inside a |tikzpicture| environment. It is useful for drawing
210 % multiple diagrams in one picture.
211 % In addition to the keys of |HavannahBoard|, it accepts the following keys:
212 % \begin{itemize}
213 % \item |prefix|: to be put before cell names.
214 % \item |x|: the x coordinate of the lower corner of the board.
215 % \item |y|: the y coordinate of the lower corner of the bowrd.
216 % \end{itemize}
217 % An example of its use is shown below.
218 %
219 % \vbox{\begin{lstsample}{}{}
220 % \begin{tikzpicture}
221 % \begin{InnerHavannahBoard}[board size=4,prefix=A,x=0,y=0]
222 % \end{InnerHavannahBoard}
223 % \begin{InnerHavannahBoard}[board size=4,prefix=B,x=7cm,y=0]
224 % \end{InnerHavannahBoard}
225 % \draw (Ad4)..controls (Ae7) and (Bg5)..(Bd4);
226 % \HStoneGroup[color=white]{Ad4,Bd4}
227 % \end{tikzpicture}
228 % \end{lstsample}}
229 %
230 % \DescribeEnv{InnerHexBoard}
231 % The |InnerHexBoard| environment typesets a Hex board
232 % inside a |tikzpicture| environment. It accepts the same set
233 % of extra keys as |InnerHavannahBoard|: |prefix|, |x|, and |y|.
234 %
235 % \DescribeMacro{HLetterCordinates}
236 % \DescribeMacro{HCoordinateStyle}
237 % \DescribeMacro{HDrawHex}
238 % You can use \cs{renewcommand} to redefine three hooks
239 % that change the look and feel of |HavannahBoard| or |HexBoard|.
240 % They are:
241 % \begin{itemize}
242 % \item \cs{HLetterCoordinates}: a comma-separated list, default:\\
243 % |{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}|,
244 % \item \cs{HCoordinateStyle}: a one-argument macro, default:\\
245 % |{\sffamily#1}|,
246 % \item \cs{HDrawHex}: a |tikz| command, default:\\
247 % |{\shadedraw[shading=radial,inner color=gray!30,|\\
248 % |outer color=gray!70]}|. Note that the default shading is a heavy task
249 % for some printers so you might want to use a simpler command instead,
250 % for instance |\draw[fill=gray!35]|.
251 % \end{itemize}
252 % Sample results of redefining them are shown below.
253 %
254 % \vbox{\begin{lstsample}{}{}
255 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
256 % \HGame{d3,c2}
257 % \end{HavannahBoard}
258 % \renewcommand\HLetterCoordinates{1 ,2 ,3 ,4 ,5 }
259 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
260 % \HGame{4 3,3 2}
261 % \end{HavannahBoard}
262 % \end{lstsample}}
263 %
264 % \noindent\hrulefill
265 %
266 % \vbox{\begin{lstsample}{}{}
267 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
268 % \end{HavannahBoard}
269 % \renewcommand\HCoordinateStyle[1]{\Large\bfseries#1}
270 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
271 % \end{HavannahBoard}
272 % \end{lstsample}}
273 %
274 % \noindent\hrulefill
275 %
276 % \vbox{\begin{lstsample}{}{}
277 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
278 % \end{HavannahBoard}
279 % \renewcommand\HDrawHex{\draw[
280 % decorate,decoration={random steps,segment length=1pt}]}
281 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
282 % \end{HavannahBoard}
283 % \end{lstsample}}
284 %
285 % \noindent\hrulefill
286 %
287 % \DescribeMacro{HGame}
288 % The \cs{HGame} macro can only be used inside a
289 % |HavannahBoard| or |HexBoard| environment.
290 % It accepts the following keys:
291 % \begin{itemize}
292 % \item |first move label|: a text, default: |1|,
293 % \item |first player|: either |white| or |black|, default:
294 % |white| inside |HavannahBoard| and |black| inside |HexBoard|.
295 % \item |numbered moves|: a Boolean, default: |true|,
296 % \item |relative stone size|: a number, default: |0.75|.
297 % \end{itemize}
298 % Their effects are shown below.
299 %
300 % \vbox{\begin{lstsample}{}{}
301 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
302 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
303 % \end{HavannahBoard}
304 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
305 % \HGame[first move label=S]{
306 % c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
307 % \end{HavannahBoard}
308 % \end{lstsample}}
309 %
310 % \noindent\hrulefill
311 %
312 % \vbox{\begin{lstsample}{}{}
313 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
314 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
315 % \end{HavannahBoard}
316 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
317 % \HGame[first player=black]{
318 % c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
319 % \end{HavannahBoard}
320 % \end{lstsample}}
321 %
322 % \noindent\hrulefill
323 %
324 % \vbox{\begin{lstsample}{}{}
325 % \begin{HexBoard}[board size=3]
326 % \HGame{b2,b1,c1,a3,b3}
327 % \end{HexBoard}
328 %
329 % \begin{HexBoard}[board size=3,top left color=white]
330 % \HGame[first player=white]{
331 % b2,b1,c1,a3,b3}
332 % \end{HexBoard}
333 % \end{lstsample}}
334 %
335 % \noindent\hrulefill
336 %
337 % \vbox{\begin{lstsample}{}{}
338 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
339 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
340 % \end{HavannahBoard}
341 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
342 % \HGame[numbered moves=false]{
343 % c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
344 % \end{HavannahBoard}
345 % \end{lstsample}}
346 %
347 % \noindent\hrulefill
348 %
349 % \vbox{\begin{lstsample}{}{}
350 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
351 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
352 % \end{HavannahBoard}
353 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
354 % \HGame[relative stone size=0.9]{
355 % c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
356 % \end{HavannahBoard}
357 % \end{lstsample}}
358 %
359 % \noindent\hrulefill
360 %
361 % \DescribeMacro{HStoneGroup}
362 % The \cs{HStoneGroup} macro can only be used inside a
363 % |HavannahBoard| or |HexBoard| environment.
364 % It puts a group of stones of the same color on the board.
365 % It accepts the following keys:
366 % \begin{itemize}
367 % \item |color|: |white|, |black|, or |transparent|,
368 % there is no default -- the value must be specified,
369 % \item |label|: a text, default: empty string,
370 % \item |relative stone size|: a number, default: |0.75|.
371 % \end{itemize}
372 % The effects of |color| and |label| are shown below.
373 % The effect of |relative stone size| is the same as for
374 % \cs{HGame} and will not be shown.
375 %
376 % \vbox{\begin{lstsample}{}{}
377 % \begin{HavannahBoard}[board size=6,coordinate style=little golem]
378 % \HStoneGroup[color=black,label=$\mathcal F$]{
379 % a5,b5,c5,d6,d7,d8,c8,e8,f8,g8,h7,i7,j7}
380 % \HStoneGroup[color=white,label=$\mathcal B$]{
381 % a1,b2,c3,d3,e3,e2,f2,f1}
382 % \HStoneGroup[color=transparent,label=$\mathcal R$]{
383 % h6,g6,g5,g4,h3,i2,j2,j3,j4,i5}
384 % \end{HavannahBoard}
385 % \end{lstsample}}
386 %
387 % \DescribeMacro{HMoveNumberStyle}
388 % \DescribeMacro{HWhiteStone}
389 % \DescribeMacro{HBlackStone}
390 % \DescribeMacro{HTransparentStone}
391 % \DescribeMacro{HBeforeOddMove}
392 % \DescribeMacro{HBeforeEvenMove}
393 % \DescribeMacro{HBeforeStone}
394 % There are five hooks that can be redefined via \cs{renewcommand}
395 % to change the appearance of \cs{HGame} and \cs{HStoneGroup}.
396 % They are:
397 % \begin{itemize}
398 % \item \cs{HMoveNumberStyle}: a one-argument macro,
399 % influences \cs{HGame}, default:\\
400 % |{\sffamily#1}|,
401 % \item \cs{HWhiteStone}: a |tikz| command,
402 % influences \cs{HGame} and \cs{HStoneGroup}, default:\\
403 % |{\node[circle,draw,inner sep=0.6pt,fill=white,|\\
404 % |minimum size=\HStoneDiameter]}|,
405 % \item \cs{HBlackStone}: a |tikz| command,
406 % influences \cs{HGame} and \cs{HStoneGroup}, default:\\
407 % |{\node[circle,draw,inner sep=0.6pt,fill=black,text=white|\\
408 % |minimum size=\HStoneDiameter]}|,
409 % \item \cs{HTransparentStone}: a |tikz| command,
410 % influences \cs{HStoneGroup}, default:\\
411 % |{\node[circle,draw,inner sep=0.6pt,|\\
412 % |minimum size=\HStoneDiameter]}|,
413 % \item \cs{HBeforeOddMove}, \cs{BeforeEvenMove}: macros expanded
414 % before placing stones, for example \cs{pause} when animating
415 % games in |beamer|, influence \cs{HGame}, default: |{}|,
416 % \item \cs{HBeforeStone}: a macro expanded before placing stones,
417 % influences \cs{HStoneGroup}, default: |{}|.
418 % \end{itemize}
419 % Sample effects of redefining some of them are shown below.
420 %
421 % \vbox{\begin{lstsample}{}{}
422 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
423 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
424 % \end{HavannahBoard}
425 % \renewcommand\HMoveNumberStyle[1]{\footnotesize\romannumeral#1}
426 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
427 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
428 % \end{HavannahBoard}
429 % \end{lstsample}}
430 %
431 % \noindent\hrulefill
432 %
433 % \vbox{\begin{lstsample}{}{}
434 % \begin{HavannahBoard}[board size=3,coordinate style=little golem]
435 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
436 % \end{HavannahBoard}
437 % \renewcommand\HDrawHex{\draw}
438 % \renewcommand\HWhiteStone{\node[
439 % circle,shading=ball,ball color=white,inner sep=0.6pt,
440 % minimum size=\HStoneDiameter]}
441 % \renewcommand\HBlackStone{\node[
442 % circle,shading=ball,ball color=black,inner sep=0.6pt,text=white,
443 % minimum size=\HStoneDiameter]}
444 % \begin{HavannahBoard}[board size=3]
445 % \HGame{c3,e1,e3,c2,a1,d3,c5,d4,c4,b2,a3,d2,b4}
446 % \end{HavannahBoard}
447 % \end{lstsample}}
448 %
449 % \noindent\hrulefill
450 %
451 % \DescribeMacro{HHexGroup}
452 % The \cs{HHexGroup} macro can only be used inside a
453 % |HavannahBoard| or |HexBoard| environment.
454 % It puts a group of hexes on the board,
455 % which presumably is typeset with| show hexes=false|.
456 % It is recommended to use it inside the |HexBoard| environment
457 % due to the simplicity of its coordinate system.
458 % It accepts the following keys:
459 % \begin{itemize}
460 % \item |label|: a text, default: empty string,
461 % \end{itemize}
462 % An example of its use is shown below.
463 %
464 % \vbox{\begin{lstsample}{}{}
465 % \begin{HexBoard}[
466 % board size=9,show coordinates=false,show hexes=false]
467 % \HHexGroup
468 % {a1,b1,c1,d1,e1,f1,g1,h1,a2,b2,c2,e2,f2,g2,a3,b3,c3,d3,e3,f3,b4,c4,d4}
469 % \draw [dotted] (a1)--(a2); \draw [dotted] (b1)--(a2);
470 % \draw [dotted] (c1)--(c2); \draw [dotted] (d1)--(c2);
471 % \draw [dotted] (e1)--(e2); \draw [dotted] (f1)--(e2);
472 % \draw [dotted] (g1)--(g2); \draw [dotted] (h1)--(g2);
473 % \draw [dotted] (c2)--(b3); \draw [dotted] (e2)--(e3);
474 % \draw [dotted] (a2)..controls(a3)..(b3);
475 % \draw [dotted] (a2)..controls(b2)..(b3);
476 % \draw [dotted] (g2)..controls(f3)..(e3);
477 % \draw [dotted] (g2)..controls(f2)..(e3);
478 % \draw [dotted] (b3)..controls(b4)..(c4);
479 % \draw [dotted] (b3)..controls(c3)..(c4);
480 % \draw [dotted] (e3)..controls(d4)..(c4);
481 % \draw [dotted] (e3)..controls(d3)..(c4);
482 % \HStoneGroup[color=black]{a,b,c,d,e,f,g,h,i,c4}
483 % \end{HexBoard}
484 % \end{lstsample}}
485 %
486 % \StopEventually
487 %
488 % \section{Implementation}
489 % \begin{macrocode}
490 %<*package>
491 \NeedsTeXFormat{LaTeX2e}
492 \ProvidesPackage{havannah}[2010/06/06 LaTeX havannah package]
493 \RequirePackage{tikz}
494 % \end{macrocode}
495 %
496 % The naming schema used in the \package{havannah} package
497 % is \cs{HFooBar} for redefinable hooks,
498 % and \cs{h@foo@bar} for internal macros.
499 %
500 % Start with defining default expansions for the hooks.
501 % \begin{macrocode}
502 \newcommand\HLetterCoordinates{%
503 a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}
504 \newcommand\HCoordinateStyle[1]{\sffamily#1}
505 \newcommand\HMoveNumberStyle[1]{\sffamily#1}
506 \newcommand\HDrawHex{\shadedraw[
507 shading=radial,inner color=gray!30,outer color=gray!70]}
508 \newcommand\HWhiteStone{\node[
509 circle,draw=black,inner sep=0.6pt,fill=white,
510 minimum size=\HStoneDiameter]}
511 \newcommand\HBlackStone{\node[
512 circle,draw=black,inner sep=0.6pt,fill=black,text=white,
513 minimum size=\HStoneDiameter]}
514 \newcommand\HTransparentStone{\node[
515 circle,draw=black,inner sep=0.6pt,
516 minimum size=\HStoneDiameter]}
517 \newcommand\HBeforeOddMove{}
518 \newcommand\HBeforeEvenMove{}
519 \newcommand\HBeforeStone{}
520 % \end{macrocode}
521 %
522 % The \cs{h@draw@hex} macro draws a hexagonal cell.
523 % The cell is |3\h@one@third@hex@wd| wide and |2\h@half@hex@ht| high.
524 % It has two horizontal and four slanted edges.
525 % The \cs{h@draw@hex} macro takes one argument:
526 % the coordinates of the center of the cell.
527 % It uses the \cs{HDrawHex} hook to style the cell.
528 % \begin{macrocode}
529 \newcommand{\h@draw@hex}[1]{%
530 \HDrawHex (#1)
531 ++(-2\h@one@third@hex@wd,0)--
532 ++(\h@one@third@hex@wd,-\h@half@hex@ht)--
533 ++(2\h@one@third@hex@wd,0)--
534 ++(\h@one@third@hex@wd,\h@half@hex@ht)--
535 ++(-\h@one@third@hex@wd,\h@half@hex@ht)--
536 ++(-2\h@one@third@hex@wd,0)--
537 cycle;
538 }
539 % \end{macrocode}
540 %
541 % Define \package{pgfkeys} paths.
542 % \begin{macrocode}
543 \newif\ifh@numbered@moves
544 \newif\ifh@show@coordinates
545 \newif\ifh@show@hexes
546 \pgfkeys{%
547 /h@havannah@board/.cd,
548 board size/.store in=\hv@board@size,
549 coordinate style/.is choice,
550 coordinate style/classical/.code={%
551 \def\h@draw@board{\h@draw@classical@board}},
552 coordinate style/little golem/.code={%
553 \def\h@draw@board{\h@draw@little@golem@board}},
554 hex height/.store in=\h@hex@height,
555 prefix/.store in=\h@prefix,
556 show coordinates/.is if=h@show@coordinates,
557 show hexes/.is if=h@show@hexes,
558 x/.store in=\h@xx,
559 y/.store in=\h@yy,
560 board size=10,
561 coordinate style=classical,
562 hex height=17.5pt,
563 prefix=,
564 show coordinates=true,
565 show hexes=true,
566 x=0,
567 y=0,
568 %
569 /h@hex@board/.cd,
570 top left color/.is choice,
571 top left color/white/.code={%
572 \def\h@top@left@color{\HWhiteStone}%
573 \def\h@bottom@left@color{\HBlackStone}%
574 },
575 top left color/black/.code={%
576 \def\h@top@left@color{\HBlackStone}%
577 \def\h@bottom@left@color{\HWhiteStone}%
578 },
579 board size/.store in=\hx@board@size,
580 hex height/.store in=\h@hex@height,
581 prefix/.store in=\h@prefix,
582 relative stone size/.store in=\h@relative@stone@size,
583 show coordinates/.is if=h@show@coordinates,
584 show hexes/.is if=h@show@hexes,
585 x/.store in=\h@xx,
586 y/.store in=\h@yy,
587 top left color=black,
588 board size=11,
589 hex height=17.5pt,
590 relative stone size=0.75,
591 show coordinates=true,
592 show hexes=true,
593 %
594 /h@game/.cd,
595 first move label/.store in=\h@first@move@label,
596 first player/.is choice,
597 first player/white/.code={%
598 \def\h@odd@player{\HWhiteStone}%
599 \def\h@even@player{\HBlackStone}%
600 },
601 first player/black/.code={%
602 \def\h@odd@player{\HBlackStone}%
603 \def\h@even@player{\HWhiteStone}%
604 },
605 numbered moves/.is if=h@numbered@moves,
606 relative stone size/.store in=\h@relative@stone@size,
607 first move label=1,
608 numbered moves=true,
609 relative stone size=0.75,
610 %
611 /h@stone@group/.cd,
612 color/.is choice,
613 color/white/.code={\def\h@player{\HWhiteStone}},
614 color/black/.code={\def\h@player{\HBlackStone}},
615 color/transparent/.code={\def\h@player{\HTransparentStone}},
616 label/.store in=\h@label,
617 relative stone size/.store in=\h@relative@stone@size,
618 relative stone size=0.75,
619 %
620 /h@hex@group/.cd,
621 label/.store in=\h@label,
622 }
623 % \end{macrocode}
624 %
625 % The |InnerHavannahBoard| environment first sets the values of
626 % \cs{hv@board@size}, \cs{h@draw@board}, \cs{h@hex@height},
627 % and \cs{h@show@coordinatestrue} or \cs{h@show@coordinatesfalse}.
628 % Then it computes \cs{h@half@hex@ht}, \cs{h@one@third@hex@wd},
629 % and \cs{h@board@diagonal}, and executes \cs{h@draw@board}.
630 % \begin{macrocode}
631 \newcount\h@board@diagonal
632 \newdimen\h@half@hex@ht
633 \newdimen\h@one@third@hex@wd
634 \newenvironment{InnerHavannahBoard}[1][]{%
635 \def\h@odd@player{\HWhiteStone}%
636 \def\h@even@player{\HBlackStone}%
637 \pgfqkeys{/h@havannah@board}{#1}%
638 \setlength\h@half@hex@ht{\h@hex@height}%
639 \divide\h@half@hex@ht by 2
640 \setlength\h@one@third@hex@wd{0.577350269\h@half@hex@ht}%
641 \h@board@diagonal=\hv@board@size
642 \multiply\h@board@diagonal by 2
643 \advance\h@board@diagonal by -1
644 \h@draw@board
645 }
646 % \end{macrocode}
647 %
648 % There is nothing to be done at the end of |InnerHavannahBoard|.
649 % \begin{macrocode}
650 {}
651 % \end{macrocode}
652 %
653 % The |HavannahBoard| environment just wraps |InnerHavannahBoard|
654 % inside a |tikzpicture|.
655 % \begin{macrocode}
656 \newenvironment{HavannahBoard}[1][]{%
657 \begin{tikzpicture}
658 \begin{InnerHavannahBoard}[#1,prefix=,x=0,y=0]
659 }
660 % \end{macrocode}
661 % Finally, |HavannahBoard| closes the |InnerHavannahBoard| and
662 % |tikzpicture| environments.
663 % \begin{macrocode}
664 { \end{InnerHavannahBoard}
665 \end{tikzpicture}
666 }
667 % \end{macrocode}
668 %
669 % The \cs{h@draw@classical@board} and \cs{h@draw@little@golem@board}
670 % macros differ enough that a common routine would be of little help.
671 % They both draw a rhombus of hexes with two corners cut.
672 % The edges of adjacent hexes are drawn twice.
673 %
674 % The following counters are shared by both macros.
675 % \begin{macrocode}
676 \newcount\h@l
677 \newcount\h@a@corner
678 \newcount\h@b@corner
679 % \end{macrocode}
680 %
681 % The \cs{h@draw@classical@board} macro is a bit simpler
682 % than the other one.
683 % \begin{macrocode}
684 \newcommand\h@draw@classical@board{%
685 \h@l=0
686 \h@b@corner=\hv@board@size
687 \foreach \h@letter in \HLetterCoordinates {%
688 \global\advance\h@l by 1
689 \ifnum \h@l > \h@board@diagonal
690 \breakforeach
691 \else
692 \global\advance\h@b@corner by 1
693 \h@a@corner=\hv@board@size
694 \foreach \h@n in {1,...,\h@board@diagonal} {%
695 \global\advance\h@a@corner by 1
696 \ifnum \h@l < \h@a@corner
697 \ifnum \h@n < \h@b@corner
698 \coordinate (\h@prefix\h@letter\h@n) at
699 (\h@xx+3*\h@n\h@one@third@hex@wd-3*\h@l\h@one@third@hex@wd,
700 \h@yy+\h@n\h@half@hex@ht+\h@l\h@half@hex@ht);
701 \ifh@show@hexes
702 \h@draw@hex{\h@prefix\h@letter\h@n}%
703 \fi
704 \fi
705 \fi
706 }%
707 \ifh@show@coordinates
708 \ifnum \h@l < \hv@board@size\relax
709 \node at
710 (\h@xx-3*\h@l\h@one@third@hex@wd,\h@yy+\h@l\h@half@hex@ht)
711 {\HCoordinateStyle{\h@letter}};
712 \else
713 \node at
714 (\h@xx-3*\hv@board@size\h@one@third@hex@wd,
715 \h@yy+2*\h@l\h@half@hex@ht-\hv@board@size\h@half@hex@ht)
716 {\HCoordinateStyle{\h@letter}};
717 \fi
718 \fi
719 \fi
720 }%
721 \ifh@show@coordinates
722 \foreach \h@n in {1,...,\h@board@diagonal} {%
723 \ifnum \h@n < \hv@board@size
724 \node at
725 (\h@xx+3*\h@n\h@one@third@hex@wd,\h@yy+\h@n\h@half@hex@ht)
726 {\HCoordinateStyle{\h@n}};
727 \else
728 \node at
729 (\h@xx+3*\hv@board@size\h@one@third@hex@wd,
730 \h@yy+2*\h@n\h@half@hex@ht-\hv@board@size\h@half@hex@ht)
731 {\HCoordinateStyle{\h@n}};
732 \fi
733 }%
734 \fi
735 }
736 % \end{macrocode}
737 %
738 % The \cs{h@draw@little@golem@board} macro is more complicated
739 % since the numbered rows in Little Golem change direction in the middle.
740 % \begin{macrocode}
741 \newcommand\h@draw@little@golem@board{%
742 \h@a@corner=\hv@board@size
743 \h@b@corner=\hv@board@size
744 \multiply\h@b@corner by 3
745 \h@l=0
746 \foreach \h@letter in \HLetterCoordinates {%
747 \global\advance\h@l by 1
748 \ifnum \h@l > \h@board@diagonal
749 \breakforeach
750 \else
751 \global\advance\h@a@corner by 1
752 \global\advance\h@b@corner by -1
753 \foreach \h@n in {1,...,\h@board@diagonal} {%
754 \ifnum \h@n < \h@a@corner
755 \ifnum \h@n < \h@b@corner
756 \ifnum \h@l < \hv@board@size
757 \coordinate (\h@prefix\h@letter\h@n) at
758 (\h@xx+3*\h@l\h@one@third@hex@wd,
759 \h@yy+2*\hv@board@size\h@half@hex@ht+
760 2*\h@n\h@half@hex@ht-\h@l\h@half@hex@ht);
761 \ifh@show@hexes
762 \h@draw@hex{\h@prefix\h@letter\h@n}%
763 \fi
764 \else
765 \coordinate (\h@prefix\h@letter\h@n) at
766 (\h@xx+3*\h@l\h@one@third@hex@wd,
767 \h@yy+2*\h@n\h@half@hex@ht+\h@l\h@half@hex@ht);
768 \ifh@show@hexes
769 \h@draw@hex{\h@prefix\h@letter\h@n}%
770 \fi
771 \fi
772 \fi
773 \fi
774 }
775 \ifh@show@coordinates
776 \ifnum \h@l < \hv@board@size
777 \node at
778 (\h@xx+3*\h@l\h@one@third@hex@wd,
779 \h@yy+2*\hv@board@size\h@half@hex@ht-\h@l\h@half@hex@ht)
780 {\HCoordinateStyle{\h@letter}};
781 \else
782 \node at
783 (\h@xx+3*\h@l\h@one@third@hex@wd,\h@yy+\h@l\h@half@hex@ht)
784 {\HCoordinateStyle{\h@letter}};
785 \fi
786 \fi
787 \fi
788 }%
789 \ifh@show@coordinates
790 \foreach \h@n in {1,...,\h@board@diagonal} {%
791 \ifnum \h@n < \hv@board@size
792 \node at
793 (\h@xx,
794 \h@yy+2*\h@n\h@half@hex@ht+
795 \h@board@diagonal\h@half@hex@ht+\h@half@hex@ht)
796 {\HCoordinateStyle{\h@n}};
797 \node at
798 (\h@xx+3*\h@board@diagonal\h@one@third@hex@wd+
799 3*\h@one@third@hex@wd,
800 \h@yy+2*\h@n\h@half@hex@ht+
801 \h@board@diagonal\h@half@hex@ht+\h@half@hex@ht)
802 {\HCoordinateStyle{\h@n}};
803 \else
804 \node at
805 (\h@xx+3*\h@n\h@one@third@hex@wd-
806 3*\hv@board@size\h@one@third@hex@wd,
807 \h@yy+\h@n\h@half@hex@ht+3*\hv@board@size\h@half@hex@ht)
808 {\HCoordinateStyle{\h@n}};
809 \node at
810 (\h@xx-3*\h@n\h@one@third@hex@wd+
811 9*\hv@board@size\h@one@third@hex@wd,
812 \h@yy+\h@n\h@half@hex@ht+3*\hv@board@size\h@half@hex@ht)
813 {\HCoordinateStyle{\h@n}};
814 \fi
815 }%
816 \fi
817 }
818 % \end{macrocode}
819 %
820 % The |InnerHexBoard| environment is similar to |InnerHavannahBoard|
821 % but simpler, as it typesets an entire cross-product of coordinates,
822 % without cutting the corners.
823 % \begin{macrocode}
824 \newenvironment{InnerHexBoard}[1][]{%
825 \def\h@odd@player{\HBlackStone}%
826 \def\h@even@player{\HWhiteStone}%
827 \pgfqkeys{/h@hex@board}{#1}%
828 \tracingcommands=1
829 \setlength\h@half@hex@ht{\h@hex@height}%
830 \divide\h@half@hex@ht by 2
831 \setlength\h@one@third@hex@wd{0.577350269\h@half@hex@ht}%
832 \HStoneDiameter=\h@relative@stone@size\h@half@hex@ht
833 \multiply\HStoneDiameter by 2
834 \h@l=0
835 \foreach \h@letter in \HLetterCoordinates {%
836 \global\advance\h@l by 1
837 \ifnum \h@l > \hx@board@size
838 \breakforeach
839 \else
840 \foreach \h@n in {1,...,\hx@board@size} {%
841 \coordinate (\h@letter\h@n) at
842 (3*\h@l\h@one@third@hex@wd+3*\h@n\h@one@third@hex@wd,
843 \h@l\h@half@hex@ht-\h@n\h@half@hex@ht);
844 \ifh@show@hexes
845 \h@draw@hex{\h@letter\h@n}%
846 \fi
847 }%
848 \coordinate (\h@letter) at
849 (3*\h@l\h@one@third@hex@wd,
850 2\h@half@hex@ht-2\h@half@hex@ht+\h@l\h@half@hex@ht);
851 \coordinate (-\h@letter) at
852 (3*\hx@board@size\h@one@third@hex@wd+
853 3\h@one@third@hex@wd+3*\h@l\h@one@third@hex@wd,
854 -\hx@board@size\h@half@hex@ht-
855 \h@half@hex@ht+\h@l\h@half@hex@ht);
856 \ifh@show@coordinates
857 \h@top@left@color at (\h@letter)
858 {\HCoordinateStyle{\h@letter}};
859 \h@top@left@color at (-\h@letter)
860 {\HCoordinateStyle{\h@letter}};
861 \fi
862 \fi
863 }%
864 \ifh@show@coordinates
865 \foreach \h@n in {1,...,\hx@board@size} {%
866 \coordinate (\h@n) at
867 (3*\h@n\h@one@third@hex@wd,-1*\h@n\h@half@hex@ht);
868 \coordinate (-\h@n) at
869 (3*\hx@board@size\h@one@third@hex@wd+3\h@one@third@hex@wd+
870 3*\h@n\h@one@third@hex@wd,
871 \hx@board@size\h@half@hex@ht+\h@half@hex@ht-\h@n\h@half@hex@ht);
872 \h@bottom@left@color at (\h@n)
873 {\HCoordinateStyle{\h@n}};
874 \h@bottom@left@color at (-\h@n)
875 {\HCoordinateStyle{\h@n}};
876 }%
877 \fi
878 }
879 {}
880 % \end{macrocode}
881 %
882 % The |HexBoard| environment just wraps |InnerHexBoard|
883 % inside a |tikzpicture|.
884 % \begin{macrocode}
885 \newenvironment{HexBoard}[1][]{%
886 \begin{tikzpicture}
887 \begin{InnerHexBoard}[#1,prefix=,x=0,y=0]
888 }
889 % \end{macrocode}
890 % Finally, |HexBoard| closes the |InnerHexBoard| and
891 % |tikzpicture| environments.
892 % \begin{macrocode}
893 { \end{InnerHexBoard}
894 \end{tikzpicture}
895 }
896 % \end{macrocode}
897 %
898 % The \cs{HGame} macro
899 % \begin{macrocode}
900 \newcount\h@move@number
901 \newdimen\HStoneDiameter
902 \newcommand\HGame[2][]{%
903 \pgfqkeys{/h@game}{#1}%
904 \HStoneDiameter=\h@relative@stone@size\h@half@hex@ht
905 \multiply\HStoneDiameter by 2
906 \h@move@number=0
907 \ifh@numbered@moves
908 \def\h@label{\HMoveNumberStyle{\h@first@move@label}%
909 \global\def\h@label{\HMoveNumberStyle{\the\h@move@number}}}
910 \else
911 \def\h@label{}
912 \fi
913 \foreach \h@coord in {#2} {%
914 \global\advance\h@move@number by 1
915 \ifodd\h@move@number
916 \HBeforeOddMove
917 \h@odd@player at (\h@coord) {\h@label};
918 \else
919 \HBeforeEvenMove
920 \h@even@player at (\h@coord) {\h@label};
921 \fi
922 }
923 }
924 % \end{macrocode}
925 %
926 % The \cs{HStoneGroup}
927 % \begin{macrocode}
928 \newcommand\HStoneGroup[2][]{%
929 \let\h@player\empty
930 \let\h@label\empty
931 \pgfqkeys{/h@stone@group}{#1}%
932 \ifx\h@player\empty
933 \errmessage{No color specified for HStoneGroup}
934 \fi
935 \HStoneDiameter=\h@relative@stone@size\h@half@hex@ht
936 \multiply\HStoneDiameter by 2
937 \foreach \h@coord in {#2} {%
938 \HBeforeStone
939 \h@player at (\h@coord) {\h@label};
940 }%
941 }
942 % \end{macrocode}
943 %
944 % The \cs{HHexGroup}
945 % \begin{macrocode}
946 \newcommand\HHexGroup[2][]{%
947 \let\h@label\empty
948 \pgfqkeys{/h@hex@group}{#1}%
949 \foreach \h@coord in {#2} {%
950 \node at (\h@coord) {\h@label};
951 \h@draw@hex{\h@coord}%
952 }%
953 }
954 % \end{macrocode}
955 %
956 % That's all, folks.
957 % \begin{macrocode}
958 %</package>
959 % \end{macrocode}
960 %
961 % \Finale