Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %%
3 %% 文件:weiqi.dtx
4 %%
5 %% 版权 (C) 2023-2024 By Ms_yam
6 %%
7 %% 它可以在 LaTeX 项目公共许可(LPPL)1.3c 及之后的任意版本(随你的意见)下分发或修改。
8 %% 这个许可的最新版本在如下文件中:
9 %%
10 %% https://www.latex-project.org/lppl.txt
11 %%
12 %% 本宏包为作者练习 epxl3 和编写 dtx 文件所编写,里面的接口及方法并不是最优的。
13 %% 仅供参考。
14 %%
15 % \fi
16 %
17 % \iffalse
18 %<*driver>
19 \documentclass[full]{l3doc}
20
21 \usepackage{weiqi}
22
23 % 创建代码示例
24 \usepackage{listings}
25 \ExplSyntaxOn
26 \makeatletter
27 \lst@RequireAspects{writefile}
28 \box_new:N \l__demo_box
29 \lstnewenvironment{demo}[1][code and example]
30 {
31 \use:c { demo_#1: }
32 }
33 { \use:c { demo_#1_end: } }
34 \cs_new:Nn \__demo_common:
35 {
36 \setkeys{lst}
37 {
38 basicstyle = \ttfamily,
39 gobble = 2,
40 language = [LaTeX]{TeX},
41 }
42 }
43 \cs_new:Nn \__demo_input:
44 {
45 \catcode`\^^M = 10\relax
46 \catcode`\% = 14\relax
47 \input{\jobname.tmp}
48 }
49 \cs_new:Npn \__demo_init:nnn #1#2#3
50 {
51 \cs_set:cn {demo_#1:} { #2 }
52 \cs_set:cn {demo_#1_end:} { #3 }
53 }
54
55 \__demo_init:nnn{code and example}
56 {%
57 \hbox_set:Nw \l__demo_box
58 \__demo_common:
59 \lst@BeginAlsoWriteFile{\jobname.tmp}%
60 }
61 {%
62 \lst@EndWriteFile
63 \hbox_set_end:
64 %\begin{center}
65 \fp_compare:nNnTF
66 { \box_wd:N \l__demo_box } > { 0.6 * \linewidth }
67 {
68 \begin{minipage}{\linewidth}
69 \box_use:N \l__demo_box
70 \end{minipage}%
71 \par
72 \begin{minipage}{\linewidth}
73 \__demo_input:
74 \end{minipage}
75 }
76 {
77 \begin{minipage}{0.40\linewidth}
78 \__demo_input:
79 \end{minipage}%
80 %\hfil
81 \begin{minipage}{0.54\linewidth}
82 \box_use:N \l__demo_box
83 \end{minipage}%
84 }
85 %\end{center}
86 }
87 \makeatother
88 \ExplSyntaxOff
89
90 % ^^A 添加中文支持及设置超级链接
91 \usepackage[UTF8,hyperref]{ctex}
92 \hypersetup{
93 colorlinks,
94 linkcolor=blue,
95 hyperindex,
96 pdfstartview=FitH,
97 plainpages=false,
98 backref,
99 }
100
101 % ^^A 引用待办包
102 \usepackage{todo}
103
104 % ^^A 汉化 l3doc 的部分定义
105 \NewDocumentEnvironment { texnote } { }% 不能用 Renew...,原因未知
106 {
107 \endgraf
108 \vspace{0.5em}% 3mm => 0.5em
109 \small\textbf{\TeX{} 黑客笔记:}% \TeX~hackers~note:
110 }
111 {
112 \vspace{0.5em}% 3mm => 0.5em
113 }
114
115 \begin{document}
116 \DocInput{\jobname.dtx}
117 \todos % ^^A 列出待办事宜
118 \end{document}
119 %</driver>
120 % \fi
121 %
122 % \title{^^A
123 % \pkg{weiqi}宏包:绘制围棋棋谱^^A
124 % }
125 %
126 % \author{Ms\_yam\thanks
127 % {^^A
128 % 本宏包是作者练习 \LaTeX3 和编写 dtx 文件的作品,里面的接口及方法并未优化;但宏包漏洞会尽力修复。
129 % }^^A
130 % \ (\href{mailto:[email protected]}{Ms\[email protected]})^^A
131 % }
132 % \date{\zhdigits*{2024}年\zhnumber{02}月\zhnumber{22}日}
133 %
134 % \maketitle
135 %
136 % \DoNotIndex{\[,\\,\]}
137 % \DoNotIndex{\Large, \meta, \noindent, \textbf, \texttt}
138 % \DoNotIndex{\ExplSyntaxOn, \ExplSyntaxOff, \NeedsTeXFormat, \RequirePackage, \ProvidesExplPackage, \NewDocumentCommand}
139 % \DoNotIndex{\IfBooleanT, \IfBooleanF, \IfNoValueTF}
140 % \DoNotIndex{\bool_new:N, \bool_set_eq:NN, \bool_set_false:N, \bool_set_inverse:N, \bool_set_true:N, \bool_to_str:N}
141 % \DoNotIndex{\bool_gset_eq:NN, \bool_gset_false:N, \bool_gset_true:N}
142 % \DoNotIndex{\bool_if:nT, \bool_if:NT, \bool_if:nTF, \bool_if:NTF}
143 % \DoNotIndex{\bool_lazy_all:nT, \bool_lazy_all:nTF, \bool_lazy_and:nnT, \bool_lazy_and:nnTF}
144 % \DoNotIndex{\bool_lazy_any:nTF, \bool_lazy_or:nnT, \bool_lazy_or:nnF, \bool_lazy_or:nnTF}
145 % \DoNotIndex{\box_ht:N, \box_wd:N}
146 % \DoNotIndex{\clist_new:N, \clist_const:Nn, \clist_clear:N, \clist_set:Nn, \clist_set_eq:NN, \clist_set_from_seq:NN, \clist_pop:NN, \clist_use:Nn}
147 % \DoNotIndex{\clist_gclear:N, \clist_gput_right:Nn, \clist_set_eq:Nc, \clist_gset_eq:NN, \clist_gset_eq:cN}
148 % \DoNotIndex{\clist_if_empty:NTF, \clist_map_function:NN, \clist_map_inline:Nn}
149 % \DoNotIndex{\color_fill:n, \color_select:n}
150 % \DoNotIndex{\cs_new:Nn, \cs_new:Npn, \cs_generate_variant:Nn, \cs_if_free:cT, \cs_if_free:cTF}
151 % \DoNotIndex{\draw_begin:, \draw_end:, \draw_linewidth:n, \draw_path_circle:nn, \draw_path_lineto:n, \draw_path_moveto:n}
152 % \DoNotIndex{\draw_box_use:Nn, \draw_path_use_clear:n, \draw_transform_scale:n}
153 % \DoNotIndex{\fp_new:N, \fp_set_eq:NN, \fp_set:Nn, \fp_add:Nn,\fp_sub:Nn, \fp_compare:nNnT, \fp_compare:nNnTF, \fp_gset:Nn, \fp_use:N}
154 % \DoNotIndex{\group_begin:, \group_end:}
155 % \DoNotIndex{\hbox_set:Nn}
156 % \DoNotIndex{\int_new:N, \int_new:c, \int_const:Nn, \int_set_eq:NN, \int_set_eq:Nc, \int_set:Nn, \int_set:Ne, \int_add:Nn, \int_incr:N, \int_use:N}
157 % \DoNotIndex{\int_gset:Nn, \int_gset:Ne, \int_gincr:N, \int_gset_eq:NN, \int_gset_eq:Nc, \int_gset_eq:cN}
158 % \DoNotIndex{\int_max:nn, \int_min:nn, \int_sign:n, \int_abs:n, \int_from_alph:n, \int_from_alph:e, \int_to_alph:n, \int_to_Alph:n}
159 % \DoNotIndex{\int_case:nn, \int_compare_p:n, \int_compare_p:nNn, \int_compare:nNnT, \int_compare:nNnF, \int_compare:nNnTF}
160 % \DoNotIndex{\int_if_zero:nF, \int_if_zero:nTF, \int_step_inline:nn, \int_step_inline:nnnn}
161 % \DoNotIndex{\intarray_new:Nn, \intarray_new:cn, \intarray_gset:Nnn, \intarray_gset:cnn, \intarray_gzero:N, \intarray_item:Nn, \intarray_item:cn}
162 % \DoNotIndex{\ior_open:Nn, \ior_close:N, \ior_str_map_inline:Nn}
163 % \DoNotIndex{\prg_set_conditional:Npnn, \prg_return_false:, \prg_return_true:, \prg_generate_conditional_variant:Nnn, \prg_break_point:, \prg_break:}
164 % \DoNotIndex{\regex_match:nn, \regex_match:nnTF, \regex_match:nVTF, \regex_extract_all:nnN}
165 % \DoNotIndex{\regex_extract_once:nnN, \regex_extract_once:nVN, \regex_extract_once:nnNTF, \regex_extract_once:nVNTF}
166 % \DoNotIndex{\seq_new:N, \seq_new:c, \seq_put_right:Nn, \seq_item:Nn, \seq_gclear:N, \seq_gset_item:Nnn, \seq_gset_item:NnV}
167 % \DoNotIndex{\seq_if_in:NnT, \seq_if_in:NnF, \seq_if_in:NnTF}
168 % \DoNotIndex{\str_new:N, \str_const:Nn, \str_set:Nn, \str_set:NV, \str_set:Nx, \str_set_eq:NN}
169 % \DoNotIndex{\str_put_right:Nn, \str_put_right:NV, \str_put_right:Nx}
170 % \DoNotIndex{\str_gset_eq:NN}
171 % \DoNotIndex{\str_head:N, \str_item:Nn, \str_range:Nnn, \str_range:nnn, \str_tail:N, \str_lowercase:n}
172 % \DoNotIndex{\str_if_empty_p:N, \str_if_empty:NTF, \str_if_empty:nTF, \str_if_eq_p:nn, \str_if_eq_p:Vn, \str_if_eq:nnTF}
173 % \DoNotIndex{\str_case:nn, \str_case_e:nn, \str_compare:eNeT, \str_compare:nNnTF, \str_compare:eNeTF}
174 %
175 % \begin{documentation}
176 %
177 % \section{\pkg{weiqi} 文档}
178 %
179 % 本宏包提供了绘制围棋棋谱功能。本宏包参考(或延用)了 \pkg{igo} 宏包的部分命令,
180 % 但本宏包的实现完全采用 \pkg{expl3} 方式。
181 %
182 % 本宏包的绘图采用 \pkg{l3draw} 宏包(2024-01-04 版)实现,因前者具有\emph{高度}实验性,因些本
183 % 宏包也同样具体\emph{高度}实验性。
184 %
185 %
186 % \subsection{相关概念}^^A
187 %
188 %
189 % \subsubsection{尺寸}
190 %
191 % 本宏包中的 \meta{尺寸} 特指棋盘尺寸(即一个方向包含几路),棋盘大小为 \meta{尺寸} x \meta{尺寸}。
192 % 本宏包支持的 \meta{尺寸} 取值为 $2$\~{}$26$,但通常建议使用 $9$、$13$ 和 $19$ 三种尺寸。
193 % 其中,$19$x$19$ 为标准棋盘大小(也是默认大小)。
194 %
195 %
196 % \subsubsection{坐标}
197 %
198 % 为方便描述落子位置,本宏包依惯例采用 \meta{坐标} 的概念。
199 % 本宏包支持两种形式的 \meta{坐标}:以左下角为起点(常规模式)和左上角为起点($SGF$ 模式)。
200 %
201 % 两种形式的横坐标相同,从左往右依次为 $a$、$b$、\dots。它们的区别在于:
202 % 前者纵坐标从下往上依次为 $1$、$2$、\dots;而后者的纵坐标从上往下依次为 $a$、$b$、\dots。
203 % 前者是为便于人员交互设计,后者是为支持 $sgf$ 棋谱坐标而设计。
204 %
205 % 横坐标与纵坐标组合形成 \meta{坐标},如 |a1|、|dp| 等。
206 % 通常需要 \meta{坐标} 的地方,也支持逗号列表形式的 \meta{坐标} 集合,如 “|a2, b2, dp|”。
207 %
208 % \begin{minipage}{0.45\linewidth}
209 % \newweiqi
210 % \showweiqi[a1,e4]
211 % \end{minipage}%
212 % \begin{minipage}{0.45\linewidth}
213 % \sgflocmode
214 % \showweiqi[aa,ed]
215 % \end{minipage}\\
216 %
217 %
218 % \subsubsection{虚着}
219 %
220 % 围棋有一个比较特殊的规则:它允许一方停一手(也叫虚着),另一方继续下。
221 % 为了以统一的方式记录每一手棋,特将虚着的 \meta{坐标} 定义为 |-| 或 |pass|。
222 %
223 % \subsection{基本命令}^^A
224 %
225 %
226 % \begin{function}{\newweiqi}
227 % \begin{syntax}
228 % \cs{newweiqi} [\meta{尺寸}]
229 % \end{syntax}
230 % 初始化新对局,\meta{尺寸}用于指定棋盘大小(默认为 $19$)。
231 % 带星号版本同时更改 \meta{尺寸} 的默认值。
232 % \end{function}
233 %
234 %
235 % \begin{function}{\weiqisize}
236 % \begin{syntax}
237 % \cs{weiqisize} \Arg{尺寸}
238 % \end{syntax}
239 % 修改棋盘大小为 \meta{尺寸}。
240 % 带星号版本同时更改 \meta{尺寸} 的默认值。
241 % \begin{texnote}
242 % 修改棋盘尺寸不会检查已有棋子是否越界。
243 % 同时还会引发已有的 \meta{坐标}为 $SGF$ 模式的棋子的位置错乱。
244 % \end{texnote}
245 % \end{function}
246 %
247 %
248 % \begin{function}{\weiqiblack, \weiqiwhite}
249 % \begin{syntax}
250 % \cs{weiqiblack} [\meta{标签}] \Arg{坐标}
251 % \end{syntax}
252 % 向当前对局中添加棋子。
253 % 其中,如果 \meta{标签} 为手数,则会自动递增且切换黑白方。
254 % 如果 \meta{标签} 为 $0$,则不显示标签但仍切换黑白方。
255 % \meta{坐标} 是一组表示棋子位置的逗号分隔列表,每一项表示一手棋;
256 % 默认以左下角的 \meta{坐标} 为 $a1$;虚着请使用 $-$、|pass| 或留空。
257 % \end{function}
258 %
259 %
260 % \begin{function}{\weiqidie}
261 % \begin{syntax}
262 % \cs{weiqidie} \Arg{坐标}
263 % \end{syntax}
264 % 设置指定位置的棋子为死子。
265 % \meta{坐标} 是一组表示棋子位置的逗号分隔列表,每一项表示一个位置。
266 % \begin{texnote}
267 % 死子是之前已经下过的棋子,因为没有气,所以需要从棋盘拿走。
268 % 将没有标签的棋子标记为死子是没有意义的。
269 % \end{texnote}
270 % \end{function}
271 %
272 %
273 % \begin{function}{\showweiqi}
274 % \begin{syntax}
275 % \cs{showweiqi} [\meta{区间}]
276 % \end{syntax}
277 % 绘制对局。如果指定 \meta{区间},则 \meta{区间} 应由两个角点坐标或 |full| 组成,以示指定区间内的信息;
278 % 如未指定区间,则会自动计算范围,该范围可保证至少包含一个角,其余边至少余一路。
279 % 默认情况显示完成后会清除对局,使用星号命令可保留对局。
280 % \begin{texnote}
281 % 自动计算的范围会考虑最小显示大小;如果指定区间,则不受此限制。区间外内容不会显示。
282 % \end{texnote}
283 % \end{function}
284 %
285 % \begin{demo}
286 % \newweiqi
287 % \weiqiblack[0]{bq,dq,-}
288 % \weiqiwhite[1]{b2,c2,c3,a2,d2,b1}
289 % \weiqiwhite[7]{-,b2}
290 % \weiqidie{b2}
291 % \showweiqi
292 % \end{demo}\\
293 %
294 %
295 % 死子和带标签(通常为手数)虚着会绘制在棋盘下方;不带标签的虚着则不会绘制(因为它没有任意实际意义)。
296 %
297 % \subsection{标签与指示点}^^A
298 %
299 %
300 % \begin{function}{\weiqilabel, \clearlabel}
301 % \begin{syntax}
302 % \cs{weiqilabel} [\meta{标签}] \Arg{坐标}\\
303 % \cs{clearlabel}
304 % \end{syntax}
305 % 向当前对局中添加标签,或清除对局中的所有标签。
306 % 其中,如果 \meta{标签} 为手数,则会自动递增。\meta{标签} 默认为 $a$。
307 % \meta{坐标} 是一组表示棋子位置的逗号分隔列表,每一项表示一个标签。
308 % 带星号版本在添加标签的同时会删除旧的标签。
309 % \begin{texnote}
310 % 如果 \meta{标签} 为 $0$ 或为空(|[]|),则显示实心空白圆。
311 % \meta{坐标} 规则与棋子一致,本规则在所有 \meta{坐标} 中生效。
312 % \end{texnote}
313 % \end{function}
314 %
315 %
316 % \begin{function}{\weiqired, \weiqigreen, \weiqiblue, \clearpoint}
317 % \begin{syntax}
318 % \cs{weiqired} \Arg{坐标}\\
319 % \cs{clearpoint}
320 % \end{syntax}
321 % 向当前对局中添加指示点,或清除所有指示点。
322 % \meta{坐标} 是一组表示棋子位置的逗号分隔列表,每一项表示一个点。
323 % 带星号版本在添加标签的同时会删除旧的指示点(含其它颜色)。
324 % \end{function}
325 %
326 %
327 % \begin{demo}
328 % \newweiqi
329 % \weiqiblack{a2,-,b1,cq}
330 % \weiqilabel[1]{c2,dq,-}
331 % \weiqired{d2,e3,-}
332 % \weiqigreen{b3}
333 % \showweiqi[a1,e3]
334 % \end{demo}
335 %
336 %
337 % \subsection{棋盘设置}^^A
338 %
339 %
340 % \begin{function}{\weiqirotate, \weiqimirror, \weiqiposition}
341 % \begin{syntax}
342 % \cs{weiqirotate} [\meta{角度}]\\
343 % \cs{weiqimirror} [\meta{镜像轴}]\\
344 % \cs{weiqiposition} [\meta{角度}]
345 % \end{syntax}
346 % 这三个命令用于设置棋盘的方位(旋转、镜像及指定方向)。
347 % 其中,前两个命令是基于已有方位的,最后一个则不考虑当前方位。\\
348 % \meta{角度}以度为单位(逆时针方向),如未指定,默认分别为 $90$ 度(旋转)和 $0$ 度(指定方向)。
349 % \meta{镜像轴} 应当为 $x$、$y$ 或 $xy$(默认) 三者之一。\\
350 % 使用星号命令可使当前棋盘方位为默认方位。
351 % \end{function}
352 %
353 %
354 % \begin{function}{\weiqiscale}
355 % \begin{syntax}
356 % \cs{weiqiscale} [\meta{比例}]
357 % \end{syntax}
358 % 按 \meta{比例} 缩放棋盘。 如未指定,则恢复默认比例。
359 % 使用星号命令可使当前缩放比例为默认缩放比例。缩放是基于原有比例的。
360 % \end{function}
361 %
362 %
363 % \begin{function}{\weiqiminsize}
364 % \begin{syntax}
365 % \cs{weiqiminsize} \meta{宽度} \meta{高度}
366 % \end{syntax}
367 % 棋盘最小显示大小(以格子计),使用星号命令可使当前大小为默认值。
368 % \end{function}
369 %
370 %
371 % \begin{function}{\nonelocmode, \normallocmode, \sgflocmode}
372 % \begin{syntax}
373 % \cs{nonelocmode}
374 % \end{syntax}
375 % 将棋盘坐标显示方式设置为:不显示坐标、常规模式坐标和 $SGF$ 模式坐标之一。
376 % 其中,默认为常规模式,使用星号命令可使当前设置为默认值。
377 % \end{function}
378 %
379 % ~\\
380 % \begin{demo}
381 % \newweiqi
382 % \weiqiblack[1]{a2,b2,c3,-,dr}
383 % \weiqilabel[A]{dq}
384 % \weiqirotate[180]
385 % \weiqiscale[0.8]
386 % \weiqiminsize{6}{5}
387 % \sgflocmode
388 % \showweiqi
389 % \end{demo}
390 %
391 %
392 % \subsection{棋局复用}^^A
393 %
394 % \begin{function}{\saveweiqi, \useweiqi}
395 % \begin{syntax}
396 % \cs{saveweiqi} [\meta{序号}]
397 % \end{syntax}
398 % 保存/使用对局(只保留对局信息,棋盘方位等信息不保存)。
399 % \meta{序号} 是保存的位置序号(自然数,推荐 $0$\~{}$26$)。
400 % 星号版使用对局会删除所有棋子标签及标签。
401 % \end{function}
402 %
403 %
404 % \begin{function}{\weiqichange}
405 % \begin{syntax}
406 % \cs{weiqichange} \Arg{坐标}
407 % \end{syntax}
408 % 切换指定位置的棋子的所属方(黑白方)。
409 % \meta{坐标} 是一组表示棋子位置的逗号分隔列表,每一项表示一个位置。
410 % \end{function}
411 %
412 %
413 % \begin{demo}
414 % \newweiqi
415 % \weiqiblack[1]{a2,b2,c3,-,dr}
416 % \weiqilabel[A]{dq}
417 % \saveweiqi[1]
418 % \newweiqi
419 % \useweiqi*[1]
420 % \weiqichange{dr}
421 % \showweiqi
422 % \end{demo}
423 %
424 %
425 % \begin{function}{\weiqiremove}
426 % \begin{syntax}
427 % \cs{weiqiremove} \Arg{坐标}
428 % \end{syntax}
429 % 移除指定位置的所有棋子,移除后相当于没有这一手棋。
430 % \meta{坐标} 是一组表示棋子位置的逗号分隔列表,每一项表示一个位置。
431 % \begin{texnote}
432 % 这与 \cs{weiqidie} 有本质的区别:\cs{weiqidie} 旨在标记死子(这手棋是真实存在的);
433 % 而本命令是直接移除这手棋,主要是以复用棋局而设置。
434 % \end{texnote}
435 % \end{function}
436 %
437 %
438 % \begin{demo}
439 % \newweiqi
440 % \weiqiblack[0]{bq,dq,-}
441 % \weiqiwhite[1]{b2,c2,c3,a2,d2,b1}
442 % \weiqidie{b2}
443 % \weiqiremove{d2}
444 % \weiqiwhite[5]{b4}
445 % \sgflocmode
446 % \showweiqi
447 % \end{demo}
448 %
449 %
450 % \begin{function}{\resetnumber}
451 % \begin{syntax}
452 % \cs{resetnumber} [\meta{起点}]
453 % \end{syntax}
454 % 重置围棋手数,\meta{起点} 所在位置的标签设置为 $1$,之后标签依次递增,之前无标签;默认以第 $1$ 手为起点。
455 % \end{function}
456 %
457 %
458 % \begin{demo}
459 % \useweiqi*[1]
460 % \resetnumber[2]
461 % \showweiqi
462 % \end{demo}
463 %
464 % \subsection{sgf 棋谱支持}^^A
465 %
466 %
467 % \begin{function}{\weiqisgf}
468 % \begin{syntax}
469 % \cs{weiqisgf} [\meta{标签}] \Arg{文本}
470 % \end{syntax}
471 % 使用 |sgf| 棋谱 \Arg{文本} 来指定棋子。如果 \meta{标签} 为手数,则会自动递增。
472 % \end{function}
473 %
474 % ~\\
475 % \begin{demo}
476 % \newweiqi
477 % \weiqisgf{;B[cc];W[dd]}
478 % \weiqisgf[1]{;B[cd];W[dc];B[cb]}
479 % \showweiqi
480 % \end{demo}
481 %
482 % \begin{function}{\inputsgf}
483 % \begin{syntax}
484 % \cs{weiqisgf} [\meta{起点}] \Arg{文件}
485 % \end{syntax}
486 % 新建对局并输入指定棋谱。\meta{起点} 所在位置的标签设置为 $1$,之后标签依次递增,之前无标签;默认以第 $1$ 手为起点。
487 % \end{function}
488 %
489 %
490 % \subsection{调试支持}^^A
491 %
492 % \begin{function}{\weiqidata}
493 % \begin{syntax}
494 % \cs{weiqidata}
495 % \end{syntax}
496 % 格式化输出内部变量数据。带星号版本会额外输出边界变量信息。
497 % \end{function}
498 %
499 % \newweiqi
500 % \weiqiblack[0]{bq,dq,-}
501 % \weiqiwhite[1]{b2,c2,c3,a2,d2,b1}
502 % \weiqidie{b2}
503 % \weiqiremove{d2}
504 % \weiqiwhite[5]{b4}
505 % \weiqidata*
506 %
507 % \subsection{下一步计划}^^A
508 %
509 % 中文标签的支持。
510 %
511 % \end{documentation}
512 %
513 % \begin{implementation}
514 %
515 % \newpage
516 %
517 % \section{\pkg{weiqi}实现}
518 %
519 % \subsection{初始化信息}
520 %
521 % \begin{macrocode}
522 %<*package>
523 %<@@=weiqi>
524 % \end{macrocode}
525 %
526 % 宏包基本信息:
527 % \begin{macrocode}
528 \NeedsTeXFormat{LaTeX2e}
529 \ProvidesExplPackage{weiqi}{2024-02-22}{0.1}
530 {drawing weiqi using expl3}
531 % \end{macrocode}
532 %
533 % 需要 l3draw 宏包,以支持绘图:
534 % \begin{macrocode}
535 \RequirePackage{l3draw}[2024-01-04]
536 % \end{macrocode}
537 %
538 % 开启 expl3 模式:
539 % \begin{macrocode}
540 \ExplSyntaxOn
541 % \end{macrocode}
542 %
543 %
544 % \subsection{声明系统函数的变体}
545 %
546 % \begin{macrocode}
547 \cs_generate_variant:Nn \int_set:Nn { Ne }
548 \cs_generate_variant:Nn \int_gset:Nn { Ne }
549 \cs_generate_variant:Nn \int_from_alph:n { e }
550 \cs_generate_variant:Nn \seq_gset_item:Nnn { NnV }
551 \cs_generate_variant:Nn \regex_extract_once:nnN { nVN }
552 \prg_generate_conditional_variant:Nnn \regex_match:nn { nV } { T, F, TF }
553 \prg_generate_conditional_variant:Nnn \regex_extract_once:nnN { nVN } { T, F, TF }
554 % \end{macrocode}
555 %
556 % \subsection{声明选项}
557 %
558 % \begin{macrocode}
559 % 待实现
560 % \end{macrocode}
561 %
562 %
563 % \subsection{定义常量}
564 %
565 % \begin{variable}{\c_@@_normal_size_int, \c_@@_mid_size_int, \c_@@_small_size_int, \c_@@_normal_star_clist,
566 % \c_@@_mid_star_clist, \c_@@_small_star_clist }
567 % 棋盘尺寸及对应星位坐标:
568 % \begin{macrocode}
569 \int_const:Nn \c_@@_normal_size_int { 19 }
570 \int_const:Nn \c_@@_mid_size_int { 13 }
571 \int_const:Nn \c_@@_small_size_int { 9 }
572 \clist_const:Nn \c_@@_normal_star_clist
573 { d4, j4, p4, d10, j10, p10, d16, j16, p16 }
574 \clist_const:Nn \c_@@_mid_star_clist
575 { c3, g3, k3, c7, g7, k7, c11, g11, k11 }
576 \clist_const:Nn \c_@@_small_star_clist { c3, k3, c7, k7 }
577 % \end{macrocode}
578 % \end{variable}
579 %
580 %
581 % \begin{variable}{\c_@@_max_step_int, \c_@@_normal_mode_str, \c_@@_sgf_mode_str }
582 % 支持的最大步数及坐标显示模式:
583 % \begin{macrocode}
584 \int_const:Nn \c_@@_max_step_int { 500 }
585 \str_const:Nn \c_@@_normal_mode_str { normal }
586 \str_const:Nn \c_@@_sgf_mode_str { sgf }
587 % \end{macrocode}
588 % \end{variable}
589 %
590 %
591 % \subsection{定义变量}
592 %
593 % \subsubsection{棋盘信息}
594 %
595 % 棋盘信息包含方位($x/y$方向及是否互换三者决定)、比例、最小显示大小(长与宽)及坐标控制(是否显示及坐标模式)。
596 % 共有 $8$ 个变量控制,且均具有全局及本地之分。全局变量为默认值,本地为当前对局的设置。
597 %
598 % \begin{variable}{\g_@@_x_direction_int, \g_@@_y_direction_int, \g_@@_swap_xy_bool,
599 % \g_@@_scale_fp, \g_@@_min_width_int, \g_@@_min_hight_int, \g_@@_show_loc_bool,
600 % \g_@@_loc_mode_str}
601 % 全局棋盘信息:
602 % \begin{macrocode}
603 \int_new:N \g_@@_x_direction_int
604 \int_new:N \g_@@_y_direction_int
605 \bool_new:N \g_@@_swap_xy_bool
606 \fp_new:N \g_@@_scale_fp
607 \int_new:N \g_@@_min_width_int
608 \int_new:N \g_@@_min_hight_int
609 \bool_new:N \g_@@_show_loc_bool
610 \str_new:N \g_@@_loc_mode_str
611 % \end{macrocode}
612 % \begin{macrocode}
613 \int_gset:Nn \g_@@_x_direction_int { 1 }
614 \int_gset:Nn \g_@@_y_direction_int { 1 }
615 \bool_gset_false:N \g_@@_swap_xy_bool
616 \fp_gset:Nn \g_@@_scale_fp { 1 }
617 \int_gset:Nn \g_@@_min_width_int { 3 }
618 \int_gset:Nn \g_@@_min_hight_int { 2 }
619 \bool_gset_true:N \g_@@_show_loc_bool
620 \str_gset_eq:NN \g_@@_loc_mode_str \c_@@_normal_mode_str
621 % \end{macrocode}
622 % \end{variable}
623 %
624 % \begin{variable}{\l_@@_x_direction_int, \l_@@_y_direction_int, \l_@@_swap_xy_bool,
625 % \l_@@_scale_fp, \l_@@_min_width_int, \l_@@_min_hight_int, \l_@@_show_loc_bool,
626 % \l_@@_loc_mode_str}
627 % 本地棋盘信息:
628 % \begin{macrocode}
629 \int_new:N \l_@@_x_direction_int
630 \int_new:N \l_@@_y_direction_int
631 \bool_new:N \l_@@_swap_xy_bool
632 \fp_new:N \l_@@_scale_fp
633 \int_new:N \l_@@_min_width_int
634 \int_new:N \l_@@_min_hight_int
635 \bool_new:N \l_@@_show_loc_bool
636 \str_new:N \l_@@_loc_mode_str
637 % \end{macrocode}
638 % \end{variable}
639 %
640 %
641 % \subsubsection{对局信息}
642 %
643 % 对局信息包括棋盘大小、步数、棋子/标签的信息集($x/y$ 坐标,棋手,标签)、死子集(索引)及指示点集(三色)组成。
644 % 共 $10$ 个变量,另加一个默认棋盘大小。本小节的变量的取值均为原始方位的取值。
645 %
646 % \begin{variable}{\g_@@_default_size_int}
647 % 默认对局大小:
648 % \begin{macrocode}
649 \int_new:N \g_@@_default_size_int
650 \int_gset_eq:NN \g_@@_default_size_int \c_@@_normal_size_int
651 % \end{macrocode}
652 % \end{variable}
653 %
654 % \begin{variable}{\g_@@_size_int, \g_@@_step_count_int, \g_@@_x_intarray,
655 % \g_@@_y_intarray, \g_@@_player_intarray, \g_@@_label_seq, \g_@@_die_seq}
656 % 对局内容:
657 % \begin{macrocode}
658 \int_new:N \g_@@_size_int
659 \int_new:N \g_@@_step_count_int
660 \intarray_new:Nn \g_@@_x_intarray { \c_@@_max_step_int }
661 \intarray_new:Nn \g_@@_y_intarray { \c_@@_max_step_int }
662 \intarray_new:Nn \g_@@_player_intarray { \c_@@_max_step_int }
663 \seq_new:N \g_@@_label_seq
664 \seq_new:N \g_@@_die_seq
665 % \end{macrocode}
666 % \end{variable}
667 %
668 %
669 % \begin{variable}{\g_@@_red_point_clist, \g_@@_green_point_clist,\g_@@_blue_point_clist}
670 % 对局辅助指示点:
671 % \begin{macrocode}
672 \clist_new:N \g_@@_red_point_clist
673 \clist_new:N \g_@@_green_point_clist
674 \clist_new:N \g_@@_blue_point_clist
675 % \end{macrocode}
676 % \end{variable}
677 %
678 %
679 % \subsubsection{边界信息}
680 %
681 % 本小节的变量为绘图过程中使用的边界信息变量。其是坐标是考虑方位信息的,但左右、上下及大小不考虑。
682 %
683 % 棋子区间(不考虑延伸的信息):
684 % \begin{macrocode}
685 \int_new:N \l_@@_x_min_int
686 \int_new:N \l_@@_x_max_int
687 \int_new:N \l_@@_y_min_int
688 \int_new:N \l_@@_y_max_int
689 % \end{macrocode}
690 %
691 % 棋盘边界(考虑延伸的信息):
692 % \begin{macrocode}
693 \bool_new:N \l_@@_left_bool
694 \bool_new:N \l_@@_right_bool
695 \bool_new:N \l_@@_up_bool
696 \bool_new:N \l_@@_down_bool
697 \fp_new:N \l_@@_x_min_fp
698 \fp_new:N \l_@@_x_max_fp
699 \fp_new:N \l_@@_y_min_fp
700 \fp_new:N \l_@@_y_max_fp
701 % \end{macrocode}
702 %
703 % \subsubsection{其它变量}
704 %
705 % 通用信息变量:
706 % \begin{macrocode}
707 \str_new:N \l_@@_label_str
708 \int_new:N \l_@@_x_int
709 \int_new:N \l_@@_y_int
710 \int_new:N \l_@@_player_int
711 \fp_new:N \l_@@_x_fp
712 \fp_new:N \l_@@_y_fp
713 \clist_new:N \l_@@_point_clist
714 % \end{macrocode}
715 %
716 % 其它临时变量:
717 % \begin{macrocode}
718 \int_new:N \l_@@_tmp_int
719 \str_new:N \l_@@_tmp_str
720 \bool_new:N \l_@@_tmp_bool
721 \seq_new:N \l_@@_tmp_seq
722 % \end{macrocode}
723 %
724 %
725 % \subsection{设置棋局的函数}
726 %
727 % \subsubsection{对局准备}
728 %
729 % 指定围棋大小、初始化对局的其余 $9$ 个变量(清空对局所有对局信息)及棋盘信息的 $8$ 个变量(使用默认值[全局变量])。
730 %
731 % \begin{macro}{\@@_new_game:n}
732 % 初始化对局信息(|#1| 棋盘大小)。
733 % \begin{macrocode}
734 \cs_new:Npn \@@_new_game:n #1
735 {
736 \int_set_eq:NN \l_@@_x_direction_int \g_@@_x_direction_int
737 \int_set_eq:NN \l_@@_y_direction_int \g_@@_y_direction_int
738 \bool_set_eq:NN \l_@@_swap_xy_bool \g_@@_swap_xy_bool
739 \fp_set_eq:NN \l_@@_scale_fp \g_@@_scale_fp
740 \int_set_eq:NN \l_@@_min_width_int \g_@@_min_width_int
741 \int_set_eq:NN \l_@@_min_hight_int \g_@@_min_hight_int
742 \bool_set_eq:NN \l_@@_show_loc_bool \g_@@_show_loc_bool
743 \str_set_eq:NN \l_@@_loc_mode_str \g_@@_loc_mode_str
744 % \end{macrocode}
745 % \begin{macrocode}
746 \int_gset:Ne \g_@@_size_int { #1 }
747 \int_gset:Nn \g_@@_step_count_int { 0 }
748 \intarray_gzero:N \g_@@_x_intarray
749 \intarray_gzero:N \g_@@_y_intarray
750 \intarray_gzero:N \g_@@_player_intarray
751 \seq_gclear:N \g_@@_label_seq
752 \seq_gclear:N \g_@@_die_seq
753 % \end{macrocode}
754 % \begin{macrocode}
755 \clist_gclear:N \g_@@_red_point_clist
756 \clist_gclear:N \g_@@_green_point_clist
757 \clist_gclear:N \g_@@_blue_point_clist
758 }
759 % \end{macrocode}
760 % \end{macro}
761 %
762 %
763 % \subsubsection{坐标转换函数}
764 %
765 % 实现棋子坐标的坐标对形式与字符串形式(虚着使用 |-| )两者之间的转换。
766 %
767 % \begin{macro}{\@@_loc_to_xy:n, \@@_loc_to_xy:V}
768 % 设置 $x$、$y$ 坐标变量(|#1| 坐标,支持两种模式)。
769 % \begin{macrocode}
770 \cs_new:Npn \@@_loc_to_xy:n #1
771 {
772 \str_set:Nx \l_tmpa_str { \str_lowercase:n { #1 } }
773 \bool_lazy_any:nTF
774 {
775 { \str_if_empty_p:N \l_tmpa_str }
776 { \str_if_eq_p:Vn { \l_tmpa_str } { - } }
777 { \str_if_eq_p:Vn { \l_tmpa_str } { pass } }
778 }
779 {
780 \int_set:Nn \l_@@_x_int { 0 }
781 \int_set:Nn \l_@@_y_int { 0 }
782 }
783 {
784 \int_set:Ne \l_@@_x_int
785 { \int_from_alph:e { \str_head:N \l_tmpa_str } }
786 \regex_match:nVTF { [a-z]{2} } { \l_tmpa_str }
787 {
788 \int_set:Ne \l_tmpa_int
789 { \int_from_alph:e { \str_tail:N \l_tmpa_str } }
790 \int_set:Nn \l_@@_y_int { \g_@@_size_int - \l_tmpa_int + 1 }
791 }
792 {
793 \int_set:Ne \l_@@_y_int
794 { \str_range:Nnn \l_tmpa_str { 2 } { 5 } }
795 }
796 }
797 }
798 % \end{macrocode}
799 % \begin{macrocode}
800 \cs_generate_variant:Nn \@@_loc_to_xy:n { V }
801 % \end{macrocode}
802 % \end{macro}
803 %
804 %
805 % \begin{macro}{\@@_xy_to_loc:N}
806 % 将指定变量设置为当前坐标的字符串形式(|#1| 指定的存储变量)。
807 % \begin{macrocode}
808 \cs_new:Npn \@@_xy_to_loc:N #1
809 {
810 \int_compare:nNnTF { \l_@@_x_int } = { 0 }
811 { \str_set:Nn #1 { - } }
812 {
813 \str_set:Nx \l_tmpa_str
814 { \int_to_alph:n { \l_@@_x_int } }
815 \str_compare:eNeTF
816 { \l_@@_loc_mode_str } = { \c_@@_sgf_mode_str }
817 {
818 \int_set:Nn \l_tmpa_int
819 { \g_@@_size_int - \l_@@_y_int + 1 }
820 \str_set:Nx \l_tmpb_str
821 { \int_to_alph:n { \l_tmpa_int } }
822 \str_put_right:NV \l_tmpa_str { \l_tmpb_str }
823 }
824 { \str_put_right:NV \l_tmpa_str { \l_@@_y_int } }
825 \str_set_eq:NN #1 \l_tmpa_str
826 }
827 }
828 % \end{macrocode}
829 % \end{macro}
830 %
831 %
832 % \subsubsection{添加棋子或纯标签}
833 %
834 % 向对局中添加棋子或纯标签,它们使用相同的结构存储。除了所属方不一样外,它们内部添加方式完全相同。
835 % 其中,所属方用 $0$ 表示未使用\footnote{新局开始,所属方均初始化为 $0$;移除状态的棋子,也会设置为零(同时坐标也为零)。},
836 % $1$ 表示黑方,$2$ 表示白方,$3$ 表示纯标签。
837 %
838 % 棋子可以含标签(如手数或特殊字符等),棋子|+| 纯标签不等于带标签的棋子。
839 % 因为前者是两条记录,后者是一条记录,后续处理也不一样。
840 %
841 % \begin{macro}{\@@_add_stone:nnn, \@@_add_stone:nnV, \@@_add_stone:nVV}
842 % 向对局中添加一步棋(|#1| 黑白方 ;|#2| 坐标;|#3| 标签)。
843 % \begin{macrocode}
844 \cs_new:Npn \@@_add_stone:nnn #1#2#3
845 {
846 \int_gincr:N \g_@@_step_count_int
847 \intarray_gset:Nnn \g_@@_player_intarray
848 \g_@@_step_count_int { #1 }
849 % \end{macrocode}
850 % \begin{macrocode}
851 \@@_loc_to_xy:n { #2 }
852 \intarray_gset:Nnn \g_@@_x_intarray
853 \g_@@_step_count_int \l_@@_x_int
854 \intarray_gset:Nnn \g_@@_y_intarray
855 \g_@@_step_count_int \l_@@_y_int
856 % \end{macrocode}
857 % \begin{macrocode}
858 \str_if_eq:nnTF { #3 } { 0 }
859 { \seq_put_right:Nn \g_@@_label_seq {} }
860 { \seq_put_right:Nn \g_@@_label_seq { #3 } }
861 }
862 % \end{macrocode}
863 % \begin{macrocode}
864 \cs_generate_variant:Nn \@@_add_stone:nnn {nnV, nVV}
865 % \end{macrocode}
866 % \end{macro}
867 %
868 %
869 % \begin{macro}{\@@_add_stones:nnn}
870 % 批量向对局中添加棋子(|#1| 黑白方 ;|#2| 坐标序列;|#3| 标签)。
871 % \begin{macrocode}
872 \cs_new:Npn \@@_add_stones:nnn #1#2#3
873 {
874 \int_set:Nn \l_@@_player_int { #1 }
875 \clist_set:Nn \l_@@_position_clsit { #2 }
876 \bool_set_false:N \l_@@_tmp_bool
877 \str_if_empty:nTF { #3 }
878 { \str_set:Nn \l_@@_tmp_str {} }
879 {
880 \regex_match:nnTF { [^0-9]+ } { #3 }
881 { \str_set:Nx \l_@@_tmp_str { #3 } }
882 {
883 \bool_set_true:N \l_@@_tmp_bool
884 \int_set:Nn \l_@@_tmp_int { #3 }
885 }
886 }
887 \clist_map_inline:Nn \l_@@_position_clsit
888 {
889 \bool_if:nTF \l_@@_tmp_bool
890 {
891 \@@_add_stone:nnV
892 { \l_@@_player_int }
893 { ##1 }
894 { \l_@@_tmp_int }
895 \int_case:nn { \l_@@_player_int }
896 {
897 { 1 } { \int_set:Nn \l_@@_player_int { 2 } }
898 { 2 } { \int_set:Nn \l_@@_player_int { 1 } }
899 { 3 } { \int_set:Nn \l_@@_player_int { 3 } }
900 }
901 \int_compare:nNnT { \l_@@_tmp_int } > { 0 }
902 { \int_incr:N \l_@@_tmp_int }
903 }
904 { \@@_add_stone:nnV { #1 } { ##1 } { \l_@@_tmp_str } }
905 }
906 }
907 % \end{macrocode}
908 % \end{macro}
909 %
910 %
911 % \begin{macro}{\@@_add_sgf_stones:nn, \@@_add_sgf_stones:VV}
912 % 批量向对局中添加 sgf 格式棋子(|#1| 带黑白方的坐标序列;|#2| 标签)。
913 % \begin{macrocode}
914 \cs_new:Npn \@@_add_sgf_stones:nn #1#2
915 {
916 \regex_extract_all:nnN { ;[BW]\[[a-z]{2}\] } { #1 } \l_@@_tmp_seq
917 \clist_set_from_seq:NN \l_@@_point_clist \l_@@_tmp_seq
918 \bool_set_false:N \l_@@_tmp_bool
919 \str_if_empty:nTF { #2 }
920 { \str_set:Nn \l_@@_tmp_str {} }
921 {
922 \regex_match:nnTF { [^0-9]+ } { #2 }
923 { \str_set:Nx \l_@@_tmp_str { #2 } }
924 {
925 \bool_set_true:N \l_@@_tmp_bool
926 \int_set:Nn \l_@@_tmp_int { #2 }
927 }
928 }
929 \clist_map_inline:Nn \l_@@_point_clist
930 {
931 \str_set:Nx \l_tmpa_str { \str_item:Nn { ##1 } { 2 } }
932 \str_set:Nx \l_tmpb_str { \str_range:nnn { ##1 } { 4 } { -2 } }
933 \str_case_e:nn { \l_tmpa_str }
934 {
935 { B } { \int_set:Nn \l_@@_player_int { 1 } }
936 { W } { \int_set:Nn \l_@@_player_int { 2 } }
937 }
938 \bool_if:nTF \l_@@_tmp_bool
939 {
940 \@@_add_stone:nVV { \l_@@_player_int }
941 { \l_tmpb_str } { \l_@@_tmp_int }
942 \int_compare:nNnT { \l_@@_tmp_int } > { 0 }
943 { \int_incr:N \l_@@_tmp_int }
944 }
945 {
946 \@@_add_stone:nVV { \l_@@_player_int }
947 { \l_tmpb_str } { \l_@@_tmp_str }
948 }
949 }
950 }
951 % \end{macrocode}
952 % \begin{macrocode}
953 \cs_generate_variant:Nn \@@_add_sgf_stones:nn { VV }
954 % \end{macrocode}
955 % \end{macro}
956 %
957 % \subsubsection{修改对局}
958 %
959 % 修改对局中的棋子信息(所有方、标签等)、移除棋子 或设置死子等。
960 % 其中,移除棋子相当于没有输入这个棋子\footnote{
961 % 移除棋子是通过把该手棋全部设置为零来实现;这与虚着不一样,后者仍有所属方。};
962 % 而设置死子则用于棋子被吃的情况\footnote{
963 % 设置死子是通过将棋加入死子列表中来实现,其坐标信息全部不变。}。
964 %
965 % \begin{macro}{\@@_reset_stone_number:n}
966 % 重置所有棋子的标签,移除所有棋子标签(不含纯标签)并按手数(以 |#1| 起为第 $1$ 手)设置新标签。
967 % \begin{macrocode}
968 \cs_new:Npn \@@_reset_stone_number:n #1
969 {
970 \int_set:Ne \l_@@_tmp_int { 1 - #1 }
971 \int_step_inline:nn { \c_@@_max_step_int }
972 {
973 \bool_lazy_or:nnF
974 {
975 \int_compare_p:nNn
976 { \intarray_item:Nn \g_@@_player_intarray { ##1 } } = { 0 }
977 }
978 {
979 \int_compare_p:nNn
980 { \intarray_item:Nn \g_@@_player_intarray { ##1 } } = { 3 }
981 }
982 {
983 \int_incr:N \l_@@_tmp_int
984 \int_compare:nNnTF { \l_@@_tmp_int } > { 0 }
985 { \seq_gset_item:NnV \g_@@_label_seq { ##1 } { \l_@@_tmp_int } }
986 { \seq_gset_item:Nnn \g_@@_label_seq { ##1 } {} }
987 }
988 }
989 }
990 % \end{macrocode}
991 % \end{macro}
992 %
993 %
994 % \begin{macro}{\@@_change_stone:n}
995 % 切换指定索引的棋子的黑白方(|#1| 索引)。
996 % \begin{macrocode}
997 \cs_new:Npn \@@_change_stone:n #1
998 {
999 \int_case:nn
1000 { \intarray_item:Nn \g_@@_player_intarray { #1 } }
1001 {
1002 { 1 } { \intarray_gset:Nnn \g_@@_player_intarray { #1 } { 2 } }
1003 { 2 } { \intarray_gset:Nnn \g_@@_player_intarray { #1 } { 1 } }
1004 }
1005 }
1006 % \end{macrocode}
1007 % \end{macro}
1008 %
1009 %
1010 % \begin{macro}{\@@_remove_stone:n}
1011 % 删除指定索引的棋子(|#1| 索引)。
1012 % \begin{macrocode}
1013 \cs_new:Npn \@@_remove_stone:n #1
1014 {
1015 \intarray_gset:Nnn \g_@@_x_intarray { #1 } { 0 }
1016 \intarray_gset:Nnn \g_@@_y_intarray { #1 } { 0 }
1017 \intarray_gset:Nnn \g_@@_player_intarray { #1 } { 0 }
1018 \seq_gset_item:Nnn \g_@@_label_seq { #1} { }
1019 }
1020 % \end{macrocode}
1021 % \end{macro}
1022 %
1023 %
1024 % \begin{macro}{\@@_die_stone:n}
1025 % 设置指定索引的棋子为死子(|#1| 索引)。
1026 % \begin{macrocode}
1027 \cs_new:Npn \@@_die_stone:n #1
1028 {
1029 \seq_if_in:NnF \g_@@_die_seq { #1 }
1030 {
1031 \seq_put_right:Nn \g_@@_die_seq { #1 }
1032 \prg_break:
1033 }
1034 }
1035 % \end{macrocode}
1036 % \end{macro}
1037 %
1038 %
1039 % \begin{macro}{\@@_modify_stone:N}
1040 % 使用指定函数(|#1|)修改指定位置的棋子(由 $x$, $y$ 坐标指定)。
1041 % \begin{macrocode}
1042 \cs_new:Npn \@@_modify_stone:N #1
1043 {
1044 \int_step_inline:nn { \c_@@_max_step_int }
1045 {
1046 \bool_lazy_and:nnT
1047 {
1048 \int_compare_p:n
1049 { \intarray_item:Nn \g_@@_x_intarray { ##1 } = \l_@@_x_int }
1050 }
1051 {
1052 \int_compare_p:n
1053 { \intarray_item:Nn \g_@@_y_intarray { ##1 } = \l_@@_y_int }
1054 }
1055 { #1 { ##1 } }
1056 }
1057 \prg_break_point:
1058 }
1059 % \end{macrocode}
1060 % \end{macro}
1061 %
1062 %
1063 % \begin{macro}{\@@_modify_stones:nN}
1064 % 批量修改当前对局中的棋子(|#1| 坐标序列,|#2| 修改函数)。
1065 % \begin{macrocode}
1066 \cs_new:Npn \@@_modify_stones:nN #1#2
1067 {
1068 \clist_set:Nn \l_@@_position_clsit { #1 }
1069 \clist_map_inline:Nn \l_@@_position_clsit
1070 {
1071 \@@_loc_to_xy:n { ##1 }
1072 \int_compare:nNnF { \l_@@_x_int } = { 0 }
1073 { \@@_modify_stone:N { #2 } }
1074 }
1075 }
1076 % \end{macrocode}
1077 % \end{macro}
1078 %
1079 %
1080 % \begin{macro}{\@@_clear_labels:}
1081 % 清除所有纯标签。
1082 % \begin{macrocode}
1083 \cs_new:Nn \@@_clear_labels:
1084 {
1085 \int_step_inline:nn { \c_@@_max_step_int }
1086 {
1087 \int_compare:nNnT
1088 { \intarray_item:Nn \g_@@_player_intarray { ##1 } } = { 3 }
1089 {
1090 \intarray_gset:Nnn \g_@@_x_intarray { ##1 } { 0 }
1091 \intarray_gset:Nnn \g_@@_y_intarray { ##1 } { 0 }
1092 \intarray_gset:Nnn \g_@@_player_intarray { ##1 } { 0 }
1093 \seq_gset_item:Nnn \g_@@_label_seq { ##1 } {}
1094 }
1095 }
1096 }
1097 % \end{macrocode}
1098 % \end{macro}
1099 %
1100 %
1101 % \subsubsection{指示点}
1102 %
1103 % 指示点是棋盘上的特殊圆点,它支持红绿蓝三种颜色。旨在用于在某个特定情况下的特殊指示。
1104 % 指示点的实现原理与纯标签完全不一样,侧重点也不一样。
1105 %
1106 % \begin{macro}{\@@_add_points:nn}
1107 % 批量向对局中添加指示点(|#1| 颜色 ;|#2| 坐标序列)。
1108 % \begin{macrocode}
1109 \cs_new:Npn \@@_add_points:nn #1#2
1110 {
1111 \str_case:nn { #1 }
1112 {
1113 { red }
1114 { \clist_gput_right:Nn \g_@@_red_point_clist { #2 } }
1115 { green }
1116 { \clist_gput_right:Nn \g_@@_green_point_clist { #2 } }
1117 { blue }
1118 { \clist_gput_right:Nn \g_@@_blue_point_clist { #2 } }
1119 }
1120 }
1121 % \end{macrocode}
1122 % \end{macro}
1123 %
1124 %
1125 % \begin{macro}{\@@_clear_points:}
1126 % 清除所有指示点。
1127 % \begin{macrocode}
1128 \cs_new:Nn \@@_clear_points:
1129 {
1130 \clist_clear:N \g_@@_red_point_clist
1131 \clist_clear:N \g_@@_green_point_clist
1132 \clist_clear:N \g_@@_blue_point_clist
1133 }
1134 % \end{macrocode}
1135 % \end{macro}
1136 %
1137 %
1138 % \subsection{绘制棋局的函数}
1139 %
1140 % \subsubsection{坐标变换}
1141 %
1142 % 由于对局中的坐标以原始方位输入与保存,而显示时需要按指定的方位来显示,
1143 % 因此在显示(绘图)前需要根据棋盘方位信息来进行坐标变换。
1144 %
1145 % \begin{macro}{\@@_transform_xy:NN}
1146 % 转换坐标(|#1|、|#2| 分别为 $x,y$ 坐标)。
1147 % \begin{macrocode}
1148 \cs_new:Npn \@@_transform_xy:NN #1#2
1149 {
1150 \int_set:Ne \l_tmpa_int { #1 * \l_@@_x_direction_int }
1151 \int_set:Ne \l_tmpb_int { #2 * \l_@@_y_direction_int }
1152 \bool_if:NTF \l_@@_swap_xy_bool
1153 {
1154 \int_set_eq:NN #1 \l_tmpb_int
1155 \int_set_eq:NN #2 \l_tmpa_int
1156 }
1157 {
1158 \int_set_eq:NN #1 \l_tmpa_int
1159 \int_set_eq:NN #2 \l_tmpb_int
1160 }
1161 }
1162 % \end{macrocode}
1163 % \end{macro}
1164 %
1165 %
1166 % \subsubsection{边界函数}
1167 %
1168 % 绘制棋局时,需要确认要显示的区域(显示整个棋盘通常不是最优方案),
1169 % 本小节提供一系列函数,用于确认显示边界。
1170 %
1171 % \begin{macro}{\@@_calc_range:}
1172 % 计算棋子所在区间边界。
1173 % \begin{macrocode}
1174 \cs_new:Nn \@@_calc_range:
1175 {
1176 \int_set:Nn \l_@@_x_min_int { 99 }
1177 \int_set:Nn \l_@@_y_min_int { 99 }
1178 \int_set:Nn \l_@@_x_max_int { 0 }
1179 \int_set:Nn \l_@@_y_max_int { 0 }
1180 % \end{macrocode}
1181 % 遍历生成自然边界:
1182 % \begin{macrocode}
1183 \int_step_inline:nn {\g_@@_step_count_int}
1184 {
1185 \int_set:Ne \l_@@_x_int
1186 { \intarray_item:Nn \g_@@_x_intarray { ##1 } }
1187 \int_set:Ne \l_@@_y_int
1188 { \intarray_item:Nn \g_@@_y_intarray { ##1 } }
1189 \int_compare:nNnF
1190 { \l_@@_x_int } = { 0 }
1191 {
1192 \int_compare:nNnT
1193 \l_@@_x_min_int > \l_@@_x_int
1194 { \int_set_eq:NN \l_@@_x_min_int \l_@@_x_int }
1195 \int_compare:nNnT
1196 \l_@@_x_max_int < \l_@@_x_int
1197 { \int_set_eq:NN \l_@@_x_max_int \l_@@_x_int }
1198 \int_compare:nNnT
1199 \l_@@_y_min_int > \l_@@_y_int
1200 { \int_set_eq:NN \l_@@_y_min_int \l_@@_y_int }
1201 \int_compare:nNnT
1202 \l_@@_y_max_int < \l_@@_y_int
1203 { \int_set_eq:NN \l_@@_y_max_int \l_@@_y_int }
1204 }
1205 }
1206 % \end{macrocode}
1207 % 无有效棋子的情况下,显示整个棋盘:
1208 % \begin{macrocode}
1209 \int_compare:nNnT
1210 { \l_@@_x_min_int } = { 99 }
1211 {
1212 \int_set:Nn \l_@@_x_min_int { 1 }
1213 \int_set:Nn \l_@@_y_min_int { 1 }
1214 \int_set_eq:NN \l_@@_x_max_int \g_@@_size_int
1215 \int_set_eq:NN \l_@@_y_max_int \g_@@_size_int
1216 }
1217 % \end{macrocode}
1218 % 向外延伸,以保证至少有一个角:
1219 % \begin{macrocode}
1220 \int_set:Ne \l_tmpa_int
1221 { \int_min:nn { \g_@@_size_int } { \l_@@_min_width_int } }
1222 \int_compare:nNnTF
1223 { \g_@@_size_int - \l_@@_x_max_int } > { \l_@@_x_min_int - 1 }
1224 {
1225 \int_set:Nn \l_@@_x_min_int { 1 }
1226 \int_set:Ne \l_@@_x_max_int
1227 { \int_max:nn { \l_@@_x_max_int + 1 } { \l_tmpa_int } }
1228 }
1229 {
1230 \int_set_eq:NN \l_@@_x_max_int \g_@@_size_int
1231 \int_compare:nNnF
1232 { \l_@@_x_min_int } = { 1 }
1233 {
1234 \int_set:Ne \l_@@_x_min_int
1235 {
1236 \int_min:nn
1237 { \l_@@_x_min_int - 1 }
1238 { \g_@@_size_int - \l_tmpa_int + 1 }
1239 }
1240 }
1241 }
1242 \int_set:Ne \l_tmpa_int
1243 { \int_min:nn { \g_@@_size_int } { \l_@@_min_hight_int } }
1244 \int_compare:nNnTF
1245 { \g_@@_size_int - \l_@@_y_max_int } > { \l_@@_y_min_int - 1 }
1246 {
1247 \int_set:Nn \l_@@_y_min_int { 1 }
1248 \int_set:Ne \l_@@_y_max_int
1249 { \int_max:nn { \l_@@_y_max_int + 1 } { \l_tmpa_int } }
1250 }
1251 {
1252 \int_set_eq:NN \l_@@_y_max_int \g_@@_size_int
1253 \int_compare:nNnF
1254 { \l_@@_y_min_int } = { 1 }
1255 {
1256 \int_set:Ne \l_@@_y_min_int
1257 {
1258 \int_min:nn
1259 { \l_@@_y_min_int - 1 }
1260 { \g_@@_size_int - \l_tmpa_int + 1 }
1261 }
1262 }
1263 }
1264 % \end{macrocode}
1265 % 变换坐标:
1266 % \begin{macrocode}
1267 \@@_transform_xy:NN \l_@@_x_min_int \l_@@_y_min_int
1268 \@@_transform_xy:NN \l_@@_x_max_int \l_@@_y_max_int
1269 }
1270 % \end{macrocode}
1271 % \end{macro}
1272 %
1273 %
1274 % \begin{macro}{\@@_set_range:n}
1275 % 指定棋子区间边界(边界外棋子不显示),支持 |full|。
1276 % \begin{macrocode}
1277 \cs_new:Npn \@@_set_range:n #1
1278 {
1279 \str_compare:eNeTF
1280 { \str_lowercase:n { #1 } } = { full }
1281 {
1282 \int_set:Nn \l_@@_x_min_int { 1 }
1283 \int_set:Nn \l_@@_y_min_int { 1 }
1284 \int_set_eq:NN \l_@@_x_max_int \g_@@_size_int
1285 \int_set_eq:NN \l_@@_y_max_int \g_@@_size_int
1286 }
1287 {
1288 \clist_set:Nn \l_@@_position_clsit { #1 }
1289 \clist_pop:NN \l_@@_position_clsit \l_tmpa_tl
1290 \@@_loc_to_xy:V { \l_tmpa_tl }
1291 \int_set_eq:NN \l_@@_x_min_int \l_@@_x_int
1292 \int_set_eq:NN \l_@@_y_min_int \l_@@_y_int
1293 \clist_pop:NN \l_@@_position_clsit \l_tmpa_tl
1294 \@@_loc_to_xy:V { \l_tmpa_tl }
1295 \int_set_eq:NN \l_@@_x_max_int \l_@@_x_int
1296 \int_set_eq:NN \l_@@_y_max_int \l_@@_y_int
1297 }
1298 % \end{macrocode}
1299 % 生成标准对角点,变换坐标:
1300 % \begin{macrocode}
1301 \int_compare:nNnT { \l_@@_x_min_int } > { \l_@@_x_max_int }
1302 {
1303 \int_set_eq:NN \l_tmpa_int \l_@@_x_min_int
1304 \int_set_eq:NN \l_@@_x_min_int \l_@@_x_max_int
1305 \int_set_eq:NN \l_@@_x_max_int \l_tmpa_int
1306 }
1307 \int_compare:nNnT { \l_@@_y_min_int } > { \l_@@_y_max_int }
1308 {
1309 \int_set_eq:NN \l_tmpa_int \l_@@_y_min_int
1310 \int_set_eq:NN \l_@@_y_min_int \l_@@_y_max_int
1311 \int_set_eq:NN \l_@@_y_max_int \l_tmpa_int
1312 }
1313 \@@_transform_xy:NN \l_@@_x_min_int \l_@@_y_min_int
1314 \@@_transform_xy:NN \l_@@_x_max_int \l_@@_y_max_int
1315 }
1316 % \end{macrocode}
1317 % \end{macro}
1318 %
1319 %
1320 % \begin{macro}{\@@_calc_board_border:}
1321 % 计算棋盘的显示边界。
1322 % \begin{macrocode}
1323 \cs_new:Nn \@@_calc_board_border:
1324 {
1325 \int_compare:nNnTF
1326 { \int_abs:n { \l_@@_x_min_int } } = { 1 }
1327 {
1328 \bool_set_true:N \l_@@_left_bool
1329 \fp_set:Nn \l_@@_x_min_fp
1330 { \l_@@_x_min_int }
1331 }
1332 {
1333 \bool_set_false:N \l_@@_left_bool
1334 \fp_set:Nn \l_@@_x_min_fp
1335 { \l_@@_x_min_int - 0.3 * \int_sign:n { \l_@@_x_min_int } }
1336 }
1337 \int_compare:nNnTF
1338 { \int_abs:n { \l_@@_x_max_int } } = { \g_@@_size_int }
1339 {
1340 \bool_set_true:N \l_@@_right_bool
1341 \fp_set:Nn \l_@@_x_max_fp
1342 { \l_@@_x_max_int }
1343 }
1344 {
1345 \bool_set_false:N \l_@@_right_bool
1346 \fp_set:Nn \l_@@_x_max_fp
1347 { \l_@@_x_max_int + 0.3 * \int_sign:n { \l_@@_x_max_int } }
1348 }
1349 \int_compare:nNnTF
1350 { \int_abs:n { \l_@@_y_min_int } } = { 1 }
1351 {
1352 \bool_set_true:N \l_@@_down_bool
1353 \fp_set:Nn \l_@@_y_min_fp
1354 { \l_@@_y_min_int }
1355 }
1356 {
1357 \bool_set_false:N \l_@@_down_bool
1358 \fp_set:Nn \l_@@_y_min_fp
1359 { \l_@@_y_min_int - 0.3 * \int_sign:n { \l_@@_y_min_int } }
1360 }
1361 \int_compare:nNnTF
1362 { \int_abs:n { \l_@@_y_max_int } } = { \g_@@_size_int }
1363 {
1364 \bool_set_true:N \l_@@_up_bool
1365 \fp_set:Nn \l_@@_y_max_fp
1366 { \l_@@_y_max_int }
1367 }
1368 {
1369 \bool_set_false:N \l_@@_up_bool
1370 \fp_set:Nn \l_@@_y_max_fp
1371 { \l_@@_y_max_int + 0.3 * \int_sign:n { \l_@@_y_max_int } }
1372 }
1373 }
1374 % \end{macrocode}
1375 % \end{macro}
1376 %
1377 %
1378 % \begin{macro}{\@@_within_range_p:nn, \@@_within_range:nnT}
1379 % 判定点是否在范围内(|#1| $x$坐标;|#2| $y$ 坐标)。
1380 % 坐标是变换后的坐标。
1381 % \begin{macrocode}
1382 \prg_set_conditional:Npnn \@@_within_range:nn #1#2 { p, T }
1383 {
1384 \fp_set:Nn \l_tmpa_fp { abs( \l_@@_x_min_fp - #1 ) }
1385 \fp_add:Nn \l_tmpa_fp { abs( \l_@@_x_max_fp - #1 ) }
1386 \fp_sub:Nn \l_tmpa_fp { abs( \l_@@_x_max_fp - \l_@@_x_min_fp ) }
1387 \fp_add:Nn \l_tmpa_fp { abs( \l_@@_y_min_fp - #2 ) }
1388 \fp_add:Nn \l_tmpa_fp { abs( \l_@@_y_max_fp - #2 ) }
1389 \fp_sub:Nn \l_tmpa_fp { abs( \l_@@_y_max_fp - \l_@@_y_min_fp ) }
1390 \fp_compare:nNnTF
1391 { \l_tmpa_fp } < { 0.1 }
1392 { \prg_return_true: }
1393 { \prg_return_false: }
1394 }
1395 % \end{macrocode}
1396 % \end{macro}
1397 %
1398 %
1399 % \subsubsection{绘制函数}
1400 %
1401 % 绘制对局包括绘制棋盘、棋子与纯标签、标记点及死子几个步骤。
1402 % 其中,棋盘包括网格线、边界线、角、星位及坐标标签。
1403 % 绘制前需要设置好棋子区间边界\footnote{棋盘边界在绘制棋盘时内部调用,因此不需要额外设置。}。
1404 %
1405 %
1406 % \begin{macro}{\@@_draw_board_grid:}
1407 % 绘制棋盘的网格线(路径)。
1408 % \begin{macrocode}
1409 \cs_new:Nn \@@_draw_board_grid:
1410 {
1411 \int_set:Ne \l_@@_tmp_int
1412 { \int_sign:n { \l_@@_x_max_int - \l_@@_x_min_int } }
1413 \int_step_inline:nnnn
1414 { \l_@@_x_min_int } { \l_@@_tmp_int } { \l_@@_x_max_int }
1415 {
1416 \draw_path_moveto:n { ##1 cm, \l_@@_y_min_fp cm }
1417 \draw_path_lineto:n { ##1 cm, \l_@@_y_max_fp cm }
1418 }
1419 \int_set:Ne \l_@@_tmp_int
1420 { \int_sign:n { \l_@@_y_max_int - \l_@@_y_min_int } }
1421 \int_step_inline:nnnn
1422 { \l_@@_y_min_int } { \l_@@_tmp_int } { \l_@@_y_max_int }
1423 {
1424 \draw_path_moveto:n { \l_@@_x_min_fp cm, ##1 cm }
1425 \draw_path_lineto:n { \l_@@_x_max_fp cm, ##1 cm }
1426 }
1427 }
1428 % \end{macrocode}
1429 % \end{macro}
1430 %
1431 %
1432 % \begin{macro}{\@@_draw_board_border:}
1433 % 绘制棋盘的边界线(路径)。
1434 % \begin{macrocode}
1435 \cs_new:Nn \@@_draw_board_border:
1436 {
1437 \bool_if:nT { \l_@@_left_bool }
1438 {
1439 \draw_path_moveto:n { \l_@@_x_min_fp cm, \l_@@_y_min_fp cm }
1440 \draw_path_lineto:n { \l_@@_x_min_fp cm, \l_@@_y_max_fp cm }
1441 }
1442 \bool_if:nT { \l_@@_right_bool }
1443 {
1444 \draw_path_moveto:n { \l_@@_x_max_fp cm, \l_@@_y_min_fp cm }
1445 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_max_fp cm }
1446 }
1447 \bool_if:nT { \l_@@_down_bool }
1448 {
1449 \draw_path_moveto:n { \l_@@_x_min_fp cm, \l_@@_y_min_fp cm }
1450 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_min_fp cm }
1451 }
1452 \bool_if:nT { \l_@@_up_bool }
1453 {
1454 \draw_path_moveto:n { \l_@@_x_min_fp cm, \l_@@_y_max_fp cm }
1455 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_max_fp cm }
1456 }
1457 }
1458 % \end{macrocode}
1459 % \end{macro}
1460 %
1461 %
1462 % \begin{macro}{\@@_draw_board_corner:}
1463 % 绘制棋盘的角(路径)。
1464 % \begin{macrocode}
1465 \cs_new:Nn \@@_draw_board_corner:
1466 {
1467 \bool_if:nT { \l_@@_left_bool && \l_@@_down_bool }
1468 {
1469 \draw_path_moveto:n { \l_@@_x_min_fp cm, \l_@@_y_max_fp cm }
1470 \draw_path_lineto:n { \l_@@_x_min_fp cm, \l_@@_y_min_fp cm }
1471 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_min_fp cm }
1472 }
1473 \bool_if:nT { \l_@@_right_bool && \l_@@_down_bool }
1474 {
1475 \draw_path_moveto:n { \l_@@_x_max_fp cm, \l_@@_y_max_fp cm }
1476 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_min_fp cm }
1477 \draw_path_lineto:n { \l_@@_x_min_fp cm, \l_@@_y_min_fp cm }
1478 }
1479 \bool_if:nT { \l_@@_right_bool && \l_@@_up_bool }
1480 {
1481 \draw_path_moveto:n { \l_@@_x_max_fp cm, \l_@@_y_min_fp cm }
1482 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_max_fp cm }
1483 \draw_path_lineto:n { \l_@@_x_min_fp cm, \l_@@_y_max_fp cm }
1484 }
1485 \bool_if:nT { \l_@@_left_bool && \l_@@_up_bool }
1486 {
1487 \draw_path_moveto:n { \l_@@_x_min_fp cm, \l_@@_y_min_fp cm }
1488 \draw_path_lineto:n { \l_@@_x_min_fp cm, \l_@@_y_max_fp cm }
1489 \draw_path_lineto:n { \l_@@_x_max_fp cm, \l_@@_y_max_fp cm }
1490 }
1491 }
1492 % \end{macrocode}
1493 % \end{macro}
1494 %
1495 % \begin{macro}{\@@_draw_point:n}
1496 % 绘制单个点(路径)(|#1| 坐标)。
1497 % \begin{macrocode}
1498 \cs_new:Npn \@@_draw_point:n #1
1499 {
1500 \__weiqi_loc_to_xy:n { #1 }
1501 \@@_transform_xy:NN \l_@@_x_int \l_@@_y_int
1502 \@@_within_range:nnT { \l_@@_x_int } { \l_@@_y_int }
1503 {
1504 \draw_path_circle:nn
1505 { \l_@@_x_int cm, \l_@@_y_int cm } { 1mm }
1506 }
1507 }
1508 % \end{macrocode}
1509 % \end{macro}
1510 %
1511 %
1512 % \begin{macro}{\@@_draw_board_star:}
1513 % 绘制棋盘的星位(路径)。
1514 % \begin{macrocode}
1515 \cs_new:Nn \@@_draw_board_star:
1516 {
1517 \clist_clear:N \l_@@_point_clist
1518 \int_case:nn { \g_@@_size_int }
1519 {
1520 { \c_@@_normal_size_int }
1521 { \clist_set_eq:NN \l_@@_point_clist \c_@@_normal_star_clist }
1522 { \c_@@_mid_size_int }
1523 { \clist_set_eq:NN \l_@@_point_clist \c_@@_mid_star_clist }
1524 { \c_@@_small_size_int }
1525 { \clist_set_eq:NN \l_@@_point_clist \c_@@_small_star_clist }
1526 }
1527 \clist_map_function:NN \l_@@_point_clist \@@_draw_point:n
1528 }
1529 % \end{macrocode}
1530 % \end{macro}
1531 %
1532 %
1533 % \begin{macro}{\@@_set_loc_label:nn}
1534 % 设置坐标标签(|#1| 标签方案;|#2| 单轴坐标)。
1535 % \begin{macrocode}
1536 \cs_new:Npn \@@_set_loc_label:nn #1#2
1537 {
1538 \str_case_e:nn { #1 }
1539 {
1540 { A }
1541 { \str_set:Nx \l_@@_label_str { \int_to_Alph:n { #2 } } }
1542 { \c_@@_normal_mode_str }
1543 { \str_set:NV \l_@@_label_str { #2 } }
1544 { \c_@@_sgf_mode_str }
1545 {
1546 \int_set:Nn \l_tmpa_int { \g_@@_size_int - #2 + 1 }
1547 \str_set:Nx\l_@@_label_str { \int_to_alph:n { \l_tmpa_int } }
1548 }
1549 }
1550 }
1551 % \end{macrocode}
1552 % \end{macro}
1553 %
1554 %
1555 % \begin{macro}{\@@_draw_board_loc:}
1556 % 绘制棋盘的坐标(路径)。
1557 % \begin{macrocode}
1558 \cs_new:Nn \@@_draw_board_loc:
1559 {
1560 \int_gset:Nn \g_tmpa_int
1561 { \int_sign:n { \l_@@_x_max_int - \l_@@_x_min_int } }
1562 \int_gset:Nn \g_tmpb_int
1563 { \int_sign:n { \l_@@_y_max_int - \l_@@_y_min_int } }
1564 \int_step_inline:nnnn
1565 { \l_@@_x_min_int } { \g_tmpa_int } { \l_@@_x_max_int }
1566 {
1567 \int_set:Ne \l_@@_tmp_int { \int_abs:n { ##1 } }
1568 \bool_if:NTF \l_@@_swap_xy_bool
1569 { \@@_set_loc_label:nn { \l_@@_loc_mode_str } { \l_@@_tmp_int } }
1570 { \@@_set_loc_label:nn { A } { \l_@@_tmp_int } }
1571 \hbox_set:Nn \l_tmpa_box { \l_@@_label_str }
1572 \fp_set:Nn \l_tmpa_fp { 0.2 * \g_tmpb_int }
1573 \fp_set:Nn \l_tmpb_fp { 0.5 * { \box_ht:N \l_tmpa_box } * \g_tmpb_int }
1574 \bool_if:NT \l_@@_up_bool
1575 {
1576 \draw_box_use:Nn \l_tmpa_box
1577 {
1578 ##1 cm - 0.5 * { \box_wd:N \l_tmpa_box },
1579 (\l_@@_y_max_fp + \l_tmpa_fp ) cm - abs(\l_tmpb_fp) + \l_tmpb_fp
1580 }
1581 }
1582 \bool_if:NT \l_@@_down_bool
1583 {
1584 \draw_box_use:Nn \l_tmpa_box
1585 {
1586 ##1 cm - 0.5 * { \box_wd:N \l_tmpa_box },
1587 (\l_@@_y_min_fp - \l_tmpa_fp ) cm - abs(\l_tmpb_fp) - \l_tmpb_fp
1588 }
1589 }
1590 }
1591 \int_step_inline:nnnn
1592 { \l_@@_y_min_int } { \g_tmpb_int } { \l_@@_y_max_int }
1593 {
1594 \int_set:Ne \l_@@_tmp_int { \int_abs:n { ##1 } }
1595 \bool_if:NTF \l_@@_swap_xy_bool
1596 { \@@_set_loc_label:nn { A } { \l_@@_tmp_int } }
1597 { \@@_set_loc_label:nn { \l_@@_loc_mode_str } { \l_@@_tmp_int } }
1598 \hbox_set:Nn \l_tmpa_box { \l_@@_label_str }
1599 \fp_set:Nn \l_tmpa_fp { 0.2 * \g_tmpa_int }
1600 \fp_set:Nn \l_tmpb_fp { 0.5 * { \box_wd:N \l_tmpa_box } * \g_tmpa_int }
1601 \bool_if:NT \l_@@_left_bool
1602 {
1603 \draw_box_use:Nn \l_tmpa_box
1604 {
1605 (\l_@@_x_min_fp - \l_tmpa_fp) cm - abs(\l_tmpb_fp) - \l_tmpb_fp,
1606 ##1 cm - 0.5 * { \box_ht:N \l_tmpa_box }
1607 }
1608 }
1609 \bool_if:NT \l_@@_right_bool
1610 {
1611 \draw_box_use:Nn \l_tmpa_box
1612 {
1613 (\l_@@_y_max_fp + \l_tmpa_fp) cm - abs(\l_tmpb_fp) + \l_tmpb_fp,
1614 ##1 cm - 0.5 * { \box_ht:N \l_tmpa_box }
1615 }
1616 }
1617 }
1618 }
1619 % \end{macrocode}
1620 % \end{macro}
1621 %
1622 %
1623 % \begin{macro}{\@@_draw_board:}
1624 % 绘制完整的棋盘元素。
1625 % \begin{macrocode}
1626 \cs_new:Nn \@@_draw_board:
1627 {
1628 \@@_calc_board_border:
1629 % \end{macrocode}
1630 %
1631 % \begin{macrocode}
1632 \draw_linewidth:n { 0.7 }
1633 \color_select:n { black }
1634 \@@_draw_board_grid:
1635 \draw_path_use_clear:n { stroke }
1636 % \end{macrocode}
1637 %
1638 % \begin{macrocode}
1639 \draw_linewidth:n { 2 }
1640 \@@_draw_board_border:
1641 \draw_path_use_clear:n { stroke }
1642 \@@_draw_board_corner:
1643 \draw_path_use_clear:n { stroke }
1644 % \end{macrocode}
1645 %
1646 % \begin{macrocode}
1647 \color_select:n { black }
1648 \@@_draw_board_star:
1649 \draw_path_use_clear:n { draw, fill }
1650 % \end{macrocode}
1651 %
1652 % \begin{macrocode}
1653 \color_select:n { black!50 }
1654 \bool_if:NT \l_@@_show_loc_bool
1655 { \@@_draw_board_loc: }
1656 \draw_path_use_clear:n { stroke }
1657 }
1658 % \end{macrocode}
1659 % \end{macro}
1660 %
1661 %
1662 % \begin{macro}{\@@_draw_points:}
1663 % 绘制完整的指示点。
1664 % \begin{macrocode}
1665 \cs_new:Npn \@@_draw_points:
1666 {
1667 \color_select:n { red }
1668 \clist_map_function:NN \g_@@_red_point_clist \@@_draw_point:n
1669 \draw_path_use_clear:n { draw, fill }
1670 \color_select:n { green }
1671 \clist_map_function:NN \g_@@_green_point_clist \@@_draw_point:n
1672 \draw_path_use_clear:n { draw, fill }
1673 \color_select:n { blue }
1674 \clist_map_function:NN \g_@@_blue_point_clist \@@_draw_point:n
1675 \draw_path_use_clear:n { draw, fill }
1676 }
1677 % \end{macrocode}
1678 % \end{macro}
1679 %
1680 % \begin{macro}{\@@_draw_stone:nnnn}
1681 % 绘制一手棋或纯标签(|#1| 黑白方;|#2| $x$坐标;|#3| $y$ 坐标;|#4| 标签)。\\
1682 % 坐标是变换后的坐标。
1683 % \begin{macrocode}
1684 \cs_new:Npn \@@_draw_stone:nnnn #1#2#3#4
1685 {
1686 % \end{macrocode}
1687 % 绘制外围空白,如果是纯标签则不绘制:
1688 % \begin{macrocode}
1689 \int_compare:nNnF { #1 } = { 3 }
1690 {
1691 \color_fill:n { white }
1692 \draw_path_circle:nn { #2cm, #3cm } { 4.4mm }
1693 \draw_path_use_clear:n { fill }
1694 }
1695 % \end{macrocode}
1696 % 绘制棋子(不含标签);如果为纯标签,则绘制空白:
1697 % \begin{macrocode}
1698 \color_select:n { black }
1699 \int_case:nn { #1 }
1700 {
1701 { 1 } { \color_fill:n { black } }
1702 { 2 } { \color_fill:n { white } }
1703 { 3 } { \color_select:n { white } }
1704 }
1705 \draw_path_circle:nn{ #2cm, #3cm } { 4mm }
1706 \draw_path_use_clear:n { draw, fill }
1707 % \end{macrocode}
1708 % 绘制棋子标签:
1709 % \begin{macrocode}
1710 \int_case:nn { #1 }
1711 {
1712 { 1 } { \color_select:n { white } }
1713 { 2 } { \color_select:n { black } }
1714 { 3 } { \color_select:n { blue } }
1715 }
1716 \hbox_set:Nn \l_tmpa_box { \Large \textbf{ #4 } }
1717 \draw_box_use:Nn \l_tmpa_box
1718 {
1719 #2cm - 0.5 * { \box_wd:N \l_tmpa_box },
1720 #3cm - 0.5 * { \box_ht:N \l_tmpa_box }
1721 }
1722 }
1723 % \end{macrocode}
1724 % \end{macro}
1725 %
1726 %
1727 % \begin{macro}{\@@_draw_stones:}
1728 % 绘制完整的常规棋子。
1729 % \begin{macrocode}
1730 \cs_new:Nn \@@_draw_stones:
1731 {
1732 \draw_linewidth:n { 1 }
1733 \int_step_inline:nn {\g_@@_step_count_int}
1734 {
1735 \int_set:Ne \l_@@_x_int
1736 { \intarray_item:Nn \g_@@_x_intarray { ##1 } }
1737 \int_set:Ne \l_@@_y_int
1738 { \intarray_item:Nn \g_@@_y_intarray { ##1 } }
1739 \int_set:Ne \l_@@_player_int
1740 { \intarray_item:Nn \g_@@_player_intarray { ##1 } }
1741 \str_set:Nx \l_@@_tmp_str
1742 { \seq_item:Nn \g_@@_label_seq { ##1 } }
1743 \seq_if_in:NnT \g_@@_die_seq { ##1 }
1744 { \int_set:Nn \l_@@_x_int { 0 } }
1745 \int_if_zero:nF { \l_@@_x_int }
1746 {
1747 \@@_transform_xy:NN \l_@@_x_int \l_@@_y_int
1748 \@@_within_range:nnT
1749 { \l_@@_x_int } { \l_@@_y_int }
1750 {
1751 \@@_draw_stone:nnnn { \l_@@_player_int }
1752 { \l_@@_x_int } { \l_@@_y_int } { \l_@@_tmp_str }
1753 }
1754 }
1755 }
1756 }
1757 % \end{macrocode}
1758 % \end{macro}
1759 %
1760 %
1761 % \begin{macro}{\@@_draw_specific_stone:}
1762 % 绘制指定的一个特殊的棋子(死子、虚着)。
1763 % \begin{macrocode}
1764 \cs_new:Nn \@@_draw_specific_stone:
1765 {
1766 \color_select:n { black }
1767 \int_case:nn { \l_@@_player_int }
1768 {
1769 { 1 } { \color_fill:n { black } }
1770 { 2 } { \color_fill:n { white } }
1771 }
1772 \draw_path_circle:nn{ \l_@@_x_fp cm, \l_@@_y_fp cm } { 4mm }
1773 \draw_path_use_clear:n { draw, fill }
1774 % \end{macrocode}
1775 % \begin{macrocode}
1776 \int_case:nn { \l_@@_player_int }
1777 {
1778 { 1 } { \color_select:n { white } }
1779 { 2 } { \color_select:n { black } }
1780 }
1781 \@@_xy_to_loc:N \l_tmpa_str
1782 \hbox_set:Nn \l_tmpa_box { \Large \textbf{ \l_@@_tmp_str } }
1783 \hbox_set:Nn \l_tmpb_box { \Large \texttt{ \l_tmpa_str } }
1784 \draw_box_use:Nn \l_tmpa_box
1785 {
1786 \l_@@_x_fp cm - 0.5 * { \box_wd:N \l_tmpa_box },
1787 \l_@@_y_fp cm - 0.5 * { \box_ht:N \l_tmpa_box }
1788 }
1789 \color_select:n { black }
1790 \draw_box_use:Nn \l_tmpb_box
1791 {
1792 \l_@@_x_fp cm + 6mm,
1793 \l_@@_y_fp cm - 0.5 * { \box_ht:N \l_tmpa_box }
1794 }
1795 % \end{macrocode}
1796 % \begin{macrocode}
1797 \fp_set:Nn \l_tmpa_fp { min(\l_@@_x_min_fp, \l_@@_x_max_fp) }
1798 \fp_set:Nn \l_tmpb_fp { max(\l_@@_x_min_fp, \l_@@_x_max_fp) }
1799 \fp_add:Nn \l_@@_x_fp { 2 }
1800 \fp_compare:nNnT { \l_@@_x_fp } > { \l_tmpb_fp }
1801 {
1802 \fp_set_eq:NN \l_@@_x_fp \l_tmpa_fp
1803 \fp_sub:Nn \l_@@_y_fp { 1 }
1804 }
1805 }
1806 % \end{macrocode}
1807 % \end{macro}
1808 %
1809 %
1810 % \begin{macro}{\@@_draw_specific_stones:}
1811 % 绘制完整的特殊棋子(死子、虚着)。
1812 % \begin{macrocode}
1813 \cs_new:Nn \@@_draw_specific_stones:
1814 {
1815 \draw_linewidth:n { 1 }
1816 \fp_set:Nn \l_@@_x_fp { min(\l_@@_x_min_int, \l_@@_x_max_int) }
1817 \fp_set:Nn \l_@@_y_fp { min(\l_@@_y_min_int, \l_@@_y_max_int) - 1.2}
1818 \int_step_inline:nn {\g_@@_step_count_int}
1819 {
1820 \int_set:Ne \l_@@_x_int
1821 { \intarray_item:Nn \g_@@_x_intarray { ##1 } }
1822 \int_set:Ne \l_@@_y_int
1823 { \intarray_item:Nn \g_@@_y_intarray { ##1 } }
1824 \int_set:Ne \l_@@_player_int
1825 { \intarray_item:Nn \g_@@_player_intarray { ##1 } }
1826 \str_set:Nx \l_@@_tmp_str
1827 { \seq_item:Nn \g_@@_label_seq { ##1 } }
1828 % \end{macrocode}
1829 % \begin{macrocode}
1830 \seq_if_in:NnTF \g_@@_die_seq { ##1 }
1831 { \int_set:Nn \l_tmpa_int { 0 } }
1832 { \int_set_eq:NN \l_tmpa_int \l_@@_x_int }
1833 \str_compare:eNeT { \l_@@_tmp_str } = {}
1834 { \int_set:Nn \l_tmpa_int { 1 } }
1835 \bool_lazy_all:nT
1836 {
1837 { \int_compare_p:nNn { \l_tmpa_int } = { 0 } }
1838 { \int_compare_p:nNn { \l_@@_player_int } > { 0 } }
1839 { \int_compare_p:nNn { \l_@@_player_int } < { 3 } }
1840 }
1841 { \@@_draw_specific_stone: }
1842 }
1843 }
1844 % \end{macrocode}
1845 % \end{macro}
1846 %
1847 %
1848 % \begin{macro}{\@@_show:}
1849 % 显示完整对局。
1850 % \begin{macrocode}
1851 \cs_new:Nn \@@_show:
1852 {
1853 \draw_begin:
1854 \group_begin:
1855 \draw_transform_scale:n { \l_@@_scale_fp }
1856 \@@_draw_board:
1857 \@@_draw_points:
1858 \@@_draw_stones:
1859 \@@_draw_specific_stones:
1860 \group_end:
1861 \draw_end:
1862 }
1863 % \end{macrocode}
1864 % \end{macro}
1865 %
1866 %
1867 % \subsection{定义文档命令}
1868 %
1869 % 本节定义了一些供宏包外使用的文档命令。
1870 %
1871 % \begin{macro}{\newweiqi}
1872 % 开始新对局。
1873 % \begin{macrocode}
1874 \NewDocumentCommand \newweiqi { s o }
1875 {
1876 \IfNoValueTF { #2 }
1877 { \@@_new_game:n { \g_@@_default_size_int } }
1878 {
1879 \IfBooleanT { #1 } { \int_gset:Nn \g_@@_default_size_int { #2 } }
1880 \@@_new_game:n { #2 }
1881 }
1882 }
1883 % \end{macrocode}
1884 % \end{macro}
1885 %
1886 %
1887 % \begin{macro}{\weiqisize}
1888 % 更改棋盘大小。
1889 % \begin{macrocode}
1890 \NewDocumentCommand \weiqisize { s m }
1891 {
1892 \IfBooleanT{ #1 }
1893 { \int_gset:Nn \g_@@_default_size_int { #2 } }
1894 \int_set:Nn \g_@@_size_int { #2 }
1895 }
1896 % \end{macrocode}
1897 % \end{macro}
1898 %
1899 %
1900 % \begin{macro}{\weiqiblack, \weiqiwhite}
1901 % 添加黑/白棋子。星号版本命令无区别。
1902 % \begin{macrocode}
1903 \NewDocumentCommand \weiqiblack { s o m }
1904 {
1905 \IfNoValueTF { #2 }
1906 { \@@_add_stones:nnn { 1 } { #3 } { } }
1907 { \@@_add_stones:nnn { 1 } { #3 } { #2 } }
1908 }
1909 % \end{macrocode}
1910 % \begin{macrocode}
1911 \NewDocumentCommand \weiqiwhite { s o m }
1912 {
1913 \IfNoValueTF { #2 }
1914 { \@@_add_stones:nnn { 2 } { #3 } { } }
1915 { \@@_add_stones:nnn { 2 } { #3 } { #2 } }
1916 }
1917 % \end{macrocode}
1918 % \end{macro}
1919 %
1920 %
1921 % \begin{macro}{\weiqisgf}
1922 % 使用 sgf 文本添加黑/白棋子。星号版本命令无区别。
1923 % \begin{macrocode}
1924 \NewDocumentCommand \weiqisgf { s o m }
1925 {
1926 \IfNoValueTF { #2 }
1927 { \@@_add_sgf_stones:nn { #3 } { } }
1928 { \@@_add_sgf_stones:nn { #3 } { #2 } }
1929 }
1930 % \end{macrocode}
1931 % \end{macro}
1932 %
1933 %
1934 % \begin{macro}{\inputsgf}
1935 % 读取 sgf 棋谱。星号版本命令无区别。
1936 % \begin{macrocode}
1937 \NewDocumentCommand \inputsgf { s o m }
1938 {
1939 \ior_open:Nn \g_tmpa_ior { #3 }
1940 \str_set:Nn \l_@@_tmp_str {}
1941 \ior_str_map_inline:Nn \g_tmpa_ior
1942 {
1943 \str_put_right:Nx \l_@@_tmp_str { ##1 }
1944 }
1945 \ior_close:N \g_tmpa_ior
1946 % \end{macrocode}
1947 % \begin{macrocode}
1948 \regex_extract_once:nVNTF { ;GM\[1\] } { \l_@@_tmp_str } \l_tmpa_seq
1949 {
1950 \regex_extract_once:nVNTF { SZ\[[0-9]+\] } { \l_@@_tmp_str } \l_tmpa_seq
1951 {
1952 \str_set:Nx \l_tmpa_str { \seq_item:Nn \l_tmpa_seq { 1 } }
1953 \str_set:Nx \l_tmpa_str { \str_range:Nnn \l_tmpa_str { 4 } { -2 } }
1954 \int_set:Ne \l_tmpa_int { \l_tmpa_str }
1955 \newweiqi [ \l_tmpa_int ]
1956 \regex_extract_once:nVN { HA\[[0-9]+\] } { \l_@@_tmp_str } \l_tmpa_seq
1957 \str_set:Nx \l_tmpa_str { \seq_item:Nn \l_tmpa_seq { 1 } }
1958 \str_set:Nx \l_tmpa_str {\str_range:Nnn \l_tmpa_str { 4 } { -2 } }
1959 \int_set:Ne \l_tmpa_int { \l_tmpa_str }
1960 \IfNoValueTF { #2 }
1961 { \int_add:Nn \l_tmpa_int { 1 } }
1962 { \int_add:Nn \l_tmpa_int { #2 } }
1963 \@@_add_sgf_stones:VV { \l_@@_tmp_str } { \l_tmpa_int }
1964 }
1965 { 解析棋盘大小失败 }
1966 }
1967 { 不支持的棋谱 }
1968 }
1969 % \end{macrocode}
1970 % \end{macro}
1971 %
1972 %
1973 % \begin{macro}{\resetnumber}
1974 % 重新修改棋子手数。星号版本命令无区别。
1975 % \begin{macrocode}
1976 \NewDocumentCommand \resetnumber { s o }
1977 {
1978 \IfNoValueTF { #2 }
1979 { \@@_reset_stone_number:n { 1 } }
1980 { \@@_reset_stone_number:n { #2 } }
1981 }
1982 % \end{macrocode}
1983 % \end{macro}
1984 %
1985 %
1986 % \begin{macro}{\weiqilabel, \clearlabel}
1987 % 添加/删除标签。
1988 % \begin{macrocode}
1989 \NewDocumentCommand \weiqilabel { s o m }
1990 {
1991 \IfBooleanT{ #1 } { \@@_clear_labels: }
1992 \IfNoValueTF { #2 }
1993 { \@@_add_stones:nnn { 3 } { #3 } { a } }
1994 { \@@_add_stones:nnn { 3 } { #3 } { #2 } }
1995 }
1996 % \end{macrocode}
1997 %
1998 % \begin{macrocode}
1999 \NewDocumentCommand \clearlabel { }
2000 { \@@_clear_labels: }
2001 % \end{macrocode}
2002 % \end{macro}
2003 %
2004 %
2005 % \begin{macro}{\weiqired, \weiqigreen, \weiqiblue, \clearpoint}
2006 % 添加红绿蓝点。
2007 % \begin{macrocode}
2008 \NewDocumentCommand \weiqired { s m }
2009 {
2010 \IfBooleanT{ #1 } { \@@_clear_points: }
2011 \@@_add_points:nn { red } { #2 }
2012 }
2013 % \end{macrocode}
2014 %
2015 % \begin{macrocode}
2016 \NewDocumentCommand \weiqigreen { s m }
2017 {
2018 \IfBooleanT{ #1 } { \@@_clear_points: }
2019 \@@_add_points:nn { green } { #2 }
2020 }
2021 % \end{macrocode}
2022 %
2023 % \begin{macrocode}
2024 \NewDocumentCommand \weiqiblue { s m }
2025 {
2026 \IfBooleanT{ #1 } { \@@_clear_points: }
2027 \@@_add_points:nn { blue } { #2 }
2028 }
2029 % \end{macrocode}
2030 %
2031 % \begin{macrocode}
2032 \NewDocumentCommand \clearpoint { }
2033 { \@@_clear_points: }
2034 % \end{macrocode}
2035 % \end{macro}
2036 %
2037 %
2038 % \begin{macro}{\weiqidie}
2039 % 标记死子。
2040 % \begin{macrocode}
2041 \NewDocumentCommand \weiqidie { s m }
2042 {
2043 \@@_modify_stones:nN { #2 } \@@_die_stone:n
2044 }
2045 % \end{macrocode}
2046 % \end{macro}
2047 %
2048 %
2049 % \begin{macro}{\weiqiremove}
2050 % 移除棋子。
2051 % \begin{macrocode}
2052 \NewDocumentCommand \weiqiremove { s m }
2053 {
2054 \@@_modify_stones:nN { #2 } \@@_remove_stone:n
2055 }
2056 % \end{macrocode}
2057 % \end{macro}
2058 %
2059 %
2060 % \begin{macro}{\weiqichange}
2061 % 切换棋子黑白方。
2062 % \begin{macrocode}
2063 \NewDocumentCommand \weiqichange { s m }
2064 {
2065 \@@_modify_stones:nN { #2 } \@@_change_stone:n
2066 }
2067 % \end{macrocode}
2068 % \end{macro}
2069 %
2070 %
2071 % \begin{macro}{\showweiqi}
2072 % 显示棋盘。
2073 % \begin{macrocode}
2074 \NewDocumentCommand \showweiqi { s o }
2075 {
2076 \IfNoValueTF { #2 }
2077 { \@@_calc_range: }
2078 { \@@_set_range:n { #2 } }
2079 \@@_show:
2080 \IfBooleanF { #1 } { \newweiqi }
2081 }
2082 % \end{macrocode}
2083 % \end{macro}
2084 %
2085 %
2086 % \begin{macro}{\nonelocmode, \normallocmode, \sgflocmode}
2087 % 设置围棋坐标显示模式。
2088 % \begin{macrocode}
2089 \NewDocumentCommand \nonelocmode { s }
2090 {
2091 \bool_set_false:N \l_@@_show_loc_bool
2092 \IfBooleanT { #1 } { \bool_gset_false:N \g_@@_show_loc_bool }
2093 }
2094 % \end{macrocode}
2095 %
2096 % \begin{macrocode}
2097 \NewDocumentCommand \normallocmode { s }
2098 {
2099 \bool_set_true:N \l_@@_show_loc_bool
2100 \str_set_eq:NN \l_@@_loc_mode_str \c_@@_normal_mode_str
2101 \IfBooleanT { #1 }
2102 {
2103 \bool_gset_true:N \g_@@_show_loc_bool
2104 \str_gset_eq:NN \g_@@_loc_mode_str \c_@@_normal_mode_str
2105 }
2106 }
2107 % \end{macrocode}
2108 %
2109 % \begin{macrocode}
2110 \NewDocumentCommand \sgflocmode { s }
2111 {
2112 \bool_set_true:N \l_@@_show_loc_bool
2113 \str_set_eq:NN \l_@@_loc_mode_str \c_@@_sgf_mode_str
2114 \IfBooleanT { #1 }
2115 {
2116 \bool_gset_true:N \g_@@_show_loc_bool
2117 \str_gset_eq:NN \g_@@_loc_mode_str \c_@@_sgf_mode_str
2118 }
2119 }
2120 % \end{macrocode}
2121 % \end{macro}
2122 %
2123
2124 %
2125 % \begin{macro}{\weiqirotate, \weiqimirror, \weiqiposition}
2126 % 旋转棋盘、镜像棋盘或指定棋盘方位。
2127 % \begin{macrocode}
2128 \NewDocumentCommand \weiqirotate { s o }
2129 {
2130 \IfNoValueTF { #2 }
2131 { \int_set:Nn \l_tmpa_int { 90 } }
2132 { \int_set:Ne \l_tmpa_int { #2 } }
2133 \int_compare:nNnT { \l_tmpa_int } < { 0 }
2134 { \int_add:Nn \l_tmpa_int { 360 } }
2135 \int_case:nn { \l_tmpa_int }
2136 {
2137 { 90 }
2138 {
2139 \bool_set_inverse:N \l_@@_swap_xy_bool
2140 \int_set:Ne \l_tmpb_int { \l_@@_x_direction_int }
2141 \int_set:Ne \l_@@_x_direction_int { \l_@@_y_direction_int }
2142 \int_set:Ne \l_@@_y_direction_int { 0 - \l_tmpb_int }
2143 }
2144 { 180 }
2145 {
2146 \int_set:Ne \l_@@_x_direction_int { 0 - \l_@@_x_direction_int }
2147 \int_set:Ne \l_@@_y_direction_int { 0 - \l_@@_y_direction_int }
2148 }
2149 { 270 }
2150 {
2151 \bool_set_inverse:N \l_@@_swap_xy_bool
2152 \int_set:Ne \l_tmpb_int { \l_@@_x_direction_int }
2153 \int_set:Ne \l_@@_x_direction_int { 0 - \l_@@_y_direction_int }
2154 \int_set:Ne \l_@@_y_direction_int { \l_tmpb_int }
2155 }
2156 }
2157 \IfBooleanT{ #1 }
2158 {
2159 \bool_gset_eq:NN \g_@@_swap_xy_bool \l_@@_swap_xy_bool
2160 \int_gset_eq:NN \g_@@_x_direction_int \l_@@_x_direction_int
2161 \int_gset_eq:NN \g_@@_y_direction_int \l_@@_y_direction_int
2162 }
2163 }
2164 % \end{macrocode}
2165 % \begin{macrocode}
2166 \NewDocumentCommand \weiqimirror { s o }
2167 {
2168 \IfNoValueTF { #2 }
2169 { \str_set:Nn \l_tmpa_str { xy } }
2170 { \str_set:Nx \l_tmpa_str { #2 } }
2171 \str_case_e:nn { \l_tmpa_str }
2172 {
2173 { x }
2174 {
2175 \int_set:Ne \l_@@_x_direction_int { 0 - \l_@@_x_direction_int }
2176 }
2177 { y }
2178 {
2179 \int_set:Ne \l_@@_y_direction_int { 0 - \l_@@_y_direction_int }
2180 }
2181 { xy }
2182 {
2183 \int_set:Ne \l_@@_x_direction_int { 0 - \l_@@_x_direction_int }
2184 \int_set:Ne \l_@@_y_direction_int { 0 - \l_@@_y_direction_int }
2185 }
2186
2187 }
2188 \IfBooleanT{ #1 }
2189 {
2190 \bool_set_eq:NN \g_@@_swap_xy_bool \l_@@_swap_xy_bool
2191 \int_set_eq:NN \g_@@_x_direction_int \l_@@_x_direction_int
2192 \int_set_eq:NN \g_@@_y_direction_int \l_@@_y_direction_int
2193 }
2194 }
2195 % \end{macrocode}
2196 % \begin{macrocode}
2197 \NewDocumentCommand \weiqiposition { s o }
2198 {
2199 \IfNoValueTF { #2 }
2200 { \int_set:Nn \l_tmpa_int { 0 } }
2201 { \int_set:Ne \l_tmpa_int { #2 } }
2202 \int_compare:nNnT { \l_tmpa_int } < { 0 }
2203 { \int_add:Nn \l_tmpa_int { 360 } }
2204 \int_case:nn { \l_tmpa_int }
2205 {
2206 { 0 }
2207 {
2208 \bool_set_false:N \l_@@_swap_xy_bool
2209 \int_set:Nn \l_@@_x_direction_int { 1 }
2210 \int_set:Nn \l_@@_y_direction_int { 1 }
2211 }
2212 { 90 }
2213 {
2214 \bool_set_true:N \l_@@_swap_xy_bool
2215 \int_set:Nn \l_@@_x_direction_int { 1 }
2216 \int_set:Nn \l_@@_y_direction_int { -1 }
2217 }
2218 { 180 }
2219 {
2220 \bool_set_false:N \l_@@_swap_xy_bool
2221 \int_set:Nn \l_@@_x_direction_int { -1 }
2222 \int_set:Nn \l_@@_y_direction_int { -1 }
2223 }
2224 { 270 }
2225 {
2226 \bool_set_true:N \l_@@_swap_xy_bool
2227 \int_set:Nn \l_@@_x_direction_int { -1 }
2228 \int_set:Nn \l_@@_y_direction_int { 1 }
2229 }
2230 }
2231 \IfBooleanT{ #1 }
2232 {
2233 \bool_gset_eq:NN \g_@@_swap_xy_bool \l_@@_swap_xy_bool
2234 \int_gset_eq:NN \g_@@_x_direction_int \l_@@_x_direction_int
2235 \int_gset_eq:NN \g_@@_y_direction_int \l_@@_y_direction_int
2236 }
2237 }
2238 % \end{macrocode}
2239 % \end{macro}
2240 %
2241 %
2242 % \begin{macro}{\weiqiscale}
2243 % 缩放棋盘。
2244 % \begin{macrocode}
2245 \NewDocumentCommand \weiqiscale { s o }
2246 {
2247 \IfNoValueTF { #2 }
2248 { \fp_set:Nn \l_@@_scale_fp { 1.0 } }
2249 { \fp_set:Nn \l_@@_scale_fp { #2 * \l_@@_scale_fp } }
2250 \IfBooleanT{ #1 }
2251 { \fp_set_eq:NN \g_@@_scale_fp \l_@@_scale_fp }
2252 }
2253 % \end{macrocode}
2254 % \end{macro}
2255 %
2256 %
2257 % \begin{macro}{\weiqiminsize}
2258 % 最小显示尺寸。
2259 % \begin{macrocode}
2260 \NewDocumentCommand \weiqiminsize { s m m }
2261 {
2262 \int_set:Nn \l_@@_min_width_int { #2 }
2263 \int_set:Nn \l_@@_min_hight_int { #3 }
2264 \IfBooleanT{ #1 }
2265 {
2266 \int_gset:Nn \g_@@_min_width_int { #2 }
2267 \int_gset:Nn \g_@@_min_hight_int { #3 }
2268 }
2269 }
2270 % \end{macrocode}
2271 % \end{macro}
2272 %
2273 %
2274 % \begin{macro}{\saveweiqi}
2275 % 保存对局。
2276 % \begin{macrocode}
2277 \NewDocumentCommand \saveweiqi { s o }
2278 {
2279 \IfNoValueTF { #2 }
2280 { \str_set:Nx \l_tmpa_str { Default } }
2281 { \str_set:Nx \l_tmpa_str { \int_to_alph:n { #2 } } }
2282 \cs_if_free:cT { g_@@_size_int_\l_tmpa_str }
2283 {
2284 \int_new:c { g_@@_size_int_\l_tmpa_str }
2285 \int_new:c { g_@@_step_count_int_\l_tmpa_str }
2286 \intarray_new:cn { g_@@_x_intarray_\l_tmpa_str }
2287 { \c_@@_max_step_int }
2288 \intarray_new:cn { g_@@_y_intarray_\l_tmpa_str }
2289 { \c_@@_max_step_int }
2290 \intarray_new:cn { g_@@_player_intarray_\l_tmpa_str }
2291 { \c_@@_max_step_int }
2292 \seq_new:c { g_@@_label_seq_\l_tmpa_str }
2293 \seq_new:c { g_@@_die_seq_\l_tmpa_str }
2294 }
2295 \int_gset_eq:cN { g_@@_size_int_\l_tmpa_str } \g_@@_size_int
2296 \int_gset_eq:cN
2297 { g_@@_step_count_int_\l_tmpa_str } \g_@@_step_count_int
2298 \int_step_inline:nn { \c_@@_max_step_int }
2299 {
2300 \intarray_gset:cnn { g_@@_x_intarray_\l_tmpa_str } { ##1 }
2301 { \intarray_item:Nn \g_@@_x_intarray { ##1 } }
2302 \intarray_gset:cnn { g_@@_y_intarray_\l_tmpa_str } { ##1 }
2303 { \intarray_item:Nn \g_@@_y_intarray { ##1 } }
2304 \intarray_gset:cnn { g_@@_player_intarray_\l_tmpa_str } { ##1 }
2305 { \intarray_item:Nn \g_@@_player_intarray { ##1 } }
2306 }
2307 \clist_gset_eq:cN { g_@@_label_seq_\l_tmpa_str } \g_@@_label_seq
2308 \clist_gset_eq:cN { g_@@_die_seq_\l_tmpa_str } \g_@@_die_seq
2309 }
2310 % \end{macrocode}
2311 % \end{macro}
2312 %
2313 %
2314 % \begin{macro}{\useweiqi}
2315 % 使用对局。
2316 % \begin{macrocode}
2317 \NewDocumentCommand \useweiqi { s o }
2318 {
2319 \IfNoValueTF { #2 }
2320 { \str_set:Nx \l_tmpa_str { Default } }
2321 { \str_set:Nx \l_tmpa_str { \int_to_alph:n { #2 } } }
2322 \cs_if_free:cTF { g_@@_size_int_\l_tmpa_str }
2323 { \@@_new_game:n { \g_@@_default_size_int } }
2324 {
2325 \int_set_eq:Nc \l_tmpa_int { g_@@_size_int_\l_tmpa_str }
2326 \@@_new_game:n { \l_tmpa_int }
2327 \int_gset_eq:Nc \g_@@_step_count_int
2328 { g_@@_step_count_int_\l_tmpa_str }
2329 \int_step_inline:nn { \c_@@_max_step_int }
2330 {
2331 \intarray_gset:Nnn \g_@@_x_intarray { ##1 }
2332 { \intarray_item:cn { g_@@_x_intarray_\l_tmpa_str } { ##1 } }
2333 \intarray_gset:Nnn \g_@@_y_intarray { ##1 }
2334 { \intarray_item:cn { g_@@_y_intarray_\l_tmpa_str } { ##1 } }
2335 \intarray_gset:Nnn \g_@@_player_intarray { ##1 }
2336 {
2337 \intarray_item:cn
2338 { g_@@_player_intarray_\l_tmpa_str } { ##1 }
2339 }
2340 }
2341 \clist_set_eq:Nc \g_@@_label_seq { g_@@_label_seq_\l_tmpa_str }
2342 \clist_set_eq:Nc \g_@@_die_seq { g_@@_die_seq_\l_tmpa_str }
2343 }
2344 \IfBooleanT{ #1 }
2345 {
2346 \@@_clear_labels:
2347 \int_step_inline:nn { \g_@@_step_count_int }
2348 {
2349 \seq_gset_item:Nnn \g_@@_label_seq { ##1 } {}
2350 }
2351 }
2352 }
2353 % \end{macrocode}
2354 % \end{macro}
2355 %
2356 %
2357 % \begin{macro}{\weiqidata}
2358 % 查询内部数据。
2359 % \begin{macrocode}
2360 \NewDocumentCommand \weiqidata { s }
2361 {
2362 \noindent 棋盘大小:\int_use:N \g_@@_size_int~
2363 (默认:\int_use:N \g_@@_default_size_int)\\
2364 当前对局步数:\int_use:N \g_@@_step_count_int~(含纯标签及移除棋子)\\
2365 \int_compare:nNnT { \g_@@_step_count_int } > { 0 }
2366 { 序号:($x$,~$y$),所属方,标签,备注\\ }
2367 \int_step_inline:nn {\g_@@_step_count_int}
2368 {
2369 \int_set:Ne \l_@@_x_int
2370 { \intarray_item:Nn \g_@@_x_intarray { ##1 } }
2371 \int_set:Ne \l_@@_y_int
2372 { \intarray_item:Nn \g_@@_y_intarray { ##1 } }
2373 \int_set:Ne \l_@@_player_int
2374 { \intarray_item:Nn \g_@@_player_intarray { ##1 } }
2375 \str_set:Nx \l_@@_tmp_str
2376 { \seq_item:Nn \g_@@_label_seq { ##1 } }
2377 ##1:
2378 (\int_use:N \l_@@_x_int,~\int_use:N \l_@@_y_int),
2379 \int_case:nn { \l_@@_player_int }
2380 {
2381 { 1 } { B }
2382 { 2 } { W }
2383 { 3 } { L }
2384 { 0 } { - }
2385 },
2386 \str_if_empty:NTF \l_@@_tmp_str
2387 { \meta{空} }
2388 { \l_@@_tmp_str },
2389 \int_compare:nNnTF
2390 { \l_@@_player_int } = { 0 }
2391 { \meta{无效} }
2392 {
2393 \seq_if_in:NnT \g_@@_die_seq { ##1 }
2394 { \meta{死子} }
2395 {
2396 \int_compare:nNnT
2397 { \l_@@_x_int } = { 0 }
2398 { \meta{虚着} }
2399 }
2400 }\\
2401 }
2402 红色指示点:
2403 \clist_if_empty:NTF \g_@@_red_point_clist
2404 { \meta{空} }
2405 { \clist_use:Nn \g_@@_red_point_clist {,~} }\\
2406 绿色指示点:
2407 \clist_if_empty:NTF \g_@@_green_point_clist
2408 { \meta{空} }
2409 { \clist_use:Nn \g_@@_green_point_clist {,~} }\\
2410 蓝色指示点:
2411 \clist_if_empty:NTF \g_@@_blue_point_clist
2412 { \meta{空} }
2413 { \clist_use:Nn \g_@@_blue_point_clist {,~} }\\
2414 方位信息:
2415 \int_use:N \l_@@_x_direction_int,~
2416 \int_use:N \l_@@_x_direction_int,~
2417 \bool_to_str:N \l_@@_swap_xy_bool;~
2418 (全局:
2419 \int_use:N \g_@@_x_direction_int,~
2420 \int_use:N \g_@@_x_direction_int,~
2421 \bool_to_str:N \g_@@_swap_xy_bool
2422 )\\
2423 缩放比例:\fp_use:N \l_@@_scale_fp~
2424 (全局:\fp_use:N \g_@@_scale_fp)\\
2425 坐标刻度:\l_@@_loc_mode_str,~\bool_to_str:N \l_@@_show_loc_bool
2426 (全局:\g_@@_loc_mode_str,~\bool_to_str:N \g_@@_show_loc_bool)\\
2427 最小显示尺寸:
2428 \int_use:N \l_@@_min_width_int,~
2429 \int_use:N \l_@@_min_hight_int~
2430 (全局:
2431 \int_use:N \g_@@_min_width_int,~
2432 \int_use:N \g_@@_min_hight_int
2433 )\\
2434 \IfBooleanT{ #1 }
2435 {
2436 棋子区间:
2437 (\int_use:N \l_@@_x_min_int,~\int_use:N \l_@@_y_max_int),
2438 (\int_use:N \l_@@_x_max_int,~\int_use:N \l_@@_y_min_int)\\
2439 棋盘边界:
2440 (\fp_use:N \l_@@_x_min_fp,~\fp_use:N \l_@@_x_max_fp),
2441 (\fp_use:N \l_@@_y_min_fp,~\fp_use:N \l_@@_y_max_fp)\\
2442 是否边路:
2443 \bool_to_str:N \l_@@_up_bool,
2444 \bool_to_str:N \l_@@_down_bool,
2445 \bool_to_str:N \l_@@_left_bool,
2446 \bool_to_str:N \l_@@_right_bool(上下左右)\\
2447 }
2448 }
2449 % \end{macrocode}
2450 % \end{macro}
2451 %
2452 %
2453 % \subsection{扫尾}
2454 %
2455 % 初始新对局
2456 % \begin{macrocode}
2457 \newweiqi
2458 % \end{macrocode}
2459 %
2460 % 关闭 expl3 模式
2461 % \begin{macrocode}
2462 \ExplSyntaxOff
2463 % \end{macrocode}
2464 %
2465 % \begin{macrocode}
2466 %</package>
2467 % \end{macrocode}
2468 %
2469 % \end{implementation}
2470 %
2471 % \PrintIndex