summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/psgo/psgo.sty
blob: 93d71470332b93db0c2a14c3173e12af292c9808 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
%% psgo.sty
%% Copyright 2004, 2003,2001 V. Bos
%
% This program may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% This program consists of the files:
%
%   psgo.sty
%   psgomanual.tex
%   psgomanual.ps
%
% RCS-ID: $Id: psgo.sty,v 1.7 2004/02/24 10:20:11 vbos Exp $
%
\NeedsTeXFormat{LaTeX2e}% 
\ProvidesPackage{psgo}[2003/10/06, v0.16]
\message{`PSGO', <2004/02/24>, v0.16}
\RequirePackage{pstricks,pstcol,pst-node,calc,ifthen}

\newcommand{\psgo}{\textsf{psgo}}
\newsavebox{\stmarkbox}
\newcounter{gomove}
\setcounter{gomove}{-1}
\newcounter{boardsize}
\newboolean{blackmove}
\setboolean{blackmove}{true}
\newcommand{\toggleblackmove}{%
  \ifthenelse{\boolean{blackmove}}{\setboolean{blackmove}{false}}{\setboolean{blackmove}{true}}%
}
\newlength{\goxunit}
\newlength{\goyunit}
\newcommand{\setgounit}[1]{\setlength{\goxunit}{#1}\setlength{\goyunit}{1.115\goxunit}}
\setgounit{0.6cm}
\newcommand{\hatchangle}{-42.5}
\newlength{\tmplx}
\newlength{\tmply}
\newlength{\tmpxa}%
\newlength{\tmpxb}%
\newlength{\tmpya}%
\newlength{\tmpyb}%
\newcounter{gotmpc}
\newcommand{\pointbox}[1]{\raisebox{-0.5\height+0.5\depth}[0pt][0pt]{\makebox[0pt]{#1}}}
\newcommand{\golabelformat}[1]{{\sffamily #1}}
\newcommand{\goxposition}[1]{%
	\ifx#1a 0\else%
	\ifx#1b 1\else%
	\ifx#1c 2\else%
	\ifx#1d 3\else%
	\ifx#1e 4\else%
	\ifx#1f 5\else%
	\ifx#1g 6\else%
	\ifx#1h 7\else%
	\ifx#1j 8\else%
	\ifx#1k 9\else%
	\ifx#1l 10\else%
	\ifx#1m 11\else%
	\ifx#1n 12\else%
	\ifx#1o 13\else%
	\ifx#1p 14\else%
	\ifx#1q 15\else%
	\ifx#1r 16\else%
	\ifx#1s 17\else%
	\ifx#1t 18\else%
	\relax%
	\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
}%
\newcommand{\goyposition}[1]{%
	\ifnum#1=1 0\else%
	\ifnum#1=2 1\else%
	\ifnum#1=3 2\else%
	\ifnum#1=4 3\else%
	\ifnum#1=5 4\else%
	\ifnum#1=6 5\else%
	\ifnum#1=7 6\else%
	\ifnum#1=8 7\else%
	\ifnum#1=9 8\else%
	\ifnum#1=10 9\else%
	\ifnum#1=11 10\else%
	\ifnum#1=12 11\else%
	\ifnum#1=13 12\else%
	\ifnum#1=14 13\else%
	\ifnum#1=15 14\else%
	\ifnum#1=16 15\else%
	\ifnum#1=17 16\else%
	\ifnum#1=18 17\else%
	\ifnum#1=19 18\else%
	\relax%
	\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
}%

\newenvironment{gomoves}{%
	\newcommand{\mdd}[4]{%
		\setlength{\tmpxa}{\goxposition{##1}\goxunit}\addtolength{\tmpxa}{-0.5\goxunit}%
		\setlength{\tmpxb}{\goxposition{##3}\goxunit}\addtolength{\tmpxb}{0.5\goxunit}%
		\setlength{\tmpya}{\goyposition{##2}\goyunit}\addtolength{\tmpya}{-0.5\goyunit}%
		\setlength{\tmpyb}{\goyposition{##4}\goyunit}\addtolength{\tmpyb}{0.5\goyunit}%
		\psframe[dimen=middle,fillstyle=vlines,hatchsep=2pt,hatchwidth=0.2pt,hatchangle=\hatchangle,linestyle=none]%
		(\tmpxa,\tmpya)(\tmpxb,\tmpyb)%
		}%
	\newcommand{\placesymbol}[3]{%
		\ifthenelse{\value{boardsize} > \goxposition{##2}%
                            \and \value{boardsize} > \goyposition{##3}}{%
			\rput(\goxposition{##2},\goyposition{##3}){##1}%
		}{}%
		}%
	\newcommand{\markpos}[3]{\placesymbol{\psframebox[dimen=inner,fillcolor=white,fillstyle=solid,linestyle=none,boxsep=false,framesep=0.3\goxunit]{##1}}{##2}{##3}}%
	\newcommand{\blackstone}[3][\relax]{%
		\placesymbol{\pscircle[linewidth=0.4pt,fillstyle=solid,fillcolor=black](0,0){0.5\goxunit}%
			  {\psset{linecolor=white,fillcolor=white,hatchcolor=gray}\color{white}##1}}{##2}{##3}%
		}%
	\newcommand{\whitestone}[3][\relax]{%
		\placesymbol{\pscircle[linewidth=0.4pt,fillstyle=solid,fillcolor=white](0,0){0.5\goxunit}%
			  {\psset{linecolor=black,fillcolor=black,hatchcolor=gray}\color{black}##1}}{##2}{##3}%
		}%
	\renewcommand{\stone}[4][\nomark{\relax}]{%
%		\def\stmark{\raisebox{-0.5\height+0.5\depth}[0.5\totalheight][0.5\totalheight]{\makebox[0pt]{##1}}}%
		\def\stmark{\pointbox{##1}}
		\ifthenelse{\equal{##2}{black}}%
			   {\blackstone[\stmark]{##3}{##4}}%
			   {\whitestone[\stmark]{##3}{##4}}%
		}%
	\newcommand{\move}{\@ifstar{\movestar}{\movenostar}}%
	\newcommand{\movestar}[3][\nomark]{%
		\ifthenelse{\boolean{blackmove}}%
		           {\stone[##1]{black}{##2}{##3}}%
		           {\stone[##1]{white}{##2}{##3}}%
		\toggleblackmove%
		}%
	\newcommand{\movenostar}[3][\nomark]{%
		\refstepcounter{gomove}%		
		\ifthenelse{\boolean{blackmove}}%
		           {\stone[##1\rput(0,0){\golabelformat{\thegomove}}]{black}{##2}{##3}}%
		           {\stone[##1\rput(0,0){\golabelformat{\thegomove}}]{white}{##2}{##3}}%
		\toggleblackmove%
		}%
    \newcommand{\pass}{\@ifstar{\passstar}{\passnostar}}%
    \newcommand{\passstar}{\toggleblackmove}%
    \newcommand{\passnostar}{\refstepcounter{gomove}\toggleblackmove}%
	\newcommand{\goline}[4]{\psline[linewidth=1.4pt,linecolor=black,linestyle=solid]%
		(\goxposition{##1},\goyposition{##2})(\goxposition{##3},\goyposition{##4})%
		}%
	\newcommand{\goarrow}[4]{\psline[linewidth=1.4pt,linecolor=black,linestyle=solid,arrowscale=1.5]%
		{->}%
		(\goxposition{##1},\goyposition{##2})(\goxposition{##3},\goyposition{##4})%
		}%
	}{}%
\newcommand{\xpositionmarks}[2]{%
	\whiledo{\value{#1} < #2}{%
	  \rput[t](\value{#1},-\goyunit){%
	    \addtocounter{#1}{1}%
	    \ifthenelse{\value{#1} > 8}%
	      {\addtocounter{#1}{1}\golabelformat{\Alph{#1}}\addtocounter{#1}{-1}}%
	      {\golabelformat{\Alph{#1}}}%
	    \addtocounter{#1}{-1}}%
      \setlength{\tmply}{#2\goyunit}%
	  \rput[B](\value{#1},\tmply){%
	    \addtocounter{#1}{1}%
	    \ifthenelse{\value{#1} > 8}%
	      {\addtocounter{#1}{1}\golabelformat{\Alph{#1}}\addtocounter{#1}{-1}}%
	      {\golabelformat{\Alph{#1}}}%
	    \addtocounter{#1}{-1}}%
	  \stepcounter{#1}%
	  }%
	}%
\newcommand{\ypositionmarks}[2]{%
	\whiledo{\value{#1} < #2}{%
	  \addtocounter{#1}{1}%
	  \edef\ypos{\arabic{#1}}%
	  \addtocounter{#1}{-1}%
	  \rput[r](-\goxunit,\value{#1}){\golabelformat{\ypos}}%
      \setlength{\tmplx}{#2\goxunit}%
	  \rput[l](\tmplx,\value{#1}){\golabelformat{\ypos}}%
	  \stepcounter{#1}%
	  }%
	}%

\def\psgosetboardsizes(#1,#2)(#3,#4){%
  \def\psgollx{#1}%
  \def\psgolly{#2}%
  \ifthenelse{#3 > \value{boardsize}}{\def\psgourx{\value{boardsize}}}{\def\psgourx{#3}}%
  \ifthenelse{#4 > \value{boardsize}}{\def\psgoury{\value{boardsize}}}{\def\psgoury{#4}}%
}
\newboolean{withindices}%
\setboolean{withindices}{true}%
\newenvironment{psgopartialboard}[2][19]{%
	\setcounter{boardsize}{#1}%
    \psgosetboardsizes#2%
	\psset{xunit=\goxunit,yunit=\goyunit}%
    \ifthenelse{\boolean{withindices}}%
               {\def\xoffset{2\goxunit}\def\yoffset{2\goyunit}}%
               {\def\xoffset{.5\goxunit}\def\yoffset{.5\goyunit}}%
    \ifthenelse{\psgollx = 1 \or \psgollx < 1}%
               {\def\psgollxval{-\xoffset}}%
               {\setlength{\tmplx}{\psgollx\goxunit - 1\goxunit}\edef\psgollxval{\the\tmplx}}%
    \ifthenelse{\psgolly = 1 \or \psgolly < 1}%
               {\def\psgollyval{-\yoffset}}%
               {\setlength{\tmply}{\psgolly\goyunit - 1\goyunit}\edef\psgollyval{\the\tmply}}%
    \ifthenelse{\psgourx = \value{boardsize} \or \psgourx > \value{boardsize}}%
               {\setlength{\tmplx}{\value{boardsize}\goxunit - \goxunit + \xoffset}%
                \edef\psgourxval{\the\tmplx}}%
               {\def\psgourxval{\psgourx\goxunit}}%
    \ifthenelse{\psgoury = \value{boardsize} \or \psgoury > \value{boardsize}}%
               {\setlength{\tmply}{\value{boardsize}\goyunit - \goyunit + \yoffset}%
                \edef\psgouryval{\the\tmply}}%
               {\def\psgouryval{\psgoury\goyunit}}%
	\begin{pspicture}(\psgollxval,\psgollyval)(\psgourxval,\psgouryval)%
    \ifthenelse{\psgollx = 1 \or \psgollx < 1}%
               {\def\psgollxval{-\xoffset}}%
               {\setlength{\tmplx}{\psgollx\goxunit - 1.5\goxunit}\edef\psgollxval{\the\tmplx}}%
    \ifthenelse{\psgolly = 1 \or \psgolly < 1}%
               {\def\psgollyval{-\yoffset}}%
               {\setlength{\tmply}{\psgolly\goyunit - 1.5\goyunit}\edef\psgollyval{\the\tmply}}%
    \ifthenelse{\psgourx = \value{boardsize} \or \psgourx > \value{boardsize}}%
               {\setlength{\tmplx}{\value{boardsize}\goxunit - \goxunit + \xoffset}%
                \edef\psgourxval{\the\tmplx}}%
               {\setlength{\tmplx}{\psgourx\goxunit - .5\goxunit}%
                \edef\psgourxval{\the\tmplx}}%
    \ifthenelse{\psgoury = \value{boardsize} \or \psgoury > \value{boardsize}}%
               {\setlength{\tmply}{\value{boardsize}\goyunit - \goyunit + \yoffset}%
                \edef\psgouryval{\the\tmply}}%
               {\setlength{\tmply}{\psgoury\goyunit - .5\goyunit}%
                \edef\psgouryval{\the\tmply}}%
    %% uncomment the following line to get a visual bounding box 
    %% \psframe[linecolor=green,linewidth=0.4pt](\psgollxval,\psgollyval)(\psgourxval,\psgouryval)
    \psclip{\psframe[linecolor=white,linewidth=0](\psgollxval,\psgollyval)(\psgourxval,\psgouryval)}%
	\setlength{\tmply}{\value{boardsize}\goyunit + 0.5\goyunit}%
	\setlength{\tmplx}{\value{boardsize}\goxunit + 0.5\goxunit}%
	\addtolength{\tmply}{-1.5\goyunit}%
	\addtolength{\tmplx}{-1.5\goxunit}%
	\multips(0,0)(1,0){\value{boardsize}}{\psline[linewidth=0.2pt](0,0)(0,\tmply)}%
	\multips(0,0)(0,1){\value{boardsize}}{\psline[linewidth=0.2pt](0,0)(\tmplx,0)}%
	\psframe[linewidth=1pt](0,0)(\tmplx,\tmply)%
    \ifthenelse{\boolean{withindices}}{%
	  \setcounter{gotmpc}{0}%
	  \xpositionmarks{gotmpc}{\value{boardsize}}%
	  \setcounter{gotmpc}{0}%
	  \ypositionmarks{gotmpc}{\value{boardsize}}%
    }{\relax}%
	\ifthenelse{\equal{\value{boardsize}}{19}}{%
	  \multips(3,3)(0,6){3}{\pscircle[fillstyle=solid,fillcolor=black](0,0){.15\goxunit}}%
	  \multips(9,3)(0,6){3}{\pscircle[fillstyle=solid,fillcolor=black](0,0){.15\goxunit}}%
	  \multips(15,3)(0,6){3}{\pscircle[fillstyle=solid,fillcolor=black](0,0){.15\goxunit}}%
	}{\relax}%
	\begin{gomoves}%
	}%
	{\end{gomoves}%
    \endpsclip%
	\end{pspicture}%
	}%
\newenvironment{psgoboard}[1][19]{%
  \begin{psgopartialboard}[#1]{(0,0)(#1,#1)}%
}{%
  \end{psgopartialboard}%
}

\newenvironment{psgopartialboard*}[2][19]{%
  \setboolean{withindices}{false}%
  \begin{psgopartialboard}[#1]{#2}%
}{\end{psgopartialboard}}

\newenvironment{psgoboard*}[1][19]{%
  \begin{psgopartialboard*}[#1]{(0,0)(#1,#1)}%
}{%
  \end{psgopartialboard*}%
}

\newcommand{\nomark}{\relax}%
\newcommand{\factor}{0.28284271247461901}% = 2/5 * sin(1/4 * pi)
\newcommand{\markma}{%
	\psline[linewidth=1.4pt](-\factor,-\factor)(\factor,\factor)%
	\psline[linewidth=1.4pt](-\factor,\factor)(\factor,-\factor)%
	}
\newcommand{\marktr}{%
	\rput(0,-0.3\goxunit){\pstriangle(-0.66\goxunit,0.66\goxunit)}%
	}%
\newcommand{\markcr}{%
	\pscircle(0,0){0.33\goxunit}%
	}
\newcommand{\marksq}{%
	\psframe(-0.33\goxunit,-0.33\goxunit)(0.33\goxunit,0.33\goxunit)%
	}
\newcommand{\marklb}[1]{%
	\rput(0,0){\golabelformat{#1}}%
	}%
\newcommand{\marksl}{%
	\psframe[fillstyle=solid,fillcolor=gray,linecolor=gray](-0.22\goxunit,-0.22\goxunit)(0.22\goxunit,0.22\goxunit)%
	}%
\newcommand{\markdd}{%
	\psframe[dimen=middle,fillstyle=vlines,hatchsep=2pt,hatchwidth=0.2pt,hatchangle=\hatchangle,linestyle=none]%
	(-0.5\goxunit,-0.5\goyunit)(0.5\goxunit,0.5\goyunit)%
	}%
\newcommand{\stone}[2][\relax]{%
  \setlength{\tmply}{-0.5\goxunit + 0.5ex}%
  \raisebox{\tmply}{\psset{unit=\goxunit}\begin{pspicture}(-0.5,-0)(0.5,1)%
    \pscircle[fillstyle=solid,fillcolor=#2](0,0.5){0.5}%
    \ifthenelse{\equal{#2}{black}}%
      {\rput(0,0.5){{\psset{linecolor=white}\color{white}\golabelformat{#1}}}}%
      {\rput(0,0.5){{\psset{linecolor=black}\color{black}\golabelformat{#1}}}}%
  \end{pspicture}}}