| 1 |
%\iffalse meta-comment |
| 2 |
%Copyright (c) 2022 Peter Rowlett |
| 3 |
% |
| 4 |
%Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
%of this software and associated documentation files (the "Software"), to deal |
| 6 |
%in the Software without restriction, including without limitation the rights |
| 7 |
%to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 |
%copies of the Software, and to permit persons to whom the Software is |
| 9 |
%furnished to do so, subject to the following conditions: |
| 10 |
% |
| 11 |
%The above copyright notice and this permission notice shall be included in all |
| 12 |
%copies or substantial portions of the Software. |
| 13 |
% |
| 14 |
%THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
%IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
%FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
%AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
%LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 |
%OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 |
%SOFTWARE. |
| 21 |
%\fi |
| 22 |
%\section{Background} |
| 23 |
% |
| 24 |
%\lstinline|nimsticks| is a package for \LaTeX{} that draws sticks for representating games of multi-pile Nim. |
| 25 |
% |
| 26 |
%Nim objects could be anything, of course, but conventionally sticks or stones are used. There are various types of dot in LaTeX that might look like stones, but somehow a line of dots didn't seem satisfactory. There are various ways to draw a line (e.g. just typing IIIII), including some tally markers (e.g. in hhcount). My problem with these (call me picky) is that they are all identical lines, and a `heap' of them just looks very organised. Really, I want a set of lines that looks like someone just threw them into heaps (though probably without crossings for the avoidance of ambiguity). |
| 27 |
% |
| 28 |
%The way this works is it draws a thick vertical line in TikZ with a little wobble added so each one doesn't look extremely well-lined-up with its neighbour, achieved by adding or subtracting a small random number to the top and bottom coordinate. There are various built-in options to customise the size and colour of the sticks, and flexibility to draw heaps of different objects. |
| 29 |
% |
| 30 |
%N.B. The precise look of example output in this document is affected by random wobble in the sticks. |
| 31 |
% |
| 32 |
%\section{Basic usage} |
| 33 |
% |
| 34 |
%\subsection{Draw a game of multi-pile Nim} |
| 35 |
% |
| 36 |
%For example, the input \lstinline!\nimgame{5,3,4}! will produce output like this: \nimgame{5,3,4} |
| 37 |
% |
| 38 |
%This is designed to look like a 3-pile Nim game with 5 sticks in the first pile (or heap), 3 in the second and 4 in the third. |
| 39 |
% |
| 40 |
%\lstinline|\nimgame| will happily work with one heap, so for example the input \lstinline!\nimgame{7}! will produce output like this: \nimgame{7} |
| 41 |
% |
| 42 |
%The command \lstinline|\nimgame| presents the Nim game as its own paragraph with \lstinline!\centering!. An optional flag \lstinline|inline| can be used to produce the Nim game inline without the \lstinline|\centering|. For example, the command \lstinline!\nimgame[inline]{5,3,4}! will produce outline like this: \nimgame[inline]{5,3,4} |
| 43 |
% |
| 44 |
%\subsection{Draw a single Nim stick} |
| 45 |
% |
| 46 |
%It is likely the user will want to use \lstinline|\nimgame| and not \lstinline|\drawnimstick| directly, but the input \lstinline|\drawnimstick| will produce output like this: \reinitrand[first=-100,last=100,seed=256]\drawnimstick |
| 47 |
% |
| 48 |
%\section{Customisation} |
| 49 |
% |
| 50 |
%\subsection{Colour} |
| 51 |
% |
| 52 |
%A command \lstinline|\setnimstickcolour{colour}| is used to set the colour of the sticks, by default black. The input \lstinline|colour| can be any named colour defined in the document. |
| 53 |
% |
| 54 |
%\begin{verbatim}\nimgame{3,4,5} |
| 55 |
% |
| 56 |
%\setnimstickcolour{blue}\nimgame{3,4,5} |
| 57 |
% |
| 58 |
%\setnimstickcolour{magenta}\nimgame{3,4,5} |
| 59 |
% |
| 60 |
%\definecolor{lightcornflowerblue}{rgb}{0.6, 0.81, 0.93} % from https://latexcolor.com/ |
| 61 |
%\setnimstickcolour{lightcornflowerblue}\nimgame{3,4,5}\end{verbatim} |
| 62 |
% |
| 63 |
%\nimgame{3,4,5} |
| 64 |
% |
| 65 |
%\setnimstickcolour{blue}\nimgame{3,4,5} |
| 66 |
% |
| 67 |
%\setnimstickcolour{magenta}\nimgame{3,4,5} |
| 68 |
% |
| 69 |
%\definecolor{lightcornflowerblue}{rgb}{0.6, 0.81, 0.93} |
| 70 |
%\setnimstickcolour{lightcornflowerblue}\nimgame{3,4,5} |
| 71 |
% |
| 72 |
%\setnimstickcolour{black} |
| 73 |
% |
| 74 |
%\section{Size} |
| 75 |
% |
| 76 |
%\subsection{Basic size configuration} |
| 77 |
% |
| 78 |
%\lstinline|\nimgame| and \lstinline|\drawnimstick| respond to the current text size, as demonstrated below. This is because their size is defined in ex, with the default height of a stick 3.3ex (roughly twice the size of a capital letter in the current font). |
| 79 |
% |
| 80 |
%\begin{tabular}{cc} |
| 81 |
% \tiny tiny: & \tiny\nimgame{3,4,5}\\ |
| 82 |
% \scriptsize scriptsize: & \scriptsize\nimgame{3,4,5}\\ |
| 83 |
% \footnotesize footnotesize: & \footnotesize\nimgame{3,4,5}\\ |
| 84 |
% \small small: & \small\nimgame{3,4,5}\\ |
| 85 |
% \normalsize normalsize: & \normalsize\nimgame{3,4,5}\\ |
| 86 |
% \large large: & \large\nimgame{3,4,5}\\ |
| 87 |
% \Large Large: & \Large\nimgame{3,4,5}\\ |
| 88 |
% \LARGE LARGE: & \LARGE\nimgame{3,4,5}\\ |
| 89 |
% \huge huge: & \huge\nimgame{3,4,5}\\ |
| 90 |
% \Huge Huge: & \Huge\nimgame{3,4,5}\\ |
| 91 |
%\end{tabular} |
| 92 |
% |
| 93 |
%\subsection{Advanced size configuration} |
| 94 |
% |
| 95 |
%The size can be further customised by a command \lstinline|\setnimscale{num}|. This controls the height of the sticks, their thickness, the gaps between sticks, the gaps between heaps and the size of the wobble. |
| 96 |
% |
| 97 |
%Usage is like \lstinline|\setnimscale{2}\nimgame{3,4,5}| |
| 98 |
% |
| 99 |
%For example: |
| 100 |
% |
| 101 |
%\begin{tabular}{cc} |
| 102 |
% \textbf{Nim scale} & \lstinline|\normalsize| \textbf{game}\\ |
| 103 |
% 0.5: & \setnimscale{0.5}\nimgame{3,4,5}\\ |
| 104 |
% 0.675: & \setnimscale{0.675}\nimgame{3,4,5}\\ |
| 105 |
% 1: & \setnimscale{1}\nimgame{3,4,5}\\ |
| 106 |
% 1.5: & \setnimscale{1.5}\nimgame{3,4,5}\\ |
| 107 |
% 2: & \setnimscale{2}\nimgame{3,4,5}\\ |
| 108 |
% 4: & \setnimscale{4}\nimgame{3,4,5}\\ |
| 109 |
%\end{tabular} |
| 110 |
%\setnimscale{1} |
| 111 |
% |
| 112 |
% |
| 113 |
%\section{Advanced use} |
| 114 |
% |
| 115 |
%\subsection{Changing the look of the Nim sticks/stones/etc.} |
| 116 |
% |
| 117 |
%There is a command \lstinline|\onenimstick| that includes only the TikZ code for drawing a single Nim stick. This can be redefined to draw different objects as Nim sticks using in principle arbitrary TikZ code. |
| 118 |
% |
| 119 |
%\lstinline|\onenimstick| is called from within a \lstinline|tikzpicture| environment. |
| 120 |
% |
| 121 |
%You have three randomisation parameters available to you: \begin{itemize} |
| 122 |
% \item \lstinline|\topx| and \lstinline|\botx|: small random numbers which are in the range \(-0.1\) to \(0.1\) (for default scale \lstinline|\normalsize| heaps). |
| 123 |
% \item \lstinline|\lift|: small random number which is in the range \(0\) to \(0.2\) (for default scale \lstinline|\normalsize| heaps). |
| 124 |
%\end{itemize} |
| 125 |
% |
| 126 |
%\subsubsection{Examples} |
| 127 |
% |
| 128 |
%\begin{enumerate} |
| 129 |
% \item Here we draw each stick as a little circle (to look like stones), with a little vertical \lstinline|\lift| to make them sit irregularly. |
| 130 |
% |
| 131 |
% \begin{verbatim}\renewcommand{\onenimstick}{% |
| 132 |
% \node[draw,black,fill=gray,circle] at (0,\lift) {}; |
| 133 |
%} |
| 134 |
%\nimgame{3,4,5} |
| 135 |
% |
| 136 |
%\nimgame{5,4,2,3}\end{verbatim} |
| 137 |
% |
| 138 |
% \renewcommand{\onenimstick}{% |
| 139 |
% \node[draw,black,fill=gray,circle] at (0,\lift) {}; |
| 140 |
% } |
| 141 |
% |
| 142 |
% \nimgame{3,4,5} |
| 143 |
% |
| 144 |
% \nimgame{5,4,2,3} |
| 145 |
% |
| 146 |
% \item Here we draw each stick as a little matchstick, with a little vertical \lstinline|\lift| to make them sit irregularly. |
| 147 |
% |
| 148 |
% \begin{verbatim}% Colours from https://latexcolor.com/ |
| 149 |
%\definecolor{goldenrod}{rgb}{0.85, 0.65, 0.13} |
| 150 |
%\definecolor{indianred}{rgb}{0.8, 0.36, 0.36} |
| 151 |
%\renewcommand{\onenimstick}{% |
| 152 |
% \draw[goldenrod,fill=goldenrod,rotate=\topx*40] (0,\lift) rectangle (0.14,1+\lift); |
| 153 |
% \draw[indianred,fill=indianred,rotate=\topx*40] (0.07,1+\lift) ellipse (0.1 and 0.2); |
| 154 |
%} |
| 155 |
%\nimgame{3,4,5} |
| 156 |
% |
| 157 |
%\nimgame{5,4,2,3}\end{verbatim} |
| 158 |
% |
| 159 |
% \definecolor{goldenrod}{rgb}{0.85, 0.65, 0.13} |
| 160 |
% \definecolor{indianred}{rgb}{0.8, 0.36, 0.36} |
| 161 |
% \renewcommand{\onenimstick}{% |
| 162 |
% \draw[goldenrod,fill=goldenrod,rotate=\topx*40] (0,\lift) rectangle (0.14,1+\lift); |
| 163 |
% \draw[indianred,fill=indianred,rotate=\topx*40] (0.07,1+\lift) ellipse (0.1 and 0.2); |
| 164 |
% } |
| 165 |
% |
| 166 |
% \nimgame{3,4,5} |
| 167 |
% |
| 168 |
% \nimgame{5,4,2,3} |
| 169 |
% |
| 170 |
% \item To demonstrate arbitrary drawing, here each item in the Nim heap is a little green rectangle, with size randomised using \lstinline|\topx| and \lstinline|\botx|, with a little vertical \lstinline|\lift| to make them sit irregularly. |
| 171 |
% |
| 172 |
% \begin{verbatim}\renewcommand{\onenimstick}{% |
| 173 |
% \draw[very thick,draw,fill=green] (0,\lift) rectangle (\topx+0.5,\botx+1+\lift); |
| 174 |
%} |
| 175 |
%\nimgame{3,4,5} |
| 176 |
% |
| 177 |
%\nimgame{5,4,2,3}\end{verbatim} |
| 178 |
% |
| 179 |
% \renewcommand{\onenimstick}{% |
| 180 |
% \draw[very thick,draw,fill=green] (0,\lift) rectangle (\topx+0.5,\botx+1+\lift); |
| 181 |
% } |
| 182 |
% |
| 183 |
% \nimgame{3,4,5} |
| 184 |
% |
| 185 |
% \nimgame{5,4,2,3} |
| 186 |
% |
| 187 |
% \item And, just to get silly: |
| 188 |
% |
| 189 |
% \begin{verbatim}% Colours from https://latexcolor.com/ |
| 190 |
%\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39} |
| 191 |
%\definecolor{arylideyellow}{rgb}{0.91, 0.84, 0.42} |
| 192 |
%\renewcommand{\onenimstick}{% |
| 193 |
% \node[draw,coolblack,fill=arylideyellow,rotate=90+\topx*60,anchor=north,rounded |
| 194 |
% corners=0.5ex] at (\topx,\botx) {\(e^{i\pi} + 1 = 0\)}; |
| 195 |
%} |
| 196 |
%\nimgame{3,4,5}\bigskip\end{verbatim} |
| 197 |
% |
| 198 |
% \definecolor{coolblack}{rgb}{0.0, 0.18, 0.39} |
| 199 |
% \definecolor{arylideyellow}{rgb}{0.91, 0.84, 0.42} |
| 200 |
% \renewcommand{\onenimstick}{% |
| 201 |
% \node[draw,coolblack,fill=arylideyellow,rotate=90+\topx*60,anchor=north,rounded corners=0.5ex] at (\topx,\botx) {\(e^{i\pi} + 1 = 0\)}; |
| 202 |
% } |
| 203 |
% {\footnotesize \nimgame{3,4,5} |
| 204 |
% |
| 205 |
% \nimgame{5,4,2,3}} |
| 206 |
% |
| 207 |
% \renewcommand{\onenimstick}{\draw[very thick,\nimstickcolour] (\topx,0ex) -- (\botx,\nimstickheight ex);} |
| 208 |
%\end{enumerate} |
| 209 |
% |
| 210 |
%\subsection{Creating the same randomisation twice} |
| 211 |
% |
| 212 |
%The randomisation is done with \lstinline|lcg| and you can set the seed using \lstinline|\reinitrand| from that package. The seed is supposed to be a number from \(1\) to \(2^{31} - 1\), otherwise the package will use a combination of the time, page number and line number to make the seed. So if you reset the randomisation to the same seed before running \lstinline|\drawnimstick| or \lstinline|\nimgame| you'll get the same look to the sticks. |
| 213 |
% |
| 214 |
%\subsubsection{Examples} |
| 215 |
% |
| 216 |
%\begin{enumerate} |
| 217 |
% \item Here we generate the same Nim pile twice with exact reproduction of the randomisation. The first pair of Nim games (without \lstinline|\reinitrand|) appear different; the second pair of Nim games appear identical because \lstinline|\reinitrand[first=-100,last=100,seed=1]| is used to reset the randomisation to the same point before each is drawn. Different seeds can be used if there are multiple sets of Nim games that require consistent looks. |
| 218 |
% |
| 219 |
% \begin{verbatim}\nimgame{3,4,5} |
| 220 |
% |
| 221 |
%\nimgame{3,4,5} |
| 222 |
% |
| 223 |
%\hrule |
| 224 |
% |
| 225 |
%\reinitrand[first=-100,last=100,seed=1] |
| 226 |
%\nimgame{3,4,5} |
| 227 |
% |
| 228 |
%\reinitrand[first=-100,last=100,seed=1] |
| 229 |
%\nimgame{3,4,5}\end{verbatim} |
| 230 |
% |
| 231 |
% \nimgame{3,4,5} |
| 232 |
% |
| 233 |
% \nimgame{3,4,5} |
| 234 |
% |
| 235 |
% \hrule |
| 236 |
% |
| 237 |
% \reinitrand[first=-100,last=100,seed=1] |
| 238 |
% \nimgame{3,4,5} |
| 239 |
% |
| 240 |
% \reinitrand[first=-100,last=100,seed=1] |
| 241 |
% \nimgame{3,4,5} |
| 242 |
% |
| 243 |
% \item Here we use nimsticks within Beamer with a reveal slide using \lstinline|\only|. On the first slide a Nim game is produced and when the slide is progressed to reveal ``Text'' the Nim sticks all move. On the second slide the Nim sticks do not move when ``Text'' is revealed. |
| 244 |
% |
| 245 |
% \begin{verbatim}\documentclass{beamer} |
| 246 |
%\usepackage{nimsticks} |
| 247 |
%\begin{document} |
| 248 |
%\begin{frame} |
| 249 |
% \nimgame{2,3,4} \only<2>{Text} |
| 250 |
%\end{frame} |
| 251 |
%\begin{frame} |
| 252 |
% \reinitrand[first=-100,last=100,seed=123]\nimgame{2,3,4} \only<2>{Text} |
| 253 |
%\end{frame} |
| 254 |
%\end{document}\end{verbatim} |
| 255 |
% |
| 256 |
% \item Here two pairs of Nim games are reproduced. Games 1 and 3 are identical using \lstinline|seed=1|, and games 2 and 4 are identical using \lstinline|seed=2|. |
| 257 |
% |
| 258 |
% \begin{verbatim}Game 1: \reinitrand[first=-100,last=100,seed=1]\nimgame{5,8,1,4} |
| 259 |
% |
| 260 |
%Game 2: \reinitrand[first=-100,last=100,seed=2]\nimgame{2,3} |
| 261 |
% |
| 262 |
%Game 3: \reinitrand[first=-100,last=100,seed=1]\nimgame{5,8,1,4} |
| 263 |
% |
| 264 |
%Game 4: \reinitrand[first=-100,last=100,seed=2]\nimgame{2,3}\end{verbatim} |
| 265 |
% |
| 266 |
% Game 1: \reinitrand[first=-100,last=100,seed=1]\nimgame{5,8,1,4} |
| 267 |
% |
| 268 |
% Game 2: \reinitrand[first=-100,last=100,seed=2]\nimgame{2,3} |
| 269 |
% |
| 270 |
% Game 3: \reinitrand[first=-100,last=100,seed=1]\nimgame{5,8,1,4} |
| 271 |
% |
| 272 |
% Game 4: \reinitrand[first=-100,last=100,seed=2]\nimgame{2,3} |
| 273 |
% |
| 274 |
%\end{enumerate} |
| 275 |
% |
| 276 |
%\section{Warnings} |
| 277 |
% |
| 278 |
%There is no limit in the code to the number of piles or the number in a pile, but this code doesn't do anything to cope when line breaks start happening, and presumably there is a computational limit. |
| 279 |
% |
| 280 |
%In principle, if you add lots of piles it will just wrap onto multiple lines, though it will start to look less clear. For example, the input\\ |
| 281 |
%\lstinline!\nimgame{1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1}!\\ |
| 282 |
%will produce the output: |
| 283 |
%\nimgame{1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1} |
| 284 |
%Similarly, if you have a lot of sticks in the same heap, it will wrap and look confusing, for example the input \lstinline!\nimgame{128}! will produce the output: |
| 285 |
%\nimgame{256} |
| 286 |
% |
| 287 |
% |
| 288 |
%\section{Changes to usage or output} |
| 289 |
% |
| 290 |
% (for full change log, see GitHub \lstinline|README.md|) |
| 291 |
% |
| 292 |
% \begin{itemize} |
| 293 |
% \item v2.0.1: documentation tweaks. |
| 294 |
% \item v2.0: rewrite, now based on ex and with options to customise size and colour, though basic usage should remain the same. More detailed documentation. Fixed a bug in v1.2 where a block display \lstinline|\nimgame| didn't start itself in a new paragraph. |
| 295 |
% \item v1.2: \begin{itemize} |
| 296 |
% \item switched \lstinline|\begin{center}| to \lstinline|\centering| (because the former doesn't work in \lstinline|standalone| documents and the latter doesn't add vertical space); |
| 297 |
% \item removed some whitespace that appeared to the right of the last heap. |
| 298 |
% \end{itemize} |
| 299 |
% \item v1.1: added option to make inline Nim game. |
| 300 |
%\end{itemize} |
| 301 |
%\iffalse |
| 302 |
%<*documentation> |
| 303 |
\documentclass{article} |
| 304 |
\usepackage{nimsticks} |
| 305 |
\usepackage{doc} |
| 306 |
\usepackage{listings} |
| 307 |
\lstset{basicstyle=\ttfamily\footnotesize,commentstyle=\color{white},language=TeX} |
| 308 |
\title{nimsticks v2.0.1} |
| 309 |
\author{Peter Rowlett} |
| 310 |
\begin{document} |
| 311 |
\maketitle |
| 312 |
\DocInput{nimsticks.dtx} |
| 313 |
\end{document} |
| 314 |
%</documentation> |
| 315 |
%\fi |
| 316 |
|
| 317 |
%\iffalse |
| 318 |
%<*nimsticks> |
| 319 |
\ProvidesPackage{nimsticks}[2022/08/14 nimsticks 2.0.1] |
| 320 |
\RequirePackage[first=-100,last=100,seed=0]{lcg} |
| 321 |
\RequirePackage{tikz} |
| 322 |
\RequirePackage{etoolbox} |
| 323 |
\@ifundefined{drawnimstick}{} |
| 324 |
{\PackageWarning{nimsticks}{Command `drawnimstick' already defined}} |
| 325 |
\@ifundefined{nimgame}{} |
| 326 |
{\PackageWarning{nimsticks}{Command `nimgame' already defined}} |
| 327 |
\@ifundefined{listofgames}{} |
| 328 |
{\PackageWarning{nimsticks}{Command `listofgames' already defined}} |
| 329 |
\@ifundefined{nimstickcolour}{} |
| 330 |
{\PackageWarning{nimsticks}{Command `nimstickcolour' already defined}} |
| 331 |
\@ifundefined{setnimstickcolour}{} |
| 332 |
{\PackageWarning{nimsticks}{Command `setnimstickcolour' already defined}} |
| 333 |
\@ifundefined{nimstickheight}{} |
| 334 |
{\PackageWarning{nimsticks}{Command `nimstickheight' already defined}} |
| 335 |
\@ifundefined{nimstickthickness}{} |
| 336 |
{\PackageWarning{nimsticks}{Command `nimstickthickness' already defined}} |
| 337 |
\@ifundefined{nimstickgap}{} |
| 338 |
{\PackageWarning{nimsticks}{Command `nimstickgap' already defined}} |
| 339 |
\@ifundefined{nimheapgap}{} |
| 340 |
{\PackageWarning{nimsticks}{Command `nimheapgap' already defined}} |
| 341 |
\@ifundefined{nimheapwobble}{} |
| 342 |
{\PackageWarning{nimsticks}{Command `nimheapwobble' already defined}} |
| 343 |
\@ifundefined{nimheaplift}{} |
| 344 |
{\PackageWarning{nimsticks}{Command `nimheaplift' already defined}} |
| 345 |
\@ifundefined{nimrandrange}{} |
| 346 |
{\PackageWarning{nimsticks}{Command `nimrandrange' already defined}} |
| 347 |
\@ifundefined{setnimscale}{} |
| 348 |
{\PackageWarning{nimsticks}{Command `setnimscale' already defined}} |
| 349 |
\@ifundefined{onenimstick}{} |
| 350 |
{\PackageWarning{nimsticks}{Command `onenimstick' already defined}} |
| 351 |
\@ifundefined{topx}{} |
| 352 |
{\PackageWarning{nimsticks}{Command `topx' already defined}} |
| 353 |
\@ifundefined{botx}{} |
| 354 |
{\PackageWarning{nimsticks}{Command `botx' already defined}} |
| 355 |
\@ifundefined{lift}{} |
| 356 |
{\PackageWarning{nimsticks}{Command `lift' already defined}} |
| 357 |
\@ifundefined{heap}{} |
| 358 |
{\PackageWarning{nimsticks}{Command `heap' already defined}} |
| 359 |
\@ifundefined{heapindex}{} |
| 360 |
{\PackageWarning{nimsticks}{Command `heapindex' already defined}} |
| 361 |
|
| 362 |
% Colour |
| 363 |
\newcommand{\nimstickcolour}{black} |
| 364 |
\newcommand{\setnimstickcolour}[1]{% |
| 365 |
\renewcommand{\nimstickcolour}{#1} |
| 366 |
} |
| 367 |
|
| 368 |
% Size |
| 369 |
\newcommand{\nimstickheight}{3.3} % in ex |
| 370 |
\newcommand{\nimstickthickness}{0.3} % in ex |
| 371 |
\newcommand{\nimstickgap}{0.3} % in ex |
| 372 |
\newcommand{\nimheapgap}{5} % in ex |
| 373 |
\newcommand{\nimheapwobble}{0.001} % in ex |
| 374 |
\newcommand{\nimheaplift}{0.002} % in ex |
| 375 |
\newcommand{\nimrandrange}{100} |
| 376 |
\newcommand{\setnimscale}[1]{% |
| 377 |
\pgfmathsetmacro{\nimstickheight}{3.3*#1}% |
| 378 |
\pgfmathsetmacro{\nimstickthickness}{0.3*#1}% |
| 379 |
\pgfmathsetmacro{\nimstickgap}{0.3*#1^(0.5)}% |
| 380 |
\pgfmathsetmacro{\nimheapgap}{5*#1^(0.25)}% |
| 381 |
\pgfmathsetmacro{\nimheapwobble}{0.001*#1^(0.25)}% |
| 382 |
\pgfmathsetmacro{\nimheaplift}{0.002*#1}% |
| 383 |
\pgfmathtruncatemacro{\nimrandrange}{100*#1}\reinitrand[first=-\nimrandrange,last=\nimrandrange,seed=0]% |
| 384 |
} |
| 385 |
|
| 386 |
% drawing a single Nim stick |
| 387 |
\newcommand{\onenimstick}{\draw[line width=\nimstickthickness ex,\nimstickcolour] (\topx,0ex) -- (\botx,\nimstickheight ex);} |
| 388 |
\newcommand{\drawnimstick}{% |
| 389 |
\rand\pgfmathsetmacro{\topx}{(\the\value{rand})*\nimheapwobble}% |
| 390 |
\rand\pgfmathsetmacro{\botx}{(\the\value{rand})*\nimheapwobble}% |
| 391 |
\rand\pgfmathsetmacro{\lift}{(\nimrandrange+\the\value{rand})*\nimheaplift}% |
| 392 |
\begin{tikzpicture} |
| 393 |
\node[inner sep=0] at (0,0) {}; % to anchor the diagram so any random movement isn't recentred |
| 394 |
\onenimstick |
| 395 |
\end{tikzpicture}% |
| 396 |
} |
| 397 |
\newcommand{\nimgame}[2][block]{% |
| 398 |
\ifstrequal{#1}{inline}{}{\par\bgroup\centering}% |
| 399 |
\def\listofgames{#2}% |
| 400 |
\foreach \heap in \listofgames {% |
| 401 |
\foreach \heapindex in {1, ..., \heap} {% |
| 402 |
\drawnimstick\hspace{\nimstickgap ex}% |
| 403 |
}% |
| 404 |
\hspace{\nimheapgap ex}% |
| 405 |
}\hspace{-\nimheapgap ex}% |
| 406 |
\ifstrequal{#1}{inline}{}{\par\egroup}% |
| 407 |
} |
| 408 |
%</nimsticks> |
| 409 |
%\fi |