<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%%     Copyright (C) 2020-2022 by Nan Geng &lt;nangeng@nwafu.edu.cn&gt;
%% --------------------------------------------------------------------------
%%
%%     This work may be distributed and/or modified under the
%%     conditions of the LaTeX Project Public License, either
%%     version 1.3c of this license or (at your option) any later
%%     version. This version of this license is in
%%        http://www.latex-project.org/lppl/lppl-1-3c.txt
%%     and the latest version of this license is in
%%        http://www.latex-project.org/lppl.txt
%%     and version 1.3 or later is part of all distributions of
%%     LaTeX version 2005/12/01 or later.
%%
%%     This work has the LPPL maintenance status "maintained".
%%
%%     The Current Maintainer of this work is Nan Geng.
%%
%% --------------------------------------------------------------------------
%%
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\RequirePackage{expl3}
\ProvidesExplPackage{chinesechess}{2022-05-09}{v1.2.0}
  {Typeset Chinese chess with l3draw}

\RequirePackage { l3keys2e, l3draw, xparse }

% æµ‹é‡ç›’å­æ€»é«˜åº¦(ä¿è¯TeXLiveçš„å‘ä¸‹å…¼å®¹)
\cs_if_free:NT \box_ht_plus_dp:N
  {
    \cs_new_protected:Npn \box_ht_plus_dp:N #1
      { \tex_dimexpr:D \box_ht:N #1 + \box_dp:N #1 \scan_stop: }
  }

% æ£‹ç›˜æŽ’ç‰ˆå‘½ä»¤ç”¨æˆ·æŽ¥å£
% #1 æ˜Ÿå·å‘½ä»¤ï¼Œæ˜¯å¦è¾“å‡ºæ£‹å­
% #2 æ£‹ç›˜ç±»åž‹ã€æ£‹å­ç±»åž‹ç­‰å¤–è§‚é€‰é¡¹
\NewDocumentCommand{\cchessboard}{ s o }
  {
    \group_begin:
      % æ˜Ÿå·å‘½ä»¤æ˜¯å¦å¸¦æ£‹å­
      \IfBooleanTF{ #1 }
        {
          \bool_set_false:N  \l__cchess_board_pieces_bool
        }{
          \bool_set_true:N \l__cchess_board_pieces_bool
        }

      \IfNoValueF { #2 }
        {
          % è®¾ç½®é€‰é¡¹
          \keys_set:nn { cchess } { #2 }

          % æœ‰draftå‚æ•°ï¼Œéœ€è¦é‡æž„æ£‹å­å’Œæ£‹ç›˜
          \tl_if_in:nnT { #2 } { draft }
            {
              % æž„å»ºæ£‹ç›˜
              \__cchess_board_construct:
              % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
              \__cchess_pieces_construct:
            }

          \bool_if:NF \g__cchess_draft_bool
            {
              % æž„å»ºæ£‹ç›˜
              \__cchess_board_option_if_in:nT { #2 }
                {
                  \__cchess_board_construct:
                }
              % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
              \__cchess_piece_option_if_in:nT { #2 }
                {
                  \__cchess_pieces_construct:
                }
            }
        }
      \__cchess_board_output:
    \group_end:
  }

% æ£‹è°±æŽ’ç‰ˆå‘½ä»¤ç”¨æˆ·æŽ¥å£
% #1 æ£‹ç›˜ç±»åž‹ã€æ£‹å­ç±»åž‹ç­‰å¤–è§‚é€‰é¡¹
% #2 æ£‹å­ä½ç½®åˆ—è¡¨
%    çº¢æ£‹ï¼šK=å¸…,A=ä»•,E/B=ç›¸,R=è½¦,C=ç&nbsp;²,N/H=é©¬,P=å…µ,
%    é»‘æ£‹ï¼šk=å°†,a=å£«,e/b=è±¡,r=è»Š,c=ç‚®,n/h=é¦¬,p=å’
%    æ¨ªå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8)
%    çºµå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8),j(9)
\NewDocumentCommand{\cchessman}{ o m }
  {
    \group_begin:
      % è®¾ç½®é€‰é¡¹
      \IfNoValueF { #1}
        {
          \keys_set:nn { cchess } { #1 }

          % æœ‰draftå‚æ•°ï¼Œéœ€è¦é‡æž„æ£‹å­å’Œæ£‹ç›˜
          \tl_if_in:nnT { #1 } { draft }
            {
              % æž„å»ºæ£‹ç›˜
              \__cchess_board_construct:
              % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
              \__cchess_pieces_construct:
            }

          \bool_if:NF \g__cchess_draft_bool
            {
              % æž„å»ºæ£‹ç›˜
              \__cchess_board_option_if_in:nT { #1 }
                {
                  \__cchess_board_construct:
                }
              % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
              \__cchess_piece_option_if_in:nT { #1 }
                {
                  \__cchess_pieces_construct:
                }
            }
        }
      \__cchess_manual_output:n { #2 }
    \group_end:
  }

% æ£‹å­å­—ç¬¦å¤ä½
\NewDocumentCommand{\resetpiece}{}
  {
    % å®šä¹‰æ£‹å­å­—ç¬¦å¸¸é‡
    \clist_map_inline:nn
      {
        { K } { å¸¥ }, % å¸¥\__cchess_symbol:n {"5E25}
        { A } { ä»• }, % ä»•\__cchess_symbol:n {"4ED5}
        { E } { ç›¸ }, % ç›¸\__cchess_symbol:n {"76F8}
        { B } { ç›¸ }, % ç›¸\__cchess_symbol:n {"76F8}
        { H } { é©¬ }, % é©¬\__cchess_symbol:n {"9A6C}
        { N } { é©¬ }, % é©¬\__cchess_symbol:n {"9A6C}
        { R } { è½¦ }, % è½¦\__cchess_symbol:n {"8F66}
        { C } { ç&nbsp;² }, % ç&nbsp;²\__cchess_symbol:n {"7832}
        { P } { å…µ }, % å…µ\__cchess_symbol:n {"5175}
        { k } { å°‡ }, % å°‡\__cchess_symbol:n {"5C07}
        { a } { å£« }, % å£«\__cchess_symbol:n {"58EB}
        { e } { è±¡ }, % è±¡\__cchess_symbol:n {"8C61}
        { b } { è±¡ }, % è±¡\__cchess_symbol:n {"8C61}
        { h } { é¦¬ }, % é¦¬\__cchess_symbol:n {"99AC}
        { n } { é¦¬ }, % é¦¬\__cchess_symbol:n {"99AC}
        { r } { è»Š }, % è»Š\__cchess_symbol:n {"8ECA}
        { c } { ç‚® }, % ç‚®\__cchess_symbol:n {"70AE}
        { p } { å’ }, % å’\__cchess_symbol:n {"5352}
      }
      { \__cchess_piece_char_setup:nn ##1 }

    \bool_if:NF \g__cchess_draft_bool
      {
        % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
        \__cchess_pieces_construct:
      }
  }

% æ£‹å­å­—ç¬¦è®¾ç½®å‘½ä»¤
% #1 æ£‹å­ç¼–å·åŠå­—ç¬¦
% K=å¸…,A=ä»•,B/E=ç›¸,R=è½¦,C=ç&nbsp;²,N/H=é©¬,P=å…µ
% k=å°†,a=å£«,b/e=è±¡,r=è»Š,c=ç‚®,n/h=é¦¬,p=å’
\NewDocumentCommand{\piecechar}{ m m }
  {
    \__cchess_piece_char_setup:nn { #1 } { #2 }

    \bool_if:NF \g__cchess_draft_bool
      {
        % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
        \__cchess_pieces_construct:
      }
  }

% æ‰“è°±çŽ¯å¢ƒåˆå§‹åŒ–(ä»…ç”¨äºŽsetcchessmançŽ¯å¢ƒä¸­)
% #1 æ£‹å­ä½ç½®åˆ—è¡¨
%    çº¢æ£‹ï¼šK=å¸…,A=ä»•,E/B=ç›¸,R=è½¦,C=ç&nbsp;²,N/H=é©¬,P=å…µ,
%    é»‘æ£‹ï¼šk=å°†,a=å£«,e/b=è±¡,r=è»Š,c=ç‚®,n/h=é¦¬,p=å’
%    æ¨ªå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8)
%    çºµå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8),j(9)
\NewDocumentCommand{\init}{ m }
  {
    % ä¸´æ—¶clist
    \clist_set:Nn \l_tmpa_clist { #1 }

    % æ›¿æ¢å&nbsp;ä½ç›’å­å†…å®¹
    \clist_map_inline:Nn \l_tmpa_clist
      { \__cchess_piece_replace_handle:nn  ##1 }
  }

% æ‰“è°±çŽ¯å¢ƒä¸­çš„æ£‹å­å¸ƒç½®å‘½ä»¤(ä»…ç”¨äºŽsetcchessmançŽ¯å¢ƒä¸­)
% #1 æ£‹å­ä½ç½®
% #2 æ£‹å­ä½ç½®åˆ—è¡¨
%    çº¢æ£‹ï¼šK=å¸…,A=ä»•,E/B=ç›¸,R=è½¦,C=ç&nbsp;²,N/H=é©¬,P=å…µ,
%    é»‘æ£‹ï¼šk=å°†,a=å£«,e/b=è±¡,r=è»Š,c=ç‚®,n/h=é¦¬,p=å’
%    æ¨ªå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8)
%    çºµå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8),j(9)
\NewDocumentCommand{\set}{ m m }
  {
    \__cchess_piece_replace_handle:nn { #1 } { #2 }
  }

% åˆ&nbsp;é™¤æ‰“è°±çŽ¯å¢ƒä¸­çš„æ£‹å­(ä»…ç”¨äºŽsetcchessmançŽ¯å¢ƒä¸­)
% #1 æ£‹å­ä½ç½®åˆ—è¡¨
%    æ¨ªå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8)
%    çºµå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8),j(9)
\NewDocumentCommand{\del}{ m }
  {
    \__cchess_piece_remove_handle:n { #1 }
  }

% ç§»åŠ¨æ‰“è°±çŽ¯å¢ƒä¸­çš„æ£‹å­(ä»…ç”¨äºŽsetcchessmançŽ¯å¢ƒä¸­)
% #1 æ£‹å­åç§°(å•ä¸ªè‹±æ–‡å­—æ¯)
% #2 æ£‹å­å½“å‰ä½ç½®
% #3 æ£‹å­ç›®çš„ä½ç½®
%    çº¢æ£‹ï¼šK=å¸…,A=ä»•,E/B=ç›¸,R=è½¦,C=ç&nbsp;²,N/H=é©¬,P=å…µ,
%    é»‘æ£‹ï¼šk=å°†,a=å£«,e/b=è±¡,r=è»Š,c=ç‚®,n/h=é¦¬,p=å’
%    æ¨ªå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8)
%    çºµå‘å®šä½: a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8),j(9)
\NewDocumentCommand{\mov}{ m m m }
  {
    \__cchess_piece_move_handle:nnn { #1 } { #2 } { #3 }
  }

% æ‰“è°±æŽ’ç‰ˆçŽ¯å¢ƒç”¨æˆ·æŽ¥å£
% #1 æ£‹ç›˜ç±»åž‹ã€æ£‹å­ç±»åž‹ç­‰å¤–è§‚é€‰é¡¹
\NewDocumentEnvironment{ setcchessman }{ o +b }
  {
    \group_begin:
      \bool_set_false:N  \l__cchess_with_setman_bool

      % è®¾ç½®é€‰é¡¹
      \IfNoValueF { #1}
        {
          \keys_set:nn { cchess } { #1 }

          % æœ‰draftå‚æ•°ï¼Œéœ€è¦é‡æž„æ£‹å­å’Œæ£‹ç›˜
          \tl_if_in:nnT { #1 } { draft }
            {
              % æž„å»ºæ£‹ç›˜
              \__cchess_board_construct:
              % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
              \__cchess_pieces_construct:
            }

          \bool_if:NF \g__cchess_draft_bool
            {
              % æž„å»ºæ£‹ç›˜
              \__cchess_board_option_if_in:nT { #1 }
                {
                  \__cchess_board_construct:
                }
              % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
              \__cchess_piece_option_if_in:nT { #1 }
                {
                  \__cchess_pieces_construct:
                }
            }
        }
      \__cchess_setcchessman_pre_setup:n { #2 }
  }{
      \__cchess_setcchessman_post_setup:
    \group_end:
  }

% æ‰“è°±æŽ’ç‰ˆæ˜Ÿå·çŽ¯å¢ƒç”¨æˆ·æŽ¥å£ï¼Œç”¨äºŽåŒæ—¶è¾“å‡ºæ£‹è°±æè¿°
% #1 æ£‹ç›˜ç±»åž‹ã€æ£‹å­ç±»åž‹ç­‰å¤–è§‚é€‰é¡¹
\NewDocumentEnvironment{ setcchessman* }{ o +b }
  {
    \group_begin:
      \bool_set_true:N  \l__cchess_with_setman_bool
      % è®¾ç½®é€‰é¡¹
      \keys_set:nn { cchess } { #1 }
      \__cchess_setcchessman_pre_setup:n { #2 }
  }{
      \__cchess_setcchessman_post_setup:
    \group_end:
  }

% æ‰“è°±æ£‹è°±è¾“å‡ºç”¨æˆ·æŽ¥å£
% #1 æ¯è¡Œè¾“å‡ºæ­¥æ•°
% #2 æ£‹è°±äº¤å‰å¼•ç”¨label
% å‚è€ƒé›¾æœˆçš„å›žå¤ï¼šhttps://ask.latexstudio.net/ask/question/7430.html
\NewDocumentCommand{\printman}{ O{} &gt;{\TrimSpaces} m } % åŽ»æŽ‰ä¸¤ä¾§ç©ºæ&nbsp;¼
  {
    \group_begin:
      % è®¾ç½®é€‰é¡¹
      \keys_set:nn { cchess } { #1 }
      \__cchess_setman_print:n { #2 }
    \group_end:
  }

% æ£‹å­è¾“å‡ºç”¨æˆ·æŽ¥å£
% #1 æ£‹å­å­—ä½“å­—å·
% #2 æ£‹å­ç¼–ç&nbsp;
%    çº¢æ£‹ï¼šK=å¸…,A=ä»•,E/B=ç›¸,R=è½¦,C=ç&nbsp;²,N/H=é©¬,P=å…µ,
%    é»‘æ£‹ï¼šk=å°†,a=å£«,e/b=è±¡,r=è»Š,c=ç‚®,n/h=é¦¬,p=å’
\NewDocumentCommand{\getpiece}{ O{\normalsize} m }
  {
    \group_begin:
      \__cchess_getpiece_handle:nn {#1} { #2 }
    \group_end:
  }

% ==========æ£‹å­å­—ç¬¦å¸¸é‡å®šä¹‰=====================
% è¯»å–ç¬¦å·
\cs_new:Npn \__cchess_symbol:n #1
  {
    #1
    % \tex_char:D #1
    % \scan_stop:
  }

% æ£‹å­ç¬¦å·å®šä¹‰
\cs_new_protected:Npn \__cchess_piece_define:nn #1#2
  {
    \tl_const:cn { c__cchess_ #1 _tl } { \__cchess_symbol:n { #2 } }
  }

% ==========å˜é‡å®šä¹‰=====================
% ç»˜åˆ¶æ£‹ç›˜æ—¶æ˜¯å¦å¸¦æœ‰æ£‹å­æ&nbsp;‡å¿—
\bool_new:N   \l__cchess_board_pieces_bool
\bool_new:N   \l__cchess_with_setman_bool
\bool_new:N   \g__cchess_draft_bool

% æ£‹å­å®¹å™¨
% å½“å‰ä¸­å›½è±¡æ£‹ä¸»æµè½¯ä»¶çš„æ£‹å­ä»£ç&nbsp;ï¼Œå¤šæ²¿ç”¨:
% K  A  B  N  R  C  P
% å¸… ä»• ç›¸ é©¬ è½¦ ç‚® å…µ
% ï¼ˆçº¢æ–¹ç”¨å¤§å†™å­—æ¯ï¼Œé»‘æ–¹å°å†™ï¼‰
% å‡ºäºŽå¯¹å›½é™…è±¡æ£‹æ£‹æ‰‹æ„è¯†ä¹&nbsp;æƒ¯çš„å…¼å®¹æ€§è®¾è®¡
% ç›¸ B ï¼Œä¹Ÿå¯å…¼å®¹ä½¿ç”¨ Eï¼Œ
% é©¬Nï¼Œ ä¹Ÿå¯å…¼å®¹ä½¿ç”¨ H ä»£æ›¿
% åœ¨æ­¤ï¼Œä¸ºå…¼å®¹æ€§è€ƒè™‘ä½¿ç”¨B/EåŒæ—¶è¡¨ç¤ºç›¸ï¼Œä½¿ç”¨H/NåŒæ—¶è¡¨ç¤ºé©¬
% åœ¨ä½¿ç”¨æ—¶ï¼Œå¯ä»¥ä»»æ„é€‰æ‹©ä¹&nbsp;æƒ¯çš„åç§°

% åˆ¤æ–­çº¢é»‘æ£‹å­è‹±æ–‡å•å­—æ¯åç§°çš„æ­£åˆ™è¡¨è¾¾å¼
\regex_new:N \l__capital_regex
\regex_set:Nn \l__capital_regex { [KAEBRCHNP] }

% æ£‹å­è‹±æ–‡å•å­—æ¯åç§°åˆ—è¡¨
\clist_const:Nn \c__cchess_pieces_name_clist { K,A,E,B,R,C,H,N,P,k,a,e,b,r,c,h,n,p }
\msg_new:nnn { cchess } { piecename-exists } { The~ piece~ name~ `#1~ not~ exists. }

% å®šä¹‰æ£‹å­å­—ç¬¦å¸¸é‡
% æ³¨æ„ç›¸å’Œé©¬åˆ†åˆ«ç”¨ä¸¤ä¸ªç¬¦å·ä»¥é€‚é…ä¸åŒä¹&nbsp;æƒ¯
\clist_map_inline:nn
  {
    { K } { å¸¥ }, % å¸¥"5E25
    { A } { ä»• }, % ä»•"4ED5
    { E } { ç›¸ }, % ç›¸"76F8
    { B } { ç›¸ }, % ç›¸"76F8
    { H } { é©¬ }, % é©¬"9A6C
    { N } { é©¬ }, % é©¬"9A6C
    { R } { è½¦ }, % è½¦"8F66
    { C } { ç&nbsp;² }, % ç&nbsp;²"7832
    { P } { å…µ }, % å…µ"5175
    { k } { å°‡ }, % å°‡"5C07
    { a } { å£« }, % å£«"58EB
    { e } { è±¡ }, % è±¡"8C61
    { b } { è±¡ }, % è±¡"8C61
    { h } { é¦¬ }, % é¦¬"99AC
    { n } { é¦¬ }, % é¦¬"99AC
    { r } { è»Š }, % è»Š"8ECA
    { c } { ç‚® }, % ç‚®"70AE
    { p } { å’ }, % å’"5352
  }
  { \__cchess_piece_define:nn #1 }

% å®šä¹‰æ£‹å­ç¼–ç&nbsp;ä¸Žå­—ç¬¦å¯¹ç…§å±žæ€§è¡¨
\prop_new:N \c__cchess_board_pieces_alph_name_prop
\clist_map_inline:Nn \c__cchess_pieces_name_clist
  {
    \prop_put:NnV \c__cchess_board_pieces_alph_name_prop
      { #1 } { \use:c { c__cchess_ #1 _tl } }
  }

% åœ¨æ£‹å­ç¼–ç&nbsp;åˆ—è¡¨ä¸­æ·»åŠ&nbsp;zè¡¨ç¤ºç©ºæ£‹å­
\clist_push:Nn \c__cchess_pieces_name_clist { z }

% å®šä¹‰æ£‹å­ç›’å­å®¹å™¨
\clist_map_inline:Nn \c__cchess_pieces_name_clist
  {
    \coffin_new:c { l__cchess_piece_ #1 _coffin }
  }
% å°†ç©ºæ£‹å­ç›’å­å®¹å™¨ç½®ç©º
\hcoffin_gset:Nn \l__cchess_piece_z_coffin { \phantom{a} }

% æ£‹ç›˜ç›’å­å®¹å™¨
\coffin_new:N \l__cchess_board_coffin
% æ£‹ç›˜èƒŒæ™¯ç›’å­å®¹å™¨
\coffin_new:N \l__cchess_board_background_coffin

% æ£‹è°±å®¹å™¨
\coffin_new:N \l__cchess_manual_coffin

% åˆ¤æ–­æ˜¯å¦ä¸ºå­—æ¯ä½ç½®çš„æ­£åˆ™è¡¨è¾¾å¼
\regex_new:N \l__alph_regex
\regex_set:Nn \l__alph_regex { [a-j] }

% æ£‹å­ä½ç½®å­—æ¯ä¸Žæ•°å­—å¯¹åº”å…³ç³»
\prop_const_from_keyval:Nn \c__cchess_board_pos_alph_num_prop
  {
    a = 0, b = 1, c = 2 , d = 3, e = 4,
    f = 5, g = 6, h = 7, i = 8, j = 9
  }

\coffin_new:N \l__cchess_board_pieces_pos_coffin

% åˆ¤æ–­æ˜¯å¦ä¸ºæ•°å€¼ä½ç½®çš„æ­£åˆ™è¡¨è¾¾å¼
\regex_new:N \l__digit_regex
\regex_set:Nn \l__digit_regex { [0-9] }

% æ£‹å­ä½ç½®æ•°å­—ä¸Žå­—æ¯å¯¹åº”å…³ç³»
\prop_const_from_keyval:Nn \c__cchess_board_pos_num_alph_prop
  {
    0 = a, 1 = b, 2 = c, 3 = d, 4 = e,
    5 = f, 6 = g, 7 = h, 8 = i, 9 = j
  }

% åˆ¤æ–­æ˜¯æ¨ªå‘ä½ç½®åˆæ³•æ€§çš„åˆ—è¡¨
\clist_const:Nn \c__cchess_pos_x_index_clist
  { a,b,c,d,e,f,g,h,i,0,1,2,3,4,5,6,7,8 }
\msg_new:nnn { cchess } { posx-exists } { The~ x~ index~ `#1~ not~ exists. }
% åˆ¤æ–­æ˜¯çºµå‘ä½ç½®åˆæ³•æ€§çš„åˆ—è¡¨
\clist_const:Nn \c__cchess_pos_y_index_clist
  { a,b,c,d,e,f,g,h,i,j,0,1,2,3,4,5,6,7,8,9 }
\msg_new:nnn { cchess } { posy-exists } { The~ y~ index~ `#1~ not~ exists. }

% æ£‹å­å&nbsp;ä½ç›’å­å®¹å™¨
\clist_const:Nn \c__cchess_board_pos_x_clist
  { a,b,c,d,e,f,g,h,i }
\clist_const:Nn \c__cchess_board_pos_y_clist
  { a,b,c,d,e,f,g,h,i,j }
\clist_map_inline:Nn \c__cchess_board_pos_x_clist
  {
    \clist_map_inline:Nn \c__cchess_board_pos_y_clist
      {
        \coffin_new:c { l__cchess_board_piece_ #1 _ ##1 _coffin }
        \hcoffin_gset:cn { l__cchess_board_piece_ #1 _ ##1 _coffin }
          { \phantom{a} }
      }
  }
\coffin_new:N \l__cchess_board_piece_z_coffin
\hcoffin_gset:Nn \l__cchess_board_piece_z_coffin { \phantom{a} }

% çº¢æ–¹æ£‹ç›˜åæ&nbsp;‡å­—æ¯ä¸Žçº¢æ£‹ç«–çº¿æ&nbsp;‡ä½å¯¹åº”å…³ç³»
\prop_const_from_keyval:Nn \c__cchess_board_red_x_idx_prop
  {
    a = ä¹, b = å…«, c = ä¸ƒ , d = å…­, e = äº”,
    f = å››, g = ä¸‰, h = äºŒ, i = ä¸€
  }

% é»‘æ–¹æ£‹ç›˜åæ&nbsp;‡å­—æ¯ä¸Žé»‘æ£‹ç«–çº¿æ&nbsp;‡ä½å¯¹åº”å…³ç³»
\prop_const_from_keyval:Nn \c__cchess_board_black_x_idx_prop
  {
    a = 1, b = 2, c = 3 , d = 4, e = 5,
    f = 6, g = 7, h = 8, i = 9
  }

% è‹±æ–‡æ•°å­—ä¸Žä¸­æ–‡æ•°å­—çš„å¯¹åº”å…³ç³»
\prop_const_from_keyval:Nn \c__cchess_board_pos_arabic_zh_prop
  {
    0 = ã€‡, 1 = ä¸€, 2 = äºŒ, 3 = ä¸‰, 4 = å››,
    5 = äº”, 6 = å…­, 7 = ä¸ƒ, 8 = å…«, 9 = ä¹
  }

% æ£‹è°±è®°å½•åˆ—è¡¨(å¦‚è½¦ä¸€è¿›äºŒç­‰)
\clist_new:N \l__cchess_manual_clist

% æ£‹å­å¤–æ¡†ç›’å­å®¹å™¨
\coffin_new:N \l__cchess_box_coffin
% æ£‹å­ç›’å­å®¹å™¨
\coffin_new:N \l__cchess_piece_coffin
% æ¥šæ²³æ±‰ç•Œç›’å­å®¹å™¨
\coffin_new:N \l__cchess_char_a_coffin
\coffin_new:N \l__cchess_char_b_coffin
\coffin_new:N \l__cchess_char_c_coffin
\coffin_new:N \l__cchess_char_d_coffin
% ä¸´æ—¶ç›’å­å®¹å™¨
\coffin_new:N \l__cchess_tmpa_coffin
\coffin_new:N \l__cchess_tmpb_coffin
\coffin_new:N \l__cchess_tmpc_coffin
\coffin_new:N \l__cchess_tmpd_coffin

\clist_set:Nn \l_tmpa_clist { a,b,c,d }
\clist_map_inline:Nn \l_tmpa_clist
  {
    \coffin_new:c { l_char_tmp #1 _coffin }
  }

% æ£‹å­ç±»åž‹
\tl_new:N     \l__cchess_piece_box_type_tl
% æ£‹å­ç±»åž‹åˆ—è¡¨
\clist_new:N  \g__cchess_piece_box_list_clist
% æ£‹ç›˜ç±»åž‹
\tl_new:N     \l__cchess_board_type_tl
% æ£‹ç›˜ç±»åž‹åˆ—è¡¨
\clist_new:N  \g__cchess_board_list_clist

% ç¼©æ”¾æ–¹å¼
\tl_new:N     \l__cchess_resize_method_tl
% ç¼©æ”¾æ–¹å¼åˆ—è¡¨
\clist_new:N  \g__cchess_resize_method_clist

% æ£‹è°±è¾“å‡ºå®½åº¦
\dim_new:N    \l__cchess_manual_width_dim
% æ£‹è°±è¾“å‡ºé«˜åº¦
\dim_new:N    \l__cchess_manual_height_dim

% æ£‹ç›˜å®½åº¦
\dim_new:N    \l__cchess_board_width_dim
% æ£‹ç›˜é«˜åº¦
\dim_new:N    \l__cchess_board_height_dim

% æ£‹ç›˜çº¿çº¿å®½
\dim_new:N    \l__cchess_board_linewidth_dim
% è¾…çº¿çº¿å®½
\dim_new:N    \l__cchess_cross_linewidth_dim
% è¾…çº¿é—´è·
\dim_new:N    \l__cchess_cross_sep_dim
% æ£‹å­å­—ç¬¦æ­£æ–¹å½¢å¤–æŽ¥åœ†åŠå¾„
\dim_new:N    \l__cchess_piece_box_radius_dim
% æ£‹å­å¤–æ¡†çº¿çº¿å®½
\dim_new:N    \l__cchess_box_linewidth_dim

% æ£‹ç›˜æ&nbsp;¼å­å°ºå¯¸
\dim_new:N    \gridsize
% æ£‹å­æ•´ä½“å°ºå¯¸
\dim_new:N    \piecesize
% æ£‹å­å­—ç¬¦åŒ…å›´ç›’å°ºå¯¸
\dim_new:N    \charboxsize
% æ£‹å­å­—ç¬¦åŒ…å›´ç›’å°ºå¯¸åŠé•¿
\dim_new:N    \semicharboxsize

% ä¸´æ—¶å°ºå¯¸å˜é‡
\dim_new:N    \l__cchess_tmpa_dim
\dim_new:N    \l__cchess_tmpb_dim
\dim_new:N    \l__cchess_tmpc_dim
\dim_new:N    \l__cchess_tmpd_dim

% æ£‹å­å­—ç¬¦æ&nbsp;¼å¼
\tl_new:N    \l__cchess_piece_char_format_tl
% æ£‹ç›˜èƒŒæ™¯å›¾ç‰‡åç§°
\tl_new:N    \l__cchess_board_background_tl
% æ£‹å­å­—ç¬¦å­—å½¢ç±»åž‹(å®žçº¿ã€è™šçº¿ç­‰)
\int_new:N   \l__cchess_charstroke_type_int

% æ‰“è°±çŽ¯å¢ƒæ£‹è°±æ&nbsp;‡ç­¾
\tl_new:N    \l__cchess_setman_label_tl
% æ‰“è°±ç»“æžœæ¯è¡Œæ£‹è°±æ­¥æ•°
\int_new:N   \l__cchess_mans_per_line_int

% æ‰“è°±çŽ¯å¢ƒç”¨è®¡æ•°å™¨
\newcounter{setman}

% å¢žåŠ&nbsp;ä¸¤ä¸ªä¸´æ—¶intå˜é‡
\int_new:N \l_tmpc_int
\int_new:N \l_tmpd_int
\int_new:N \l_tmpe_int
% å¢žåŠ&nbsp;ä¸¤ä¸ªä¸´æ—¶tlå˜é‡
\tl_new:N \l_tmpc_tl
\tl_new:N \l_tmpd_tl
\tl_new:N \l_tmpe_tl

% ============å®åŒ…é€‰é¡¹=================
\keys_define:nn { cchess }
  {
    draft .choice:,
    draft / true  .code:n = { \bool_set_true:N  \g__cchess_draft_bool },
    draft / false .code:n = { \bool_set_false:N \g__cchess_draft_bool },
    draft .default:n = true,
    draft .initial:n = false,

    unknown .code:n = { \msg_error:nn { cchess } { unknown-option } }
  }

% å°†æ–‡æ¡£ç±»é€‰é¡¹ä¼&nbsp;ç»™cchess
% \ProcessKeysOptions { cchess }

% æ£‹å­ç›’å­ç”±l3drawå®žçŽ°ï¼Œ
% æ£‹å­å¤–å›´ç›’å­åŠç¼©æ”¾è®¾è®¡æ€è·¯æ¥è‡ªzitieå®åŒ…
% (\url{https://www.ctan.org/pkg/zitie})ã€‚

% =============é¢œè‰²å¤„ç†å‡½æ•°=============
% å¡«å……è‰²è¾…åŠ©å‡½æ•°
\cs_new_nopar:Nn \__cchess_aux_color_boxfill:
  { }

% é¢œè‰²å‘½åå‡½æ•°
% #1 é¢œè‰²åç§°
% #2 é¢œè‰²è¡¨è¾¾å¼
\cs_set_nopar:Npn \__cchess_color_select:nn #1#2
  {
    \color_set:nn {#1} {#2}
  }
\cs_generate_variant:Nn \__cchess_color_select:nn {nx}

% é¢œè‰²å‘½åå‡½æ•°
% #1 é¢œè‰²åç§°
% #2 é¢œè‰²ç©ºé—´
% #3 é¢œè‰²åˆ†é‡å€¼
\cs_set_nopar:Npn \__cchess_color_select:nnn #1#2#3
  {
    \color_set:nnn {#1} {#2} {#3}
  }
\cs_generate_variant:Nn \__cchess_color_select:nnn {nnx}

% =============åŸºç¡€å°ºå¯¸è®¡ç®—å‡½æ•°=============
% ç›’å­å®¹å™¨æ€»é«˜åº¦è®¡ç®—å‡½æ•°
\cs_new_nopar:Npn \__cchess_coffin_ht_plus_dp:N #1
  {
    \coffin_ht:N #1 + \coffin_dp:N #1
  }

% è®¡ç®—å¤–æ¡†å¤§å°(å¤–æŽ¥æ­£æ–¹å½¢è¾¹é•¿å’Œå¤–æŽ¥åœ†åŠå¾„)
\cs_new:Npn \__cchess_calc_piece_box_size:
  {
    % è®¾ç½®è®¡ç®—åŸºç¡€ç›’å­
    \hbox_set:Nn \l_tmpa_box { xx }

    % ç›’å­å®½åº¦
    \dim_set:Nn \l_tmpa_dim
      {
        \box_wd:N \l_tmpa_box
      }
    % ç›’å­é«˜åº¦
    \dim_set:Nn \l_tmpb_dim
      {
        \box_ht_plus_dp:N \l_tmpa_box
      }

    % æ­£æ–¹å½¢è¾¹é•¿
    \dim_compare:nNnTF \l_tmpa_dim &gt; \l_tmpb_dim
      {
        \dim_gset_eq:NN \charboxsize \l_tmpa_dim
      }
      {
        \dim_gset_eq:NN \charboxsize \l_tmpb_dim
      }

    \dim_gadd:Nn \charboxsize { 2pt }

    % åŒ…å›´ç›’åŠé•¿
    \dim_gset:Nn \semicharboxsize
      {
        \fp_to_dim:n { \fp_eval:n { \charboxsize / 2 } }
        % \charboxsize / 2
      }

    % å¤–æŽ¥åœ†åŠå¾„
    \dim_gset:Nn \l__cchess_piece_box_radius_dim
      {
        \fp_to_dim:n { \fp_eval:n { \charboxsize * sqrt(2)/ 2 } }
        % \fp_to_dim:n { \fp_eval:n { \charboxsize * 0.707106781 } }
      }
  }

% =============æž„é€&nbsp;æ£‹å­å‡½æ•°=============
% å­—ç¬¦ç›’å­æž„é€&nbsp;ç±»åž‹å‡½æ•°åç§°ç”Ÿæˆå‡½æ•°
% #1 ç¼©æ”¾æ¯”ä¾‹
\cs_new_nopar:Npn \__cchess_piece_box_type:n #1
  {
    __cchess_piece_box_construct_type_ #1 :n
  }
% å­—ç¬¦ç›’å­æž„é€&nbsp;ç±»åž‹å‡½æ•°åç§°å‘½ä»¤ç”Ÿæˆå‡½æ•°
% #1 ç¼©æ”¾æ¯”ä¾‹
\cs_new_nopar:Npn \__cchess_piece_box_type_c:n #1
  {
    \use:c { __cchess_piece_box_construct_type_ #1 :n }
  }

% å­—ç¬¦ç›’å­æž„é€&nbsp;ç±»åž‹å‡½æ•°å†…éƒ¨ç”Ÿæˆå™¨å‡½æ•°
% #1 ç±»åž‹åç§°
\cs_new:Npn \__cchess_new_piece_box_private_construct:nn #1
  {
    % ç±»ä¼¼\cs_new:cn __cchess_piece_box_construct_type_none:n
    \cs_new:cn { \__cchess_piece_box_type:n {#1} }
  }
\cs_generate_variant:Nn \__cchess_new_piece_box_private_construct:nn { V }
\cs_generate_variant:Nn \__cchess_new_piece_box_private_construct:nn { x }

% å­—ç¬¦ç›’å­æž„é€&nbsp;ç±»åž‹å‡½æ•°ç”Ÿæˆå™¨å‡½æ•°
% #1 ç±»åž‹åç§°
\cs_new:Npn \__cchess_new_piece_box_construct:nn #1
  {
    % å°†ç±»åž‹åç§°è®°å…¥clist
    \clist_put_right:Nn \g__cchess_piece_box_list_clist {#1}
    % ç±»ä¼¼\cs_new:cn __cchess_piece_box_construct_type_none:n
    \cs_new:cn { \__cchess_piece_box_type:n {#1} }
  }
\cs_generate_variant:Nn \__cchess_new_piece_box_construct:nn { V }
\cs_generate_variant:Nn \__cchess_new_piece_box_construct:nn { x }

% å®šä¹‰å­—ç¬¦è¾¹æ¡†ç›’å­ç±»åž‹å†…éƒ¨å‡½æ•°
% æ—&nbsp;è¾¹æ¡†
\__cchess_new_piece_box_construct:nn { none } { }

% åº•å±‚å¡«å……å¤–æŽ¥åœ†
\__cchess_new_piece_box_private_construct:nn { __outerlowerfilledcircle }
  {
    \draw_scope_begin:
      \color_fill:n { lowerbgboxfill }
      \draw_path_circle:nn { \semicharboxsize, \semicharboxsize }
        { \l__cchess_piece_box_radius_dim*#1 }
      \draw_path_use_clear:n { fill }
    \draw_scope_end:
  }

% é¡¶å±‚å¡«å……å¤–æŽ¥åœ†
\__cchess_new_piece_box_private_construct:nn { __outerupperfilledcircle }
  {
    \draw_scope_begin:
      \color_fill:n { upperbgboxfill }
      \draw_path_circle:nn { \semicharboxsize, \semicharboxsize }
        { \l__cchess_piece_box_radius_dim*#1 }
      \draw_path_use_clear:n { fill }
    \draw_scope_end:
  }

% åœ†çŽ¯å±‚å¡«å……å¤–æŽ¥åœ†
\__cchess_new_piece_box_private_construct:nn { __outerdonutfilledcircle }
  {
    \draw_scope_begin:
      \color_fill:n { donutboxfill }
      \draw_path_circle:nn { \semicharboxsize, \semicharboxsize }
        { \l__cchess_piece_box_radius_dim*#1 }
      \draw_path_use_clear:n { fill }
    \draw_scope_end:
  }

% é˜´å½±å¡«å……å¤–æŽ¥åœ†
\__cchess_new_piece_box_private_construct:nn { __outershadowfilledcircle }
  {
    \draw_scope_begin:
      \color_fill:n { shadowboxfill   }
      \draw_transform_shift:n { \charboxsize*0.1, -\charboxsize*0.1 }
      \draw_path_circle:nn { \semicharboxsize, \semicharboxsize }
        { \l__cchess_piece_box_radius_dim*#1 }
      \draw_path_use_clear:n { fill }
    \draw_scope_end:
  }

% å¤–æŽ¥åœ†è¾¹æ¡†
\__cchess_new_piece_box_private_construct:nn { __outercirclebox }
  {
    \draw_scope_begin:
      \color_stroke:n { cchesspieceboxcolor }
      \draw_path_circle:nn { \semicharboxsize, \semicharboxsize }
        { \l__cchess_piece_box_radius_dim*#1 }
      \draw_path_use_clear:n { stroke }
    \draw_scope_end:
  }

% å¡«å……å¤–æŽ¥åœ†å&nbsp;åŠ&nbsp;å¤–æŽ¥åœ†è¾¹æ¡†
\__cchess_new_piece_box_construct:nn { o }
  {
    \__cchess_piece_box_type_c:n { __outerupperfilledcircle } {0.82}
    \__cchess_piece_box_type_c:n { __outercirclebox } {0.82}
  }

% å¡«å……å¤–æŽ¥åœ†å&nbsp;åŠ&nbsp;åŒå¿ƒ82%å¤–æŽ¥åœ†è¾¹æ¡†
\__cchess_new_piece_box_construct:nn { oo }
  {
    \__cchess_piece_box_type_c:n { __outerupperfilledcircle } {#1}
    \__cchess_piece_box_type_c:n { __outercirclebox } {#1}
    \__cchess_piece_box_type_c:n { __outercirclebox } {0.82}
  }

% 3åŒå¿ƒåœ†å&nbsp;åŠ&nbsp;(é˜´å½±)
\__cchess_new_piece_box_construct:nn { ooo }
  {
    % ç»˜åˆ¶å¡«å……å¤–æŽ¥åœ†é˜´å½±
    \__cchess_piece_box_type_c:n { __outershadowfilledcircle } {1.0}
    % ç»˜åˆ¶å¡«å……å¤–æŽ¥åœ†å¤–åœˆèƒŒæ™¯
    \__cchess_piece_box_type_c:n { __outerlowerfilledcircle } {1.0}
    % ç»˜åˆ¶å¡«å……å¤–æŽ¥è¾¹çŽ¯èƒŒæ™¯
    \__cchess_piece_box_type_c:n { __outerdonutfilledcircle } {0.88}
    % ç»˜åˆ¶å¡«å……å¤–æŽ¥åœ†å†…åœˆèƒŒæ™¯
    \__cchess_piece_box_type_c:n { __outerupperfilledcircle } {0.72}
    % ç»˜åˆ¶åŒè¾¹åˆ»çŽ¯çº¿
    \__cchess_piece_box_type_c:n { __outercirclebox } {0.88}
    \__cchess_piece_box_type_c:n { __outercirclebox } {0.72}
  }

\msg_new:nnn { cchess } { box-exists } { The~ box~ type~ `#1~ not~ exists. }

% =============æž„é€&nbsp;æ£‹ç›˜å‡½æ•°=============
% æ£‹ç›˜éƒ¨ä»¶æž„é€&nbsp;å‡½æ•°å‡½æ•°åç§°ç”Ÿæˆå‡½æ•°
% åç§°ä¸­2ä¸ªå‚æ•°åˆ†åˆ«è¡¨ç¤ºï¼š
% #1 xæ–¹å‘ç¼©æ”¾æ¯”ä¾‹(æš‚æœªä½¿ç”¨, ä¿ç•™å‚æ•°)
% #2 yæ–¹å‘ç¼©æ”¾æ¯”ä¾‹(æš‚æœªä½¿ç”¨, ä¿ç•™å‚æ•°)
\cs_new_nopar:Npn \__cchess_board_type:n #1
  {
    __cchess_board_construct_type_ #1 :nn
  }
% åç§°å‘½ä»¤ä¸­2ä¸ªå‚æ•°åˆ†åˆ«è¡¨ç¤ºï¼š
% #1 xæ–¹å‘ç¼©æ”¾æ¯”ä¾‹(æš‚æœªä½¿ç”¨, ä¿ç•™å‚æ•°)
% #2 yæ–¹å‘ç¼©æ”¾æ¯”ä¾‹(æš‚æœªä½¿ç”¨, ä¿ç•™å‚æ•°)
\cs_new_nopar:Npn \__cchess_board_type_c:n #1
  {
    \use:c { __cchess_board_construct_type_ #1 :nn }
  }

% æ£‹ç›˜ç±»åž‹å‡½æ•°ç”Ÿæˆå™¨å†…éƒ¨å‡½æ•°
% #1 ç±»åž‹åç§°
\cs_new:Npn \__cchess_new_board_private_construct:nn #1
  {
    % ç±»ä¼¼\cs_new:cn __cchess_board_construct_type_none:nn
    \cs_new:cn { \__cchess_board_type:n {#1} }
  }
\cs_generate_variant:Nn \__cchess_new_board_private_construct:nn { V }
\cs_generate_variant:Nn \__cchess_new_board_private_construct:nn { x }

% æ£‹ç›˜ç±»åž‹å‡½æ•°ç”Ÿæˆå™¨å‡½æ•°
% #1 ç±»åž‹åç§°
\cs_new:Npn \__cchess_new_board_construct:nn #1
  {
    % å°†ç±»åž‹åç§°è®°å…¥clist
    \clist_put_right:Nn \g__cchess_board_list_clist {#1}
    % ç±»ä¼¼\cs_new:cn __cchess_board_construct_type_none:nn
    \cs_new:cn { \__cchess_board_type:n {#1} }
  }
\cs_generate_variant:Nn \__cchess_new_board_construct:nn { V }
\cs_generate_variant:Nn \__cchess_new_board_construct:nn { x }

% ç©ºæ£‹ç›˜
\__cchess_new_board_construct:nn { none } { }

% ä»…æ&nbsp;¼å­çº¿åŠéƒ¨æ£‹ç›˜
\__cchess_new_board_private_construct:nn { __semiboard }
  {
    \draw_scope_begin:
      \color_stroke:n { cchessboardlinecolor }
      % ç»˜åˆ¶æ£‹ç›˜ç½‘æ&nbsp;¼
      \draw_path_grid:nnnn { \gridsize } { \gridsize }
        { 0, 0 } { \gridsize * 8, \gridsize * 4 }

      % ç»˜åˆ¶åŠé•¿è¾¹æ&nbsp;¼çº¿
      \draw_path_moveto:n { 0    , \gridsize * 4   }
      \draw_path_lineto:n { 0    , \gridsize * 4.5 }
      \draw_path_moveto:n { \gridsize * 8, \gridsize * 4   }
      \draw_path_lineto:n { \gridsize * 8, \gridsize * 4.5 }

      \draw_path_use_clear:n { stroke }
    \draw_scope_end:
  }

% å…µã€ç‚®4åˆ†ä½æ&nbsp;‡å¿—(å³ä¸Š)
\__cchess_new_board_private_construct:nn { __quaterpos }
  {
    % è®¡ç®—æ&nbsp;‡å¿—é•¿åº¦
    \dim_set:Nn \l_tmpa_dim
      { \fp_to_dim:n { \fp_eval:n { \gridsize * 0.10 } } }

    \draw_scope_begin:
      \color_stroke:n { cchessboardlinecolor }
      \draw_path_scope_begin:
        \draw_linewidth:n { \l__cchess_cross_linewidth_dim }
        \draw_path_moveto:n { 0pt        , \l_tmpa_dim }
        \draw_path_lineto:n { 0pt        , 0pt         }
        \draw_path_lineto:n { \l_tmpa_dim, 0pt         }
        \draw_path_use_clear:n { stroke }
      \draw_path_scope_end:
    \draw_scope_end:
  }

% å…µã€ç‚®å…¨ä½æ&nbsp;‡å¿—
\__cchess_new_board_private_construct:nn { __fullpos }
  {
    \draw_scope_begin:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \l__cchess_cross_sep_dim, \l__cchess_cross_sep_dim }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { -\l__cchess_cross_sep_dim, \l__cchess_cross_sep_dim }
        \draw_transform_rotate:n { 90 }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { -\l__cchess_cross_sep_dim, -\l__cchess_cross_sep_dim }
        \draw_transform_rotate:n { 180 }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \l__cchess_cross_sep_dim, -\l__cchess_cross_sep_dim }
        \draw_transform_rotate:n { 270 }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
    \draw_scope_end:
  }

% å³å‘å…µåŠä½æ&nbsp;‡å¿—
\__cchess_new_board_private_construct:nn { __rightsemipos }
  {
    \draw_scope_begin:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \l__cchess_cross_sep_dim, \l__cchess_cross_sep_dim }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \l__cchess_cross_sep_dim, -\l__cchess_cross_sep_dim }
        \draw_transform_rotate:n { -90 }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
    \draw_scope_end:
  }

% å·¦å‘å…µåŠä½æ&nbsp;‡å¿—
\__cchess_new_board_private_construct:nn { __leftsemipos }
  {
    \draw_scope_begin:
      \draw_path_scope_begin:
        \draw_transform_shift:n { -\l__cchess_cross_sep_dim, \l__cchess_cross_sep_dim }
        \draw_transform_rotate:n { 90 }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { -\l__cchess_cross_sep_dim, -\l__cchess_cross_sep_dim }
        \draw_transform_rotate:n { 180 }
        \__cchess_board_type_c:n { __quaterpos } {#1} {#2}
      \draw_path_scope_end:
    \draw_scope_end:
  }

% å…µã€ç‚®æ&nbsp;‡å¿—(åŠæ£‹ç›˜)
\__cchess_new_board_private_construct:nn { __semipos }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \draw_scope_begin:
          % ç»˜åˆ¶å…µã€ç‚®å®šä½æ&nbsp;‡å¿—
          \clist_map_variable:nNn {{1,2},{7,2},{2,3},{4,3},{6,3}} \l_tmpa_tl
            {
              \clist_set:NV \l_tmpa_clist \l_tmpa_tl
              \dim_set:Nn \l_tmpa_dim
                {
                  \fp_to_dim:n
                    {
                      \fp_eval:n { \gridsize * \clist_item:Nn \l_tmpa_clist { 1 } }
                    }
                }
              \dim_set:Nn \l_tmpb_dim
                {
                  \fp_to_dim:n
                    {
                      \fp_eval:n { \gridsize * \clist_item:Nn \l_tmpa_clist { 2 } }
                    }
                }
              \draw_path_scope_begin:
                \draw_transform_shift:n { \l_tmpa_dim, \l_tmpb_dim }
                \__cchess_board_type_c:n { __fullpos } {#1} {#2}
              \draw_path_scope_end:
            }

          \draw_path_scope_begin:
            \draw_transform_shift:n { 0, \gridsize * 3 }
            \__cchess_board_type_c:n { __rightsemipos } {#1} {#2}
          \draw_path_scope_end:

          \draw_path_scope_begin:
            \draw_transform_shift:n { \gridsize * 8, \gridsize * 3 }
            \__cchess_board_type_c:n { __leftsemipos } {#1} {#2}
          \draw_path_scope_end:

        \draw_scope_end:
      }
    % ä½¿ç”¨ç›’å­å®¹å™¨
    \draw_path_scope_begin:
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
  }

% æ—&nbsp;å…µã€ç‚®æ&nbsp;‡å¿—å…¨æ£‹ç›˜
\__cchess_new_board_private_construct:nn { __semiboardwithpos }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboard } {#1} {#2}
        \__cchess_board_type_c:n { __semipos } {#1} {#2}
      }
    % ä½¿ç”¨ç›’å­å®¹å™¨
    \draw_path_scope_begin:
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
  }

% ä¹å®«å¯¹è§’çº¿
\__cchess_new_board_private_construct:nn { __dguardcross }
  {
    \draw_scope_begin:
      \color_stroke:n { cchessboardlinecolor }
      \draw_path_scope_begin:
        \draw_linewidth:n { \l__cchess_cross_linewidth_dim }
        \draw_transform_shift:n { \gridsize * 3, 0       }

        \draw_path_moveto:n { 0          , \gridsize * 2 }
        \draw_path_lineto:n { \gridsize * 2, 0           }
        \draw_path_moveto:n { 0          , 0           }
        \draw_path_lineto:n { \gridsize * 2, \gridsize * 2 }
        \draw_path_use_clear:n { stroke }
      \draw_path_scope_end:
    \draw_scope_end:
  }

% è±¡ä½è™šçº¿
\__cchess_new_board_private_construct:nn { __elephantcross }
  {
    \draw_scope_begin:
      \color_stroke:n { cchessboardlinecolor }
      \draw_path_scope_begin:
        \draw_linewidth:n { \l__cchess_cross_linewidth_dim }
        \draw_dash_pattern:nn { 0.5mm , 0.5mm , 0.5mm , 0.5mm } { 0cm }
        \draw_path_moveto:n { \gridsize * 2, 0           }
        \draw_path_lineto:n { \gridsize * 6, \gridsize * 4 }
        \draw_path_lineto:n { \gridsize * 8, \gridsize * 2 }
        \draw_path_lineto:n { \gridsize * 6, 0           }
        \draw_path_lineto:n { \gridsize * 2, \gridsize * 4 }
        \draw_path_lineto:n { 0          , \gridsize * 2 }
        \draw_path_lineto:n { \gridsize * 2, 0           }
        \draw_path_use_clear:n { stroke }
      \draw_path_scope_end:
    \draw_scope_end:
  }

% å¸¦ç‚®ã€å…µä½æ&nbsp;‡å¿—å’Œä¹å®«å¯¹è§’çº¿çš„åŠæ£‹ç›˜
\__cchess_new_board_private_construct:nn { __semiboardposdguardcross }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboardwithpos } {#1} {#2}
        \__cchess_board_type_c:n { __dguardcross } {#1} {#2}
      }
    % ä½¿ç”¨ç›’å­å®¹å™¨
    \draw_path_scope_begin:
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
  }

% ä½¿ç”¨ç›’å­å®¹å™¨å‡½æ•°å˜ä½“
\cs_generate_variant:Nn \draw_coffin_use:Nnn { c }

% æž„å»ºæ¥šæ²³æ±‰ç•Œ
\__cchess_new_board_private_construct:nn { __midseptext }
  {

    \color_select:n { cchessboardlinecolor }

    \hcoffin_set:Nn \l_char_tmpa_coffin { æ¥š }
    \hcoffin_set:Nn \l_char_tmpb_coffin { æ²³ }
    \hcoffin_set:Nn \l_char_tmpc_coffin { æ¼¢ }
    \hcoffin_set:Nn \l_char_tmpd_coffin { ç•Œ }

    \clist_map_inline:nn { a, b }
      {
        \coffin_rotate:cn { l_char_tmp ##1 _coffin } { -90 }
      }
    \clist_map_inline:nn { c, d }
      {
        \coffin_rotate:cn { l_char_tmp ##1 _coffin } { 90 }
      }

    % æµ‹é‡ç›’å­å®¹å™¨æ€»é«˜åº¦
    \dim_set:Nn \l_tmpa_dim
      { \__cchess_coffin_ht_plus_dp:N \l_char_tmpa_coffin }

    \dim_set:Nn \l_tmpb_dim
      {
        \fp_to_dim:n { \fp_eval:n { \gridsize * 0.45 } }
      }

    % ç¼©æ”¾ç›’å­å®¹å™¨
    \clist_map_inline:nn { a, b, c, d }
      {
        \coffin_scale:cnn { l_char_tmp ##1 _coffin }
          {
            \dim_ratio:nn { \l_tmpb_dim } { \l_tmpa_dim }
          }{
            \dim_ratio:nn { \l_tmpb_dim } { \l_tmpa_dim }
          }
      }

    % æŽ’ç‰ˆæ–‡å­—
    \draw_scope_begin:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \gridsize * 2, \gridsize * 4.5 }
        \draw_transform_shift:n { -\gridsize / 2, 0pt }
        \draw_coffin_use:cnn { l_char_tmpb_coffin } { hc } { vc }
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \gridsize * 2, \gridsize * 4.5 }
        \draw_transform_shift:n { \gridsize / 2, 0pt }
        \draw_coffin_use:cnn { l_char_tmpa_coffin } { hc } { vc }
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \gridsize * 6, \gridsize * 4.5 }
        \draw_transform_shift:n { -\gridsize / 2, 0pt }
        \draw_coffin_use:cnn { l_char_tmpc_coffin } { hc } { vc }
      \draw_path_scope_end:
      \draw_path_scope_begin:
        \draw_transform_shift:n { \gridsize * 6, \gridsize * 4.5 }
        \draw_transform_shift:n { \gridsize / 2, 0pt }
        \draw_coffin_use:cnn { l_char_tmpd_coffin } { hc } { vc }
      \draw_path_scope_end:
    \draw_scope_end:
  }

% æž„å»ºæ•°å­—æ&nbsp;‡è¯†
\__cchess_new_board_private_construct:nn { __tbnumtext }
  {
    \dim_set:Nn \l__cchess_tmpc_dim
      {
        \fp_to_dim:n { \fp_eval:n { \gridsize * 9 + \gridsize * 0.7 } }
      }
    \dim_set:Nn \l__cchess_tmpd_dim
      {
        \fp_to_dim:n { \fp_eval:n { -\gridsize * 0.7 } }
      }

    \color_select:n { cchessboardlinecolor }

    \clist_set:Nn \l_tmpa_clist { 1,2,3,4,5,6,7,8,9 }
    \clist_set:Nn \l_tmpb_clist { ä¹,å…«,ä¸ƒ,å…­,äº”,å››,ä¸‰,äºŒ,ä¸€ }

    \hcoffin_set:Nn \l_tmpa_coffin { äº” }

    % æµ‹é‡ç›’å­å®¹å™¨æ€»é«˜åº¦
    \dim_set:Nn \l_tmpa_dim
      { \__cchess_coffin_ht_plus_dp:N \l_tmpa_coffin }

    \dim_set:Nn \l_tmpb_dim
      {
        \fp_to_dim:n { \fp_eval:n { \gridsize * 0.25 } }
      }

    \draw_scope_begin:
      \int_set:Nn \l_tmpa_int { 0 }
      \clist_map_inline:Nn \l_tmpa_clist
        {
          \clist_pop:NN \l_tmpb_clist \l_tmpa_tl
          \hcoffin_set:Nn \l_tmpa_coffin { ##1 }
          \hcoffin_set:Nn \l_tmpb_coffin { \l_tmpa_tl }
          \coffin_scale:Nnn \l_tmpa_coffin
            {
              \dim_ratio:nn { \l_tmpb_dim } { \l_tmpa_dim }
            }{
              \dim_ratio:nn { \l_tmpb_dim } { \l_tmpa_dim }
            }
          \coffin_scale:Nnn \l_tmpb_coffin
            {
              \dim_ratio:nn { \l_tmpb_dim } { \l_tmpa_dim }
            }{
              \dim_ratio:nn { \l_tmpb_dim } { \l_tmpa_dim }
            }

          \draw_path_scope_begin:
            \draw_transform_shift:n
              { \gridsize * \l_tmpa_int, \l__cchess_tmpc_dim }
            \draw_coffin_use:Nnn \l_tmpa_coffin { hc } { vc }
          \draw_path_scope_end:

          \draw_path_scope_begin:
            \draw_transform_shift:n
              { \gridsize * \l_tmpa_int, \l__cchess_tmpd_dim }
            \draw_coffin_use:Nnn \l_tmpb_coffin { hc } { vc }
          \draw_path_scope_end:

          \int_incr:N \l_tmpa_int
        }
    \draw_scope_end:
  }

% æ—&nbsp;å…µã€ç‚®æ&nbsp;‡å¿—å…¨æ£‹ç›˜
\__cchess_new_board_private_construct:nn { __none }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboard } {#1} {#2}
      }
    % ä¸‹åŠéƒ¨
    \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }

    % ä¸ŠåŠéƒ¨
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * 8, \gridsize * 9 }
      \draw_transform_rotate:n { 180 }
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
  }

% æ—&nbsp;å…µã€ç‚®æ&nbsp;‡å¿—å…¨æ£‹ç›˜
\__cchess_new_board_construct:nn { x }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboard } {#1} {#2}
        \__cchess_board_type_c:n { __dguardcross } {#1} {#2}
      }
    % ä¸‹åŠéƒ¨
    \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }

    % ä¸ŠåŠéƒ¨
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * 8, \gridsize * 9 }
      \draw_transform_rotate:n { 180 }
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
  }

% æœ‰å…µã€ç‚®æ&nbsp;‡å¿—å…¨æ£‹ç›˜
\__cchess_new_board_construct:nn { x+ }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboardwithpos } {#1} {#2}
        \__cchess_board_type_c:n { __dguardcross } {#1} {#2}
      }
    % ä¸‹åŠéƒ¨
    \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }

    % ä¸ŠåŠéƒ¨
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * 8, \gridsize * 9 }
      \draw_transform_rotate:n { 180 }
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
  }

% æœ‰å…µã€ç‚®æ&nbsp;‡å¿—å…¨æ£‹ç›˜
\__cchess_new_board_construct:nn { x+t }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboardwithpos } {#1} {#2}
        \__cchess_board_type_c:n { __dguardcross } {#1} {#2}
      }
    % ä¸‹åŠéƒ¨
    \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }

    % ä¸ŠåŠéƒ¨
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * 8, \gridsize * 9 }
      \draw_transform_rotate:n { 180 }
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
    \__cchess_board_type_c:n { __midseptext } {#1} {#2}
  }

% æœ‰å…µã€ç‚®æ&nbsp;‡å¿—å…¨æ£‹ç›˜
\__cchess_new_board_construct:nn { x+tn }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboardwithpos } {#1} {#2}
        \__cchess_board_type_c:n { __dguardcross } {#1} {#2}
      }
    % ä¸‹åŠéƒ¨
    \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }

    % ä¸ŠåŠéƒ¨
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * 8, \gridsize * 9 }
      \draw_transform_rotate:n { 180 }
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
    \__cchess_board_type_c:n { __midseptext } {#1} {#2}
    \__cchess_board_type_c:n { __tbnumtext } {#1} {#2}
  }

% æœ‰å…µã€ç‚®æ&nbsp;‡å¿—å’Œè±¡ä½çº¿çš„å…¨æ£‹ç›˜
\__cchess_new_board_construct:nn { x+Xtn }
  {
    \hcoffin_set:Nn \l_tmpa_coffin
      {
        \__cchess_board_type_c:n { __semiboardwithpos } {#1} {#2}
        \__cchess_board_type_c:n { __dguardcross } {#1} {#2}
        \__cchess_board_type_c:n { __elephantcross } {#1} {#2}
      }
    % ä¸‹åŠéƒ¨
    \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }

    % ä¸ŠåŠéƒ¨
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * 8, \gridsize * 9 }
      \draw_transform_rotate:n { 180 }
      \draw_coffin_use:Nnn \l_tmpa_coffin { l } { b }
    \draw_path_scope_end:
    \__cchess_board_type_c:n { __midseptext } {#1} {#2}
    \__cchess_board_type_c:n { __tbnumtext } {#1} {#2}
  }

\msg_new:nnn { cchess } { board-exists } { The~ board~ type~ `#1~ not~ exists. }

% =============ç¼©æ”¾å¤„ç†å‡½æ•°=============
% ç¼©æ”¾ç±»åž‹åç§°ç”Ÿæˆå‡½æ•°
\cs_new_nopar:Npn \__cchess_resize:n #1
  {
    __cchess_processor_resize_ #1 :w
  }

% ç¼©æ”¾ç±»åž‹å‡½æ•°åç§°å‘½ä»¤ç”Ÿæˆå‡½æ•°
\cs_new_nopar:Npn \__cchess_resize_c:n #1
  {
    \use:c
      {
        __cchess_processor_resize_ #1 :w
      }
  }

% ç¼©æ”¾ä»£ç&nbsp;ç”Ÿæˆå‡½æ•°
% #1 dimé•¿åº¦å˜é‡1
% #2 dimé•¿åº¦å˜é‡2
% #3 ç¼©æ”¾ä»£ç&nbsp;1
% #4 ç¼©æ”¾ä»£ç&nbsp;2
% #5 ç¼©æ”¾ä»£ç&nbsp;3
% #6 ç¼©æ”¾ä»£ç&nbsp;4
% å¦‚æžœ #1 &gt; 0  ä¸” #2 &gt; 0 ï¼Œå–#3ä»£ç&nbsp;
% å¦‚æžœ #1 &gt; 0  ä¸” #2 &lt;= 0ï¼Œå–#4ä»£ç&nbsp;
% å¦‚æžœ #1 &lt;= 0 ä¸” #2 &gt; 0 ï¼Œå–#5ä»£ç&nbsp;
% å¦‚æžœ #1 &lt;= 0 ä¸” #2 &lt;= 0ï¼Œå–#6ä»£ç&nbsp;
\cs_new:Npn \__cchess_dim_gezero_dispatch:NNnnnn #1#2 #3#4#5#6
  {
    \dim_compare:nNnTF #1 &gt; \c_zero_dim
      {
        \dim_compare:nNnTF #2 &gt; \c_zero_dim
          { #3 } { #4 }
      }
      {
        \dim_compare:nNnTF #2 &gt; \c_zero_dim
          { #5 } { #6 }
      }
  }

% ç¼©æ”¾ä»£ç&nbsp;ç”Ÿæˆå‡½æ•°(åˆ†åˆ«æŒ‰é«˜å®½ã€é«˜åº¦ã€å®½åº¦æˆ–å®žé™…å°ºå¯¸ç¼©æ”¾)
\cs_new:Npn \__cchess_force_size_dispatch:nnnn % both, height, width, none
  {
    % \dim_show:N \l__cchess_manual_width_dim
    \__cchess_dim_gezero_dispatch:NNnnnn \l__cchess_manual_height_dim
      \l__cchess_manual_width_dim
  }

% æž„é€&nbsp;ç¼©æ”¾ç±»åž‹
\cs_new:Npn \__cchess_new_resize_method:nn #1
  {
    \clist_put_right:Nn \g__cchess_resize_method_clist {#1}
    \cs_new:cpn { \__cchess_resize:n {#1} }
  }

% æ—&nbsp;ç¼©æ”¾
\__cchess_new_resize_method:nn { none } { }

% æŒ‰å®žé™…å‚æ•°ç¼©æ”¾
\__cchess_new_resize_method:nn { real }
  {
    \__cchess_force_size_dispatch:nnnn
      {% ç›’å­å®½é«˜ç¼©æ”¾
        \coffin_resize:Nnn \l__cchess_manual_coffin
                           \l__cchess_manual_width_dim
                           \l__cchess_manual_height_dim
      }
      {% æŒ‡å®šé«˜åº¦ä¸ºæ¯”ä¾‹ç¼©æ”¾
        \coffin_scale:Nnn \l__cchess_manual_coffin
          {
            \dim_ratio:nn { \l__cchess_manual_height_dim }
              { \__cchess_coffin_ht_plus_dp:N \l__cchess_manual_coffin }
          }
          {
            \dim_ratio:nn { \l__cchess_manual_height_dim }
              { \__cchess_coffin_ht_plus_dp:N \l__cchess_manual_coffin }
          }
      }
      {% æŒ‡å®šå®½åº¦ä¸ºæ¯”ä¾‹ç¼©æ”¾
        \coffin_scale:Nnn \l__cchess_manual_coffin
          {
            \dim_ratio:nn { \l__cchess_manual_width_dim }
                          { \coffin_wd:N \l__cchess_manual_coffin }
          }
          {
            \dim_ratio:nn { \l__cchess_manual_width_dim }
                          { \coffin_wd:N \l__cchess_manual_coffin }
          }
      }
      {% å®žé™…å®½ã€é«˜æ¯”ä¾‹ç¼©æ”¾
        \coffin_scale:Nnn \l__cchess_manual_coffin
                          { \l__cchess_x_scale_tl }
                          { \l__cchess_y_scale_tl }
      }
  }
\msg_new:nnn { cchess } { resize-type } { using~ `#1'~ resize. }

% ç¬”ç”»è®¾ç½®å‡½æ•°
\cs_new:Npn \__cchess_pieces_stroke:nn #1#2
  {
    \special { pdf:code ~ q ~ #1 } #2 \special { pdf:code ~ Q }
  }
% ç¬”ç”»æž„é€&nbsp;å‡½æ•°
\cs_new_protected:Npn \__cchess_pieces_stroke_construct:n #1
  {
    \int_case:nn {\l__cchess_charstroke_type_int}
      {
        {1}{ #1 }
        {2}{
          \__cchess_pieces_stroke:nn { 1~Tr~0.25~w~[]~0~d~1~J } {#1}
        }
        {3}{
          \__cchess_pieces_stroke:nn { 2~Tr~0.25~w~[]~0~d~1~J~1~1~1~RG~1~1~1~rg } {#1}
        }
        {4}{
          \__cchess_pieces_stroke:nn { 2~Tr~0.25~w } {#1}
        }
        {5}{
          \__cchess_pieces_stroke:nn { 3 ~ Tr } {#1}
        }
      }
  }
\cs_generate_variant:Nn  \__cchess_pieces_stroke_construct:n { V }
\cs_generate_variant:Nn  \__cchess_pieces_stroke_construct:n { x }

% =============æ£‹å­æ–‡å­—è®¾ç½®å‡½æ•°=============
% è®¾ç½®æ£‹å­çš„æ–‡å­—
% çº¢æ£‹ç¼–ç&nbsp;ç”¨å¤§å†™å­—æ¯ï¼Œé»˜è®¤ï¼š
% K=å¸…,A=ä»•,E/B=ç›¸,R=è½¦,C=ç&nbsp;²,H/N=é©¬,P=å…µ
% é»‘æ£‹ç¼–ç&nbsp;ç”¨å°å­—å­—æ¯ï¼Œé»˜è®¤ï¼š
% k=å°†,a=å£«,e/b=è±¡,r=è»Š,c=ç‚®,h/n=é¦¬,p=å’
% #1 æ£‹å­ç¼–ç&nbsp;
% #2 æ£‹å­å­—ç¬¦
\cs_new_nopar:Npn \__cchess_piece_char_setup:nn #1#2
  {
    \clist_if_in:NnF \c__cchess_pieces_name_clist { #1 }
      {
        \msg_error:nnx { cchess } { piecename-exists } { #1 }
      }

    \prop_gput:Nnn \c__cchess_board_pieces_alph_name_prop
        { #1 } { #2 }
  }

% key_valueé€‰é¡¹è®¾è®¡
\keys_define:nn { cchess }
  {
    % ç¼©æ”¾å‚æ•°
    gridsize .code:n = { \dim_set:Nn \gridsize { #1 }
                         % æ£‹å­å°ºå¯¸
                         \dim_set:Nn \piecesize
                           {
                             \fp_to_dim:n { \fp_eval:n { \gridsize * 0.9 } }
                           }
                       } ,
    gridsize .initial:n = 10mm ,
    % æ£‹ç›˜ç±»åž‹
    boardtype .code:n = { \exp_args:NNx \clist_if_in:NnTF \g__cchess_board_list_clist {#1}
                            { \tl_set:Nx \l__cchess_board_type_tl {#1} }
                            { \msg_error:nnx { cchess } { board-exists } {#1} }
                        },
    % æ£‹ç›˜çº¿çº¿å®½
    boardlinewd .code:n = { \dim_set:Nn \l__cchess_board_linewidth_dim {#1}
                            % ä¹å®«çº¿ä¸Žè±¡ä½çº¿çº¿å®½
                            \dim_gset:Nn \l__cchess_cross_linewidth_dim
                              {
                                \fp_to_dim:n
                                  {
                                    \fp_eval:n { \l__cchess_board_linewidth_dim * 0.50 }
                                  }
                              }
                            % ç‚®å…µä½ç½®çº¿ä¸Žæ£‹ç›˜çº¿é—´è·
                            \dim_gset:Nn \l__cchess_cross_sep_dim
                              {
                                \fp_to_dim:n
                                  {
                                    \fp_eval:n { \l__cchess_board_linewidth_dim * 1.80 }
                                  }
                              }
                          },
    boardlinewd .initial:n = 0.4pt ,

    % æ£‹ç›˜çº¿é¢œè‰²
    boardlinecolor  .code:n = { \__cchess_color_select:nn { cchessboardlinecolor } {#1} } ,
    boardlinecolor  .initial:n = black ,
    boardlinecolor* .code:n = { \__cchess_color_select:nnn { cchessboardlinecolor } #1 } ,

    % æ£‹ç›˜èƒŒæ™¯å›¾ç‰‡
    boardbg .tl_set:N  = \l__cchess_board_background_tl ,
    boardbg .initial:n = {} ,

    % è®¾ç½®æ£‹å­å­—ç¬¦
    piecechar .code:n    = { \__cchess_piece_char_setup:nn #1 },
    piecechar .initial:n = {K}{\c__cchess_K_tl} ,

    % å­—ç¬¦æ&nbsp;¼å¼
    piecefont .code:n = { \tl_set:Nn \l__cchess_piece_char_format_tl {#1}
                          \__cchess_calc_piece_box_size:
                        },

    % è¾¹æ¡†ç±»åž‹
    piecetype .code:n = { \exp_args:NNx \clist_if_in:NnTF
                            \g__cchess_piece_box_list_clist {#1}
                            { \tl_set:Nx \l__cchess_piece_box_type_tl {#1} }
                            { \msg_error:nnx { cchess } { box-exists } {#1} }
                        },

    % å­—ç¬¦è¾¹æ¡†çº¿å®½
    boxlinewd .dim_set:N = \l__cchess_box_linewidth_dim ,
    boxlinewd .initial:n = 0.4pt ,

    % è¾¹æ¡†çº¿é¢œè‰²
    boxcolor  .code:n    = { \__cchess_color_select:nn { cchesspieceboxcolor } {#1} } ,
    boxcolor  .initial:n = black ,
    boxcolor* .code:n    = { \__cchess_color_select:nnn { cchesspieceboxcolor } #1 } ,
    % å­—ç¬¦é¢œè‰²
    redpiece  .code:n    = { \__cchess_color_select:nn { cchessredpiececolor } {#1} } ,
    redpiece  .initial:n = red ,
    redpiece* .code:n    = { \__cchess_color_select:nnn { cchessredpiececolor } #1 } ,
    blkpiece  .code:n    = { \__cchess_color_select:nn { cchessblkpiececolor } {#1} } ,
    blkpiece  .initial:n = black ,
    blkpiece* .code:n    = { \__cchess_color_select:nnn { cchessblkpiececolor } #1 } ,

    % æ£‹å­èƒŒæ™¯åº•å±‚å¡«å……é¢œè‰²
    lower  .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1}
                         {
                           \__cchess_color_select:nn { lowerbgboxfill }
                             { yellow!70!red }
                           \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                             { \color_fill:n { yellow!70!red } }
                         }{ \__cchess_color_select:nn { lowerbgboxfill } { #1 }
                           \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                             { \color_fill:n { #1 } }
                         }
                     } ,
    lower  .initial:n = {} ,

    % æ—&nbsp;åè‰²æ—¶ä¸Šå±‚ç›’å­èƒŒæ™¯å¡«å……é¢œè‰²
    donut  .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1}
                         {
                           \__cchess_color_select:nn { donutboxfill }
                             { yellow!80!black }
                           \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                             { \color_fill:n { yellow!80!black } }
                         }{ \__cchess_color_select:nn { donutboxfill } { #1 }
                           \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                             { \color_fill:n { #1 } }
                         }
                     } ,
    donut  .initial:n = {} ,

    % æ£‹å­èƒŒæ™¯åº•å±‚å¡«å……é¢œè‰²
    redupper  .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1}
                            {
                              \__cchess_color_select:nn { redupperbgboxfill }
                                { yellow!70!red }
                              \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                                { \color_fill:n { yellow!70!red } }
                            }{ \__cchess_color_select:nn { redupperbgboxfill } { #1 }
                              \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                                { \color_fill:n { #1 } }
                            }
                        } ,
    redupper  .initial:n = {} ,

    % æ£‹å­èƒŒæ™¯åº•å±‚å¡«å……é¢œè‰²
    blkupper  .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1}
                            {
                              \__cchess_color_select:nn { blkupperbgboxfill }
                                { yellow!70!red }
                              \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                                { \color_fill:n { yellow!70!red } }
                            }{ \__cchess_color_select:nn { blkupperbgboxfill } { #1 }
                              \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                                { \color_fill:n { #1 } }
                            }
                        } ,
    blkupper  .initial:n = {} ,

    % ç›’å­é˜´å½±å¡«å……é¢œè‰²
    shadow  .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1}
                          {
                            \__cchess_color_select:nn { shadowboxfill }
                              { black!35!white }
                            \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                              { \color_fill:n { black!35!white } }
                          }{ \__cchess_color_select:nn { shadowboxfill } { #1 }
                            \cs_set_nopar:Npn \__cchess_aux_color_boxfill:
                              { \color_fill:n { #1 } }
                          }
                       } ,
    shadow  .initial:n = {} ,

    % ç¬”ç”»å‚æ•°
    charstroke .choice:,
    charstroke .value_required:n = true,
    charstroke .choices:nn =
      { none, solid, white, bold, invisible }
      { \int_set_eq:NN \l__cchess_charstroke_type_int \l_keys_choice_int },
    charstroke .initial:n = bold,

    unknown .code:n = { \msg_error:nn { cchess } { unknown-option } }
  }
\msg_new:nnn { cchess } { unknown-option }
  { package~ option~ "\l_keys_key_tl"~ is~ unknown. }

\keys_set:nn { cchess }
  {
    piecefont = \kaishu,
    piecetype = ooo,
    boardtype = x+tn,
  }

\ProcessKeysOptions { cchess }

% key_valueé€‰é¡¹è®¾è®¡(æ‰“è°±man)
\keys_define:nn { cchess / man }
  {
    % æ‰“è°±çŽ¯å¢ƒäº¤å‰å¼•ç”¨æ&nbsp;‡ç­¾
    label .tl_gset:N  = \l__cchess_setman_label_tl ,
    label .initial:n = {} ,

    % æ¯è¡Œæ£‹è°±æ­¥æ•°
    nums .tl_gset:N  = \l__cchess_mans_per_line_int ,
    nums .initial:n = 2 ,

    unknown .code:n = { \msg_error:nn { cchess } { unknown-man-option } }
  }
\msg_new:nnn { cchess } { unknown-man-option }
  { package~ manual~ option~ "\l_keys_key_tl"~ is~ unknown. }

% key_valueé€‰é¡¹è®¾è®¡(ç¼©æ”¾resize)
\keys_define:nn { cchess / resize }
  {
    % ç¼©æ”¾æ–¹å¼
    type    .code:n = { \exp_args:NNx \clist_if_in:NnTF \g__cchess_resize_method_clist {#1}
                            { \tl_set:Nx \l__cchess_resize_method_tl {#1} }
                            { \msg_error:nnx { cchess } { resize-method } {#1} }
                        },
    % ç¼©æ”¾å‚æ•°
    xscale .tl_set:N  = \l__cchess_x_scale_tl ,
    xscale .initial:n = 1 ,
    yscale .tl_set:N  = \l__cchess_y_scale_tl ,
    yscale .initial:n = 1 ,
    scale  .meta:n    = { xscale = #1 , yscale = #1 } ,
    width  .dim_set:N = \l__cchess_manual_width_dim ,
    height .dim_set:N = \l__cchess_manual_height_dim ,

    unknown .code:n = { \msg_error:nn { cchess } { unknown-resize-option } }
  }
\msg_new:nnn { cchess } { unknown-resize-option }
  { package~ resize~ option~ "\l_keys_key_tl"~ is~ unknown. }

\keys_set:nn { cchess / resize }
  {
    type = none,
  }

% =============åˆ¤æ–­é€‰é¡¹æ˜¯å¦å­˜åœ¨=============

% çŠ¶æ€è®°å½•boolå˜é‡
\bool_new:N \g__cchess_is_board_option_bool
\bool_new:N \g__cchess_is_piece_option_bool

% åˆ¤æ–­æ˜¯å¦æœ‰æ£‹ç›˜å¤–è§‚å‚æ•°
\cs_new:Npn \__cchess_board_option_if_in:n #1
  {
    \bool_set_false:N \g__cchess_is_board_option_bool
    \clist_map_inline:nn { board,gridsize }
      {
        \tl_if_in:nnT { #1 } { ##1 }
          {
            \bool_set_true:N \g__cchess_is_board_option_bool
            \clist_map_break:
          }
      }
  }

% åˆ¤æ–­æ˜¯å¦æœ‰æ£‹å­å¤–è§‚å‚æ•°
\cs_new:Npn \__cchess_piece_option_if_in:n #1
  {
    \bool_set_false:N \g__cchess_is_piece_option_bool
    \clist_map_inline:nn { piece,lower,donut,upper,shadow,box,charstroke }
      {
        \tl_if_in:nnT { #1 } { ##1 }
          {
            \bool_set_true:N \g__cchess_is_piece_option_bool
            \clist_map_break:
          }
      }
  }

% æ£‹ç›˜å‚æ•°åˆ¤æ–­
\prg_set_conditional:Npnn \__cchess_board_option_if_in:n #1 { p, T, F, TF }
  {
    \__cchess_board_option_if_in:n { #1 }

    \bool_if:NTF \g__cchess_is_board_option_bool
      {
        \prg_return_true:
      }{
        \prg_return_false:
      }
  }

% æ£‹å­å‚æ•°åˆ¤æ–­
\prg_set_conditional:Npnn \__cchess_piece_option_if_in:n #1 { p, T, F, TF }
  {
    \__cchess_piece_option_if_in:n { #1 }

    \bool_if:NTF \g__cchess_is_piece_option_bool
      {
        \prg_return_true:
      }{
        \prg_return_false:
      }
  }

% é€‰é¡¹è®¾ç½®ç”¨æˆ·æŽ¥å£
\NewDocumentCommand \cchessset { m }
  {
    \IfNoValueF { #1}
      {
        \keys_set:nn { cchess } { #1 }

        % æœ‰draftå‚æ•°ï¼Œéœ€è¦é‡æž„æ£‹å­å’Œæ£‹ç›˜
        \tl_if_in:nnT { #1 } { draft }
          {
            % æž„å»ºæ£‹ç›˜
            \__cchess_board_construct:
            % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
            \__cchess_pieces_construct:
          }

        \bool_if:NF \g__cchess_draft_bool
          {
            % æž„å»ºæ£‹ç›˜
            \__cchess_board_option_if_in:nT { #1 }
              {
                \__cchess_board_construct:
              }
            % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
            \__cchess_piece_option_if_in:nT { #1 }
              {
                \__cchess_pieces_construct:
              }
          }
      }
  }

% =============åˆ›å»ºæ£‹å­coffins=============
% é»‘ç™½æ£‹å­å­—ç¬¦é¢œè‰²åŠæ£‹å­é¢œè‰²é€‰æ‹©
\cs_new:Npn \__cchess_pieces_color_select:n #1
  {
    \regex_match:NnTF \l__capital_regex { #1 }
      {
        \color_set_eq:nn { cchesspiececolor } { cchessredpiececolor }
        \color_set_eq:nn { upperbgboxfill } { redupperbgboxfill }
      }{
        \color_set_eq:nn { cchesspiececolor } { cchessblkpiececolor }
        \color_set_eq:nn { upperbgboxfill } { blkupperbgboxfill }
      }
  }

% æž„å»ºæ£‹å­ç›’å­å®¹å™¨
\cs_new:Nn \__cchess_pieces_construct:
  {
    \group_begin:
      \prop_map_inline:Nn \c__cchess_board_pieces_alph_name_prop
        {
          % é€‰æ‹©é¢œè‰²
          \__cchess_pieces_color_select:n { ##1 }
          % æ£‹å­æ–‡å­—
          \tl_gset:Nx \l__cchess_piece_tl { ##2 }

          % æž„å»ºæ£‹å­ç›’å­å®¹å™¨
          \hcoffin_set:Nn \l__cchess_piece_coffin
            {
              \__cchess_piece_construct:N \l__cchess_piece_tl
            }

          % ç¼©æ”¾æ£‹å­ç›’å­å®¹å™¨
          \coffin_resize:Nnn \l__cchess_piece_coffin { \piecesize }{ \piecesize }

          % ä¿å­˜ç»“æžœ
          \coffin_gset_eq:cN
            { l__cchess_piece_ ##1 _coffin } \l__cchess_piece_coffin
        }
    \group_end:
  }

% æž„é€&nbsp;å¸¦åœˆå­—ç¬¦
% #1 éœ€è¦å¤„ç†çš„å­—ç¬¦(ä¸²)å˜é‡
\cs_new:Npn \__cchess_piece_construct:N #1
  {
    % æŒ‰æŒ‡å®šé¢œè‰²å’Œæ&nbsp;¼å¼æž„é€&nbsp;æ£‹å­å­—ç¬¦ç›’å­å®¹å™¨
    \hcoffin_gset:Nn \l__cchess_box_coffin
      {
        \bool_if:NTF \g__cchess_draft_bool
          {
            \color_select:n { cchesspiececolor }
            #1
          }{
            \color_select:n { cchesspiececolor }
            \tl_use:N \l__cchess_piece_char_format_tl
            % ç¬”åˆ’å¤„ç†
            \__cchess_pieces_stroke_construct:n { #1 }
          }
      }

    % æž„é€&nbsp;æž„é€&nbsp;æ£‹å­å­—ç¬¦ç›’å­å®¹å™¨è¾¹æ¡†
    \__cchess_single_box_construct:
  }
% gridsize,boardtype,boardlinewd,boardlinecolor,boardbg,
% piecechar,piecefont,piecetype,boxlinewd,boxcolor,redpiece,blkpiece,
% lower,donut,redupper,blkupper,shadow,charstroke

% å­—ç¬¦ç›’å­åŠè¾¹æ¡†ç»„åˆç›’å­å®¹å™¨æž„é€&nbsp;å‡½æ•°
\cs_new:Npn \__cchess_single_box_construct:
  {
    \bool_if:NTF \g__cchess_draft_bool
      {
        \coffin_typeset:cnnnn { l__cchess_box_coffin }
          { l } { b } { 0pt } { 0pt }
      }{
        % ç»˜åˆ¶å­—ç¬¦å¤–æ¡†å¹¶æ‹¼è£…ç»“æžœ
        \draw_begin:
          \draw_linewidth:n { \l__cchess_box_linewidth_dim }

          \draw_path_scope_begin:
            \__cchess_piece_box_type_c:n { \l__cchess_piece_box_type_tl } { 1.0 }
            \draw_transform_shift:n {\charboxsize / 2.0, \charboxsize / 2.0 }
            \draw_coffin_use:Nnn \l__cchess_box_coffin { hc } { vc }
          \draw_path_scope_end:
        \draw_end:
      }
  }

% =============åˆ›å»ºæ£‹å­å&nbsp;ä½coffins=============
  % ç¼©æ”¾ç©ºç™½æ£‹å­
\cs_new:Nn \__cchess_board_piece_z_resize:
  {
    \coffin_resize:Nnn \l__cchess_piece_z_coffin { \piecesize } { \piecesize }
  }
% ç¼©æ”¾ç©ºç™½æ£‹å­
\__cchess_board_piece_z_resize:

% å°†æ£‹å­ç›’å­å®¹å™¨å¸ƒç½®åˆ°æ£‹ç›˜æŒ‡å®šä½ç½®(ç”¨äºŽæ£‹è°±å’Œæ£‹ç›˜æŽ’ç‰ˆ)
% #1 æ£‹å­å‚æ•°
% æ£‹å­å‚æ•°çš„å½¢å¼ä¸º{{0,0}{k},{0,1}{K}}ï¼Œæ³¨æ„éœ€è¦åŒ…å«å¤§æ‹¬å·ï¼Œ
% ä¸åŒæ£‹å­ä¹‹é—´ç”¨è‹±æ–‡é€—å·åˆ†éš”
\cs_new:Npn \__cchess_board_piece_pos_construct:n #1
  {
    \hcoffin_gset:Nn \l__cchess_board_pieces_pos_coffin
      {
        \draw_begin:
          % åœ¨å››ä¸ªè§’å¸ƒç½®ç©ºç™½æ£‹å­å®žçŽ°å&nbsp;ä½(ç”¨äºŽæ’‘æ»¡æ£‹å­ç”»å¸ƒ)
          \clist_set:Nn \l_tmpa_clist
            { {0, 0}{z}, {8, 0}{z}, {0, 9}{z}, {8, 9}{z}}
          \clist_map_inline:Nn \l_tmpa_clist
            {
              \__cchess_piece_set_handle:nn ##1
            }

          % åœ¨æŒ‡å®šä½ç½®å¸ƒç½®æ£‹å­
          \clist_set:Nn \l_tmpa_clist { #1 }
          \clist_map_inline:Nn \l_tmpa_clist
            {
              \__cchess_piece_set_handle:nn ##1
            }
        \draw_end:
      }
  }

% =============åˆ›å»ºæ£‹ç›˜èƒŒæ™¯coffin=============
% è½½å…¥èƒŒæ™¯å›¾ç‰‡
\cs_new:Nn \__cchess_board_backgroud_construct:
  {
    \hcoffin_set:Nn \l__cchess_board_background_coffin
      {
        % å¦‚æžœæ–‡ä»¶åä¸ä¸ºç©ºåˆ™è½½å…¥å›¾ç‰‡ï¼Œå¦åˆ™åˆ›å»ºä¸€ä¸ªç©ºç›’å­å®¹å™¨
        \tl_if_empty:NTF \l__cchess_board_background_tl
          {
            \phantom{a}
          }{
            \includegraphics{\l__cchess_board_background_tl}
          }
      }
  }

% ç»„è£…èƒŒæ™¯å›¾ç‰‡
\cs_new:Nn \__cchess_board_assemble:
  {
    % è®¡ç®—æ£‹ç›˜+æ£‹å­åŽçš„æ€»å®½å’Œæ€»é«˜
    \dim_gset:Nn \l_tmpa_dim
      {
        \coffin_wd:N \l__cchess_manual_coffin
      }
    \dim_gset:Nn \l_tmpb_dim
      {
        \__cchess_coffin_ht_plus_dp:N \l__cchess_manual_coffin
      }

    % æ”¾å¤§ä¸€ä¸ªæ£‹å­çš„é•¿åº¦
    \dim_add:Nn \l_tmpa_dim { \piecesize / 2 }
    \dim_add:Nn \l_tmpb_dim { \piecesize / 2 }

    \bool_if:NF \g__cchess_draft_bool
      {
        % æž„å»ºèƒŒæ™¯å›¾ç‰‡coffin
        \__cchess_board_backgroud_construct:

        % ç¼©æ”¾èƒŒæ™¯å›¾ç‰‡coffin
        \coffin_resize:Nnn \l__cchess_board_background_coffin
          { \l_tmpa_dim } { \l_tmpb_dim }
      }

    % ç»˜åˆ¶æ€»è¾¹æ¡†å¤–çº¿
    \hcoffin_set:Nn \l__cchess_tmpa_coffin
      {
        \draw_begin:
          \draw_linewidth:n { \l__cchess_board_linewidth_dim * 2 }
          \draw_path_rectangle:nn
            { 0pt, 0pt } { \l_tmpa_dim * 0.99, \l_tmpb_dim * 0.99 }
          \draw_path_use_clear:n { draw }
        \draw_end:
      }

    % ç»˜åˆ¶æ€»è¾¹æ¡†å†…çº¿
    \hcoffin_set:Nn \l__cchess_tmpb_coffin
      {
        \draw_begin:
          \draw_linewidth:n { \l__cchess_board_linewidth_dim * 1 }
          \draw_path_rectangle:nn
            { 0pt, 0pt } { \l_tmpa_dim * 0.97, \l_tmpb_dim * 0.97 }
          \draw_path_use_clear:n { draw }
        \draw_end:
      }

    % æ‹¼è£…ç»“æžœ
    \hcoffin_set:Nn \l__cchess_manual_coffin
      {
        \draw_begin:
          \draw_path_scope_begin:
            \draw_transform_shift:n { \l_tmpa_dim / 2, \l_tmpa_dim / 2 }
            \bool_if:NF \g__cchess_draft_bool
              {
                \draw_coffin_use:Nnn \l__cchess_board_background_coffin { hc } { vc }
              }
            \draw_coffin_use:Nnn \l__cchess_tmpa_coffin { hc } { vc }
            \draw_coffin_use:Nnn \l__cchess_tmpb_coffin { hc } { vc }
            \draw_coffin_use:Nnn \l__cchess_manual_coffin { hc } { vc }
          \draw_path_scope_end:
        \draw_end:
      }

  }

% =============åˆ›å»ºæ£‹ç›˜coffins=============
\cs_new:Nn \__cchess_board_construct:
  {
    % æŒ‰æŒ‡å®šç±»åž‹åˆ›å»ºæ£‹ç›˜
    \hcoffin_set:Nn \l__cchess_board_coffin
      {
        \draw_begin:
          \draw_linewidth:n { \l__cchess_board_linewidth_dim }

          \draw_path_scope_begin:
            \bool_if:NTF \g__cchess_draft_bool
              {
                \__cchess_board_type_c:n { x } { 1.0 } { 1.0 }
              }{
                \__cchess_board_type_c:n { \l__cchess_board_type_tl } { 1.0 } { 1.0 }
              }
          \draw_path_scope_end:
        \draw_end:
      }

    % è®¡ç®—æ£‹ç›˜æ€»å®½å’Œæ€»é«˜
    \dim_gset:Nn \l__cchess_board_width_dim
      {
        \coffin_wd:N \l__cchess_board_coffin
      }
    \dim_gset:Nn \l__cchess_board_height_dim
      {
        \__cchess_coffin_ht_plus_dp:N \l__cchess_board_coffin
      }
  }

% åœ¨æ­£æ–‡ä¸­æŽ’ç‰ˆæ£‹å­
\cs_new:Npn \__cchess_getpiece_handle:nn #1#2
  {
    % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
    % \__cchess_pieces_construct:

    % è®¾ç½®æŒ‡å®šæ&nbsp;¼å¼çš„åŸºå­—ç¬¦ç›’å­
    \hbox_set:Nn \l_tmpa_box { #1 å°† }

    % ç›’å­é«˜åº¦
    \dim_set:Nn \l_tmpa_dim
      {
        \box_ht_plus_dp:N \l_tmpa_box
      }

    % æ£‹å­é«˜åº¦
    \dim_set:Nn \l_tmpb_dim
      {
        \__cchess_coffin_ht_plus_dp:N \l__cchess_piece_K_coffin
      }

    % ç¼©æ”¾æ£‹å­
    \coffin_scale:cnn { l__cchess_piece_ #2 _coffin }
      {
        \dim_ratio:nn { \l_tmpa_dim } { \l_tmpb_dim }
      }{
        \dim_ratio:nn { \l_tmpa_dim } { \l_tmpb_dim }
      }

    % ç›’å­æ·±åº¦
    \dim_set:Nn \l_tmpb_dim { \box_dp:N \l_tmpa_box }

    % è¾“å‡ºç›’å­(ä¸‹æ²‰æ·±åº¦è·ç¦»)
    \coffin_typeset:cnnnn { l__cchess_piece_ #2 _coffin }
        { l } { b } { 0pt } { -\l_tmpb_dim }
  }

% æž„å»ºæ£‹ç›˜
\__cchess_board_construct:

% æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
\__cchess_pieces_construct:

% =============æŽ’ç‰ˆæ£‹è°±=============
% æ£‹è°±æŽ’ç‰ˆ
\cs_new:Npn \__cchess_manual_output:n #1
  {
    % æž„å»ºæ£‹ç›˜
    % \__cchess_board_construct:

    % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
    % \__cchess_pieces_construct:

    % æž„å»ºæ£‹å­ç”»å¸ƒç›’å­å®¹å™¨
    \__cchess_board_piece_pos_construct:n { #1 }

    % å°†æ£‹ç›˜ä¸Žæ£‹å­ç”»å¸ƒå±…ä¸­å¯¹é½åŽè¿›è¡Œæ‹¼è£…
    \hcoffin_set:Nn \l__cchess_manual_coffin
      {
        \draw_begin:
          \draw_path_scope_begin:
            \draw_transform_shift:n
              {
                \l__cchess_board_width_dim / 2,
                \l__cchess_board_height_dim / 2
              }
            \draw_coffin_use:Nnn \l__cchess_board_coffin { hc } { vc }
            \draw_coffin_use:Nnn \l__cchess_board_pieces_pos_coffin { hc } { vc }
          \draw_path_scope_end:
        \draw_end:
      }

    % æŒ‰æŒ‡å®šæ–¹å¼è¿›è¡Œç¼©æ”¾
    \__cchess_resize_c:n { \l__cchess_resize_method_tl }

    % æ·»åŠ&nbsp;èƒŒæ™¯å’Œå¤–æ¡†
    \__cchess_board_assemble:

    % è¾“å‡ºç»“æžœ
    \coffin_typeset:Nnnnn \l__cchess_manual_coffin
      { l }{ b } { 0pt } { 0pt }
  }

% æŽ’ç‰ˆæ£‹ç›˜
\cs_new:Nn \__cchess_board_output:
  {
    % åˆ›å»ºæ£‹ç›˜
    % \__cchess_board_construct:

    % æ˜¯å¦éœ€è¦æ£‹å­
    \bool_if:NT  \l__cchess_board_pieces_bool
      {
        % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
        % \__cchess_pieces_construct:

        % åˆ›å»º32ä¸ªæ£‹å­ç”»å¸ƒç›’å­å®¹å™¨
        \__cchess_board_piece_pos_construct:n
          {
            { {0,0}{R} }, { {1,0}{H} }, { {2,0}{E} }, { {3,0}{A} }, { {4,0}{K} },
            { {5,0}{A} }, { {6,0}{E} }, { {7,0}{H} }, { {8,0}{R} },
            { {1,2}{C} }, { {7,2}{C} },
            { {0,3}{P} }, { {2,3}{P} }, { {4,3}{P} }, { {6,3}{P} }, { {8,3}{P} },
            { {0,9}{r} }, { {1,9}{h} }, { {2,9}{e} }, { {3,9}{a} }, { {4,9}{k} },
            { {5,9}{a} }, { {6,9}{e} }, { {7,9}{h} }, { {8,9}{r} },
            { {1,7}{c} }, { {7,7}{c} },
            { {0,6}{p} }, { {2,6}{p} }, { {4,6}{p} }, { {6,6}{p} }, { {8,6}{p} }
          }
      }

    % æ‹¼è£…ç»“æžœ
    \hcoffin_set:Nn \l__cchess_manual_coffin
      {
        \draw_begin:
          \draw_path_scope_begin:
            \draw_transform_shift:n
              {
                \l__cchess_board_width_dim / 2,
                \l__cchess_board_height_dim / 2
              }
            \draw_coffin_use:Nnn \l__cchess_board_coffin { hc } { vc }
            \bool_if:NT  \l__cchess_board_pieces_bool
              {
                \draw_coffin_use:Nnn \l__cchess_board_pieces_pos_coffin { hc } { vc }
              }
          \draw_path_scope_end:
        \draw_end:
      }

    % æŒ‰æŒ‡å®šæ–¹å¼ç¼©æ”¾
    \__cchess_resize_c:n { \l__cchess_resize_method_tl }

    % æ·»åŠ&nbsp;èƒŒæ™¯å’Œå¤–æ¡†
    \__cchess_board_assemble:

    % è¾“å‡ºç»“æžœ
    \coffin_typeset:Nnnnn \l__cchess_manual_coffin
      { l }{ b } { 0pt } { 0pt }
  }

% è®¾ç½®æ­£åˆ™åŒ¹é…å‡½æ•°å˜ä½“å‡½æ•°
\cs_generate_variant:Nn \regex_match:NnT { NV }
\cs_generate_variant:Nn \regex_match:NnF { NV }

% åˆ©ç”¨æ­£åˆ™åŒ¹é…å’Œå±žæ€§è¡¨ï¼Œ
% å°†å­—æ¯æˆ–æ•°å­—è¡¨ç¤ºçš„æ£‹å­åæ&nbsp;‡è½¬æ¢ä¸ºæ•°å­—è¡¨ç¤º
\cs_new:Npn \__cchess_piece_set_handle:nn #1#2
  {
    \clist_set:Nn \l_tmpa_clist { #1 }
    \clist_pop:NN \l_tmpa_clist \l_tmpa_tl
    \clist_pop:NN \l_tmpa_clist \l_tmpb_tl

    % åˆ¤æ–­è¾“å…¥åˆæ³•æ€§
    \clist_if_in:NVF \c__cchess_pos_x_index_clist \l_tmpa_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpa_tl }
      }
    \clist_if_in:NVF \c__cchess_pos_y_index_clist \l_tmpb_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpb_tl }
      }
    \clist_if_in:NnF \c__cchess_pieces_name_clist { #2 }
      {
        \msg_error:nnx { cchess } { piecename-exists } { #2 }
      }

    % è½¬æ¢åæ&nbsp;‡ä¸ºæ•°å­—
    \regex_match:NVT \l__alph_regex \l_tmpa_tl
      {
        \prop_get:NVN \c__cchess_board_pos_alph_num_prop \l_tmpa_tl \l_tmpa_tl
      }

    \regex_match:NVT \l__alph_regex \l_tmpb_tl
      {
        \prop_get:NVN \c__cchess_board_pos_alph_num_prop \l_tmpb_tl \l_tmpb_tl
      }

    % ç”¨æ•°å­—åæ&nbsp;‡å®šä½å¸ƒç½®æ£‹å­
    \__cchess_piece_set:VVn \l_tmpa_tl \l_tmpb_tl { #2 }
  }

% åœ¨æŒ‡å®šä½ç½®å¸ƒç½®æ£‹å­
% #1 xæ–¹å‘æ•°å­—åž‹åæ&nbsp;‡å€¼(0-8)
% #2 yæ–¹å‘æ•°å­—åž‹åæ&nbsp;‡å€¼(0-9)
% #3 æ£‹å­åç§°(å•è‹±æ–‡å­—æ¯)
\cs_new:Npn \__cchess_piece_set:nnn #1#2#3
  {
    \draw_path_scope_begin:
      \draw_transform_shift:n { \gridsize * #1, \gridsize * #2 }
      \draw_coffin_use:cnn { l__cchess_piece_ #3 _coffin } { hc } { vc }
    \draw_path_scope_end:
  }
\cs_generate_variant:Nn \__cchess_piece_set:nnn {VV}

% ======================================================
% ===é‡‡ç”¨æ£‹å­æ›¿æ¢æ–¹å¼åˆ›å»ºæ£‹å­ç”»å¸ƒcoffin(ç”¨äºŽæ‰“è°±æŽ’ç‰ˆ)===
% ======================================================
% ç¼©æ”¾å&nbsp;æ£‹å­ç›’å­å®¹å™¨
\cs_new:Nn \__cchess_board_pieces_resize:
  {
    % ç©ºç™½æ£‹å­
    \coffin_resize:Nnn \l__cchess_board_piece_z_coffin
       { \piecesize } { \piecesize }

    % å…¶å®ƒæ£‹å­ï¼ŒæŒ‰è¡Œ(a-i)åˆ—(a-j)ç¼–å·å‘½åã€‚
    \clist_map_inline:Nn \c__cchess_board_pos_x_clist
      {
        \clist_map_inline:Nn \c__cchess_board_pos_y_clist
          {
            \coffin_resize:cnn { l__cchess_board_piece_ ##1 _ ####1 _coffin }
              { \piecesize } { \piecesize }
          }
      }
  }

% åˆ›å»ºå­—æ¯è¡Œåˆ—ç¼–å·å‘½åæ£‹å­çš„å&nbsp;ä½æ£‹å­ç”»å¸ƒ
\cs_new:Nn \__cchess_board_pieces_seat:
  {
    % ç¼©æ”¾å&nbsp;ä½æ£‹å­
    \__cchess_board_pieces_resize:

    % åˆ©ç”¨åŒé‡å¾ªçŽ¯åˆ›å»ºæ£‹å­ç”»å¸ƒ
    \hcoffin_gset:Nn \l__cchess_board_pieces_pos_coffin
    {
      \draw_begin:
        \int_zero:N \l_tmpa_int
        % æ‰«æa-iæ¨ªå‘ä½ç½®ç¼–å·åˆ—è¡¨
        \clist_map_inline:Nn \c__cchess_board_pos_x_clist
          {
            \int_zero:N \l_tmpb_int
            % æ‰«æa-jçºµå‘ä½ç½®ç¼–å·åˆ—è¡¨
            \clist_map_inline:Nn \c__cchess_board_pos_y_clist
              {
                \draw_path_scope_begin:
                  % åæ&nbsp;‡å¹³ç§»
                  \draw_transform_shift:n
                    { \gridsize * \l_tmpa_int, \gridsize * \l_tmpb_int }
                  % å¸ƒç½®æ£‹å­
                  \draw_coffin_use:cnn
                    { l__cchess_board_piece_ ##1 _ ####1 _coffin } { hc } { vc }
                \draw_path_scope_end:
                \int_incr:N \l_tmpb_int
              }
            \int_incr:N \l_tmpa_int
          }
      \draw_end:
    }
  }

% æ£‹å­ç”»å¸ƒæ£‹å­æ›¿æ¢å¥æŸ„å‡½æ•°
% åˆ©ç”¨æ­£åˆ™åŒ¹é…å’Œå±žæ€§è¡¨ï¼Œ
% å°†å­—æ¯æˆ–æ•°å­—è¡¨ç¤ºçš„æ£‹å­åæ&nbsp;‡è½¬æ¢ä¸ºå­—æ¯è¡¨ç¤º
\cs_new:Npn \__cchess_piece_replace_handle:nn #1#2
  {
    \clist_set:Nn \l_tmpa_clist { #1 }
    \clist_pop:NN \l_tmpa_clist \l_tmpa_tl
    \clist_pop:NN \l_tmpa_clist \l_tmpb_tl

    % åˆ¤æ–­è¾“å…¥åˆæ³•æ€§
    \clist_if_in:NVF \c__cchess_pos_x_index_clist \l_tmpa_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpa_tl }
      }
    \clist_if_in:NVF \c__cchess_pos_y_index_clist \l_tmpb_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpb_tl }
      }
    \clist_if_in:NnF \c__cchess_pieces_name_clist { #2 }
      {
        \msg_error:nnx { cchess } { piecename-exists } { #2 }
      }

    % è½¬æ¢åæ&nbsp;‡ä¸ºå­—æ¯
    \regex_match:NVT \l__digit_regex \l_tmpa_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpa_tl \l_tmpa_tl
      }

    \regex_match:NVT \l__digit_regex \l_tmpb_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpb_tl \l_tmpb_tl
      }

    % ç”¨å­—æ¯åæ&nbsp;‡å®šä½å¸ƒç½®æ£‹å­
    \__cchess_piece_replace:VVn \l_tmpa_tl \l_tmpb_tl { #2 }
  }

% æ£‹å­å&nbsp;ä½æ›¿æ¢å‡½æ•°
% #1 æ¨ªå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-i)
% #2 çºµå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-j)
% #3 æ£‹å­åç§°(å•è‹±æ–‡å­—æ¯)
\cs_new:Npn \__cchess_piece_replace:nnn #1#2#3
  {
    \coffin_gset_eq:cc
      { l__cchess_board_piece_ #1 _ #2 _coffin }
      { l__cchess_piece_ #3 _coffin }
  }
\cs_generate_variant:Nn \__cchess_piece_replace:nnn {VV}

% æ£‹å­åˆ&nbsp;é™¤å¥æŸ„å‡½æ•°
% åˆ©ç”¨æ­£åˆ™åŒ¹é…å’Œå±žæ€§è¡¨ï¼Œ
% å°†å­—æ¯æˆ–æ•°å­—è¡¨ç¤ºçš„æ£‹å­åæ&nbsp;‡è½¬æ¢ä¸ºå­—æ¯è¡¨ç¤º
\cs_new:Npn \__cchess_piece_remove_handle:n #1
  {
    \clist_set:Nn \l_tmpa_clist { #1 }
    \clist_pop:NN \l_tmpa_clist \l_tmpa_tl
    \clist_pop:NN \l_tmpa_clist \l_tmpb_tl

    % åˆ¤æ–­è¾“å…¥åˆæ³•æ€§
    \clist_if_in:NVF \c__cchess_pos_x_index_clist \l_tmpa_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpa_tl }
      }
    \clist_if_in:NVF \c__cchess_pos_y_index_clist \l_tmpb_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpb_tl }
      }

    % è½¬æ¢åæ&nbsp;‡ä¸ºå­—æ¯
    \regex_match:NVT \l__digit_regex \l_tmpa_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpa_tl \l_tmpa_tl
      }

    \regex_match:NVT \l__digit_regex \l_tmpb_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpb_tl \l_tmpb_tl
      }

    % ç”¨å­—æ¯åæ&nbsp;‡å®šä½å¸ƒç½®æ£‹å­
    \__cchess_piece_remove:VV \l_tmpa_tl \l_tmpb_tl
  }

% æ£‹å­åˆ&nbsp;é™¤å‡½æ•°
% #1 æ¨ªå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-i)
% #2 çºµæ–¹å‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-j)
% #3 æ£‹å­åç§°(å•è‹±æ–‡å­—æ¯)
\cs_new:Npn \__cchess_piece_remove:nn #1#2
  {
    \coffin_gset_eq:cN
      { l__cchess_board_piece_ #1 _ #2 _coffin }
      \l__cchess_board_piece_z_coffin
  }
\cs_generate_variant:Nn \__cchess_piece_remove:nn {VV}

% æ£‹å­ç§»åŠ¨å¥æŸ„å‡½æ•°
% åˆ©ç”¨æ­£åˆ™åŒ¹é…å’Œå±žæ€§è¡¨ï¼Œ
% å°†å­—æ¯æˆ–æ•°å­—è¡¨ç¤ºçš„æ£‹å­åæ&nbsp;‡è½¬æ¢ä¸ºå­—æ¯è¡¨ç¤º
\cs_new:Npn \__cchess_piece_move_handle:nnn #1#2#3
  {
    \clist_set:Nn \l_tmpa_clist { #2 }
    \clist_pop:NN \l_tmpa_clist \l_tmpa_tl
    \clist_pop:NN \l_tmpa_clist \l_tmpb_tl
    \clist_set:Nn \l_tmpa_clist { #3 }
    \clist_pop:NN \l_tmpa_clist \l_tmpc_tl
    \clist_pop:NN \l_tmpa_clist \l_tmpd_tl

    % åˆ¤æ–­è¾“å…¥åˆæ³•æ€§
    \clist_if_in:NVF \c__cchess_pos_x_index_clist \l_tmpa_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpa_tl }
      }
    \clist_if_in:NVF \c__cchess_pos_y_index_clist \l_tmpb_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpb_tl }
      }
    \clist_if_in:NVF \c__cchess_pos_x_index_clist \l_tmpc_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpc_tl }
      }
    \clist_if_in:NVF \c__cchess_pos_y_index_clist \l_tmpd_tl
      {
        \msg_error:nnx { cchess } { piecename-exists } { \l_tmpd_tl }
      }
    \clist_if_in:NnF \c__cchess_pieces_name_clist { #1 }
      {
        \msg_error:nnx { cchess } { piecename-exists } { #1 }
      }

    % è½¬æ¢åæ&nbsp;‡ä¸ºå­—æ¯
    \regex_match:NVT \l__digit_regex \l_tmpa_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpa_tl \l_tmpa_tl
      }
    \regex_match:NVT \l__digit_regex \l_tmpb_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpb_tl \l_tmpb_tl
      }
    \regex_match:NVT \l__digit_regex \l_tmpc_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpc_tl \l_tmpc_tl
      }

    \regex_match:NVT \l__digit_regex \l_tmpd_tl
      {
        \prop_get:NVN \c__cchess_board_pos_num_alph_prop \l_tmpd_tl \l_tmpd_tl
      }

    % ç”¨å­—æ¯åæ&nbsp;‡å®šä½å¸ƒç½®æ£‹å­
    \__cchess_piece_move:VVVVn
      \l_tmpa_tl \l_tmpb_tl \l_tmpc_tl \l_tmpd_tl { #1 }
  }

% æ£‹å­ç§»åŠ¨å‡½æ•°
% #1 åŽŸä½ç½®æ¨ªå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-i)
% #2 åŽŸä½ç½®çºµå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-j)
% #3 æ–°ä½ç½®æ¨ªå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-i)
% #4 æ–°ä½ç½®çºµå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-j)
% #5 æ£‹å­åç§°(å•è‹±æ–‡å­—æ¯)
\cs_new:Npn \__cchess_piece_move:nnnnn #1#2#3#4#5
  {
    % åˆ&nbsp;é™¤åŽŸä½ç½®æ£‹å­
    \__cchess_piece_remove:nn { #1 } { #2 }
    % åœ¨æ–°ä½ç½®å¸ƒç½®æ£‹å­
    \__cchess_piece_replace:nnn { #3 } { #4 } { #5 }

    % ç”Ÿæˆæ‰“è°±æ£‹è°±è®°å½•
    \bool_if:NT \l__cchess_with_setman_bool
      {
        \__cchess_piece_manual_str_construct:nnnnn { #1 }{ #2 }{ #3 }{ #4 }{ #5 }
      }
  }
\cs_generate_variant:Nn \__cchess_piece_move:nnnnn {VVVV}

% ç”Ÿæˆæ‰“è°±æ£‹è°±è®°å½•
% TODOï¼šæš‚æœªå®žçŽ°çºµå‘åŒç±»æ£‹å­å‰åŽåˆ¤æ–­
% #1 åŽŸä½ç½®æ¨ªå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-i)
% #2 åŽŸä½ç½®çºµå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-j)
% #3 æ–°ä½ç½®æ¨ªå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-i)
% #4 æ–°ä½ç½®çºµå‘å­—ç¬¦åž‹åæ&nbsp;‡å€¼(a-j)
% #5 æ£‹å­åç§°(å•è‹±æ–‡å­—æ¯)
\cs_new:Npn \__cchess_piece_manual_str_construct:nnnnn #1#2#3#4#5
  {
    % å°†å­—ç¬¦åæ&nbsp;‡æ•°æ®è½¬æ¢ä¸ºæ•´æ•°åæ&nbsp;‡
    \prop_get:NnN \c__cchess_board_pos_alph_num_prop { #1 } \l_tmpa_tl
    \prop_get:NnN \c__cchess_board_pos_alph_num_prop { #2 } \l_tmpb_tl
    \prop_get:NnN \c__cchess_board_pos_alph_num_prop { #3 } \l_tmpc_tl
    \prop_get:NnN \c__cchess_board_pos_alph_num_prop { #4 } \l_tmpd_tl
    \int_set:Nn \l_tmpa_int { \l_tmpa_tl }
    \int_set:Nn \l_tmpb_int { \l_tmpb_tl }
    \int_set:Nn \l_tmpc_int { \l_tmpc_tl }
    \int_set:Nn \l_tmpd_int { \l_tmpd_tl }

    % è¡Œæ£‹åˆ†æž
    \int_compare:nNnTF { \l_tmpc_int } = { \l_tmpa_int }
      { % çºµå‘ç§»åŠ¨
        \int_compare:nNnTF { \l_tmpd_int } &gt; { \l_tmpb_int }
          {
            % åæ&nbsp;‡å‘ä¸Š
            \int_set:Nn \l_tmpe_int { \l_tmpd_int - \l_tmpb_int }
            \tl_set:Nx \l_tmpe_tl { \int_use:N \l_tmpe_int }
            \regex_match:NnTF \l__capital_regex { #5 }
              { % çº¢æ£‹
                \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                \prop_get:NnN \c__cchess_board_red_x_idx_prop { #1 } \l_tmpb_tl
                \prop_get:NVN \c__cchess_board_pos_arabic_zh_prop \l_tmpe_tl \l_tmpc_tl
                \clist_put_right:Nx \l__cchess_manual_clist
                  {
                    \l_tmpa_tl
                    \l_tmpb_tl
                    è¿›
                    \l_tmpc_tl
                  }
              }{ % é»‘æ£‹
                \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                \prop_get:NnN \c__cchess_board_black_x_idx_prop { #1 } \l_tmpb_tl
                \clist_put_right:Nx \l__cchess_manual_clist
                  {
                    \l_tmpa_tl
                    \l_tmpb_tl
                    é€€
                    \int_use:N \l_tmpe_int
                  }
              }
          }{ % åæ&nbsp;‡å‘ä¸‹
            \int_set:Nn \l_tmpe_int { \l_tmpb_int - \l_tmpd_int }
            \tl_set:Nx \l_tmpe_tl { \int_use:N \l_tmpe_int }
            \regex_match:NnTF \l__capital_regex { #5 }
              { % çº¢æ£‹
                \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                \prop_get:NnN \c__cchess_board_red_x_idx_prop { #1 } \l_tmpb_tl
                \prop_get:NVN \c__cchess_board_pos_arabic_zh_prop \l_tmpe_tl \l_tmpc_tl
                \clist_put_right:Nx \l__cchess_manual_clist
                  {
                    \l_tmpa_tl
                    \l_tmpb_tl
                    é€€
                    \l_tmpc_tl
                  }
              }{ % é»‘æ£‹
                \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                \prop_get:NnN \c__cchess_board_black_x_idx_prop { #1 } \l_tmpb_tl
                \clist_put_right:Nx \l__cchess_manual_clist
                  {
                    \l_tmpa_tl
                    \l_tmpb_tl
                    è¿›
                    \int_use:N \l_tmpe_int
                  }
              }
          }
      }{ % éžçºµå‘ç§»åŠ¨
        \int_compare:nNnTF { \l_tmpd_int } = { \l_tmpb_int }
          { % æ°´å¹³ç§»åŠ¨
            \regex_match:NnTF \l__capital_regex { #5 }
              { % é»‘æ£‹
                \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                \prop_get:NnN \c__cchess_board_red_x_idx_prop { #1 } \l_tmpb_tl
                \prop_get:NnN \c__cchess_board_red_x_idx_prop { #3 } \l_tmpc_tl
                \clist_put_right:Nx \l__cchess_manual_clist
                  {
                    \l_tmpa_tl
                    \l_tmpb_tl
                    å¹³
                    \l_tmpc_tl
                  }
              }{ % çº¢æ£‹
                \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                \prop_get:NnN \c__cchess_board_black_x_idx_prop { #1 } \l_tmpb_tl
                \prop_get:NnN \c__cchess_board_black_x_idx_prop { #3 } \l_tmpc_tl
                \clist_put_right:Nx \l__cchess_manual_clist
                  {
                    \l_tmpa_tl
                    \l_tmpb_tl
                    å¹³
                    \l_tmpc_tl
                  }
              }
          }{ % éžçºµéžæ¨ªå‘ç§»åŠ¨
            \int_compare:nNnTF { \l_tmpd_int } &gt; { \l_tmpb_int }
              { % çºµå‘å‘ä¸Š
                \regex_match:NnTF \l__capital_regex { #5 }
                  { % çº¢æ£‹
                    \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                    \prop_get:NnN \c__cchess_board_red_x_idx_prop { #1 } \l_tmpb_tl
                    \prop_get:NnN \c__cchess_board_red_x_idx_prop { #3 } \l_tmpc_tl
                    \clist_put_right:Nx \l__cchess_manual_clist
                      {
                        \l_tmpa_tl
                        \l_tmpb_tl
                        è¿›
                        \l_tmpc_tl
                      }
                  }{ % é»‘æ£‹
                    \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                    \prop_get:NnN \c__cchess_board_black_x_idx_prop { #1 } \l_tmpb_tl
                    \prop_get:NnN \c__cchess_board_black_x_idx_prop { #3 } \l_tmpc_tl
                    \clist_put_right:Nx \l__cchess_manual_clist
                      {
                        \l_tmpa_tl
                        \l_tmpb_tl
                        é€€
                        \l_tmpc_tl
                      }
                  }
              }{ % çºµå‘å‘ä¸‹
                \regex_match:NnTF \l__capital_regex { #5 }
                  { % çº¢æ£‹
                    \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                    \prop_get:NnN \c__cchess_board_red_x_idx_prop { #1 } \l_tmpb_tl
                    \prop_get:NnN \c__cchess_board_red_x_idx_prop { #3 } \l_tmpc_tl
                    \clist_put_right:Nx \l__cchess_manual_clist
                      {
                        \l_tmpa_tl
                        \l_tmpb_tl
                        é€€
                        \l_tmpc_tl
                      }
                  }{ % é»‘æ£‹
                    \prop_get:NnN \c__cchess_board_pieces_alph_name_prop { #5 } \l_tmpa_tl
                    \prop_get:NnN \c__cchess_board_black_x_idx_prop { #1 } \l_tmpb_tl
                    \prop_get:NnN \c__cchess_board_black_x_idx_prop { #3 } \l_tmpc_tl
                    \clist_put_right:Nx \l__cchess_manual_clist
                      {
                        \l_tmpa_tl
                        \l_tmpb_tl
                        è¿›
                        \l_tmpc_tl
                      }
                  }
              }
          }
      }
  }
\cs_generate_variant:Nn \__cchess_piece_manual_str_construct:nnnnn {VVVV}

% æ‰“è°±çŽ¯å¢ƒå‰å¤„ç†å‡½æ•°
% #1 æ‰“è°±å‘½ä»¤
\cs_new:Npn \__cchess_setcchessman_pre_setup:n #1
  {
    % æž„å»ºæ£‹ç›˜
    % \__cchess_board_construct:
    % æž„å»ºçº¢é»‘å„9ä¸ªæ£‹å­
    % \__cchess_pieces_construct:

    % åˆ&nbsp;é™¤çŽ¯å¢ƒä¸­çš„ä»£ç&nbsp;ä¸­çš„ç©ºç™½
    \tl_set:Nn \l_tmpa_tl { #1 }
    \tl_remove_all:Nn \l_tmpa_tl {~}
    % æ‰§è¡ŒçŽ¯å¢ƒä¸­çš„ä»£ç&nbsp;
    \tl_use:N \l_tmpa_tl
  }

% å®šä¹‰\labelå‘½ä»¤çš„å˜ä½“å‡½æ•°
%\label { #1 }
\cs_set_eq:NN \__cchess_setman_label:n \label
\cs_generate_variant:Nn \__cchess_setman_label:n { x }

% æ‰“è°±çŽ¯å¢ƒåŽå¤„ç†å‡½æ•°
\cs_new:Nn \__cchess_setcchessman_post_setup:
  {
    % å¸ƒç½®æ£‹å­
    \__cchess_board_pieces_seat:

    % å°†æ£‹ç›˜ä¸Žæ‰“è°±ç»“æžœç›’å­å®¹å™¨å±…ä¸­å¯¹é½åŽè¿›è¡Œæ‹¼è£…
    \hcoffin_set:Nn \l__cchess_manual_coffin
      {
        \draw_begin:
          \draw_path_scope_begin:
            \draw_transform_shift:n
              {
                \l__cchess_board_width_dim / 2,
                \l__cchess_board_height_dim / 2
              }
            \draw_coffin_use:Nnn \l__cchess_board_coffin { hc } { vc }
            \draw_coffin_use:Nnn \l__cchess_board_pieces_pos_coffin { hc } { vc }
          \draw_path_scope_end:
        \draw_end:
      }

    % ç¼©æ”¾æ‹¼è£…ç»“æžœ
    \__cchess_resize_c:n { \l__cchess_resize_method_tl }

    % æ·»åŠ&nbsp;èƒŒæ™¯å’Œå¤–æ¡†
    \__cchess_board_assemble:

    % æ˜Ÿå·çŽ¯å¢ƒéœ€è¦è¾“å‡ºæ‰“è°±è®°å½•
    \bool_if:NT \l__cchess_with_setman_bool
      {
        % é€’å¢žè®¡æ•°å™¨
        \refstepcounter{setman}
        % è®¾ç½®labelæ&nbsp;‡ç­¾
        \__cchess_setman_label:x { \l__cchess_setman_label_tl }

        % æž„é€&nbsp;ä¸´æ—¶æ–‡ä»¶
        \iow_open:Nn \g_tmpa_iow
          {
            \c_sys_jobname_str\l__cchess_setman_label_tl\thesetman .man
          }

        % éåŽ†æ‰“è°±è®°å½•åˆ—è¡¨ï¼Œè¾“å‡ºæ‰“è°±è®°å½•åˆ°ä¸´æ—¶æ–‡ä»¶
        \bool_until_do:nn { \clist_if_empty_p:N \l__cchess_manual_clist }
          {
            \clist_pop:NN \l__cchess_manual_clist \l_tmpa_tl
            \tl_set:Nx \l_tmpb_tl {\l_tmpa_tl}
            \iow_now:Nx \g_tmpa_iow { \l_tmpb_tl }
          }

        % å…³é—­æ–‡ä»¶
        \iow_close:N \g_tmpa_iow
      }

    % è¾“å‡ºç»“æžœç›’å­å®¹å™¨
    \coffin_typeset:Nnnnn \l__cchess_manual_coffin
      { l }{ b } { 0pt } { 0pt }
  }

% å‚è€ƒé›¾æœˆçš„å›žå¤ï¼šhttps://ask.latexstudio.net/ask/question/7430.html
% LaTeX3 å¹¶æœªå®šä¹‰ \use_i:nnnnn
\cs_set:Npn \use_i:nnnnn #1#2#3#4#5 {#1}

% æ‰“è°±æ£‹è°±æŽ’ç‰ˆæè¿°å¤„ç†
\cs_new:Npn \__cchess_setman_print:n #1
  {
    % æ&nbsp;¹æ®æ£‹è°±labelæž„å»ºæ–‡ä»¶å
    \cs_if_exist:cTF { r@#1 }
      {
        % è¿™ä¸€æ­¥æ˜¯å¾—åˆ° refï¼Œå®ƒä¿å­˜åœ¨ \r@#1 ä¸­ã€‚
        % \r@#1 æœ‰ä¸¤é¡¹ï¼Œå½“ä½¿ç”¨ hyperref æ—¶ï¼Œ
        % \r@#1 æœ‰ 5 é¡¹ï¼Œè¿™é‡Œä½¿ç”¨ \empty ç»Ÿä¸€è§£å†³
        \tl_set:Nx \l_tmpa_tl
          {
            \c_sys_jobname_str
            #1 \exp_args:NNc \exp_after:wN \use_i:nnnnn { r@ #1 }
            \c_empty_tl \c_empty_tl \c_empty_tl .man
          }

        % æ‰“å¼€æ–‡ä»¶è¯»å–æ•°æ®å¹¶è¾“å‡ºç»“æžœ
        \ior_open:NnTF \g_tmpb_ior { \l_tmpa_tl }
          {
            % å¾ªçŽ¯è®¡æ•°
            \int_set:Nn \l_tmpa_int { 1 }
            % å¾ªçŽ¯è¯»å–ä¸€è¡Œæ£‹è°±
            \ior_str_map_variable:NNn \g_tmpb_ior \l_tmpb_str
              {
                % è½¬æ¢ä¸ºtoken
                \tl_set_rescan:Nno \l_tmpb_tl
                  {
                    \char_set_catcode_letter:N \_
                    \char_set_catcode_letter:N :
                  }{ \l_tmpb_str }

                % è¾“å‡ºç»“æžœ
                \tl_use:N \l_tmpb_tl

                % æ&nbsp;¹æ®æ¯è¡Œæ­¥æ•°ç¡®å®šè¾“å‡º\quadæˆ–æ˜¯\par
                \int_set:Nn \l_tmpb_int
                  {
                    \int_mod:nn { \l_tmpa_int } { \l__cchess_mans_per_line_int }
                  }
                \int_compare:nNnTF { \l_tmpb_int } = { 0 }
                  { \par } { \quad }

                \int_incr:N \l_tmpa_int
              }
          }
          { \msg_error:nnx { cchess } { file-not-found } { \l_tmpa_tl } }

        % å…³é—­æ–‡ä»¶
        \iow_close:N \g_tmpa_ior
      }{ \G@refundefinedtrue }% å¼•ç”¨æœªå®šä¹‰
  }

\endinput
</pre></body></html>