我为国际象棋游戏创建了一个循环。
我使用了 tikz-foreach 方法并\MoveIdList
为其创建了一个(代码密集型)
问题是:可以使用 \xskakloop 循环的仅 xskak 解决方案来实现光学吗?
我不能这样做;因为在那种情况下我不知道如何设置突出显示样式。
注意:我想保留如图所示的(小)tcolorbox-itemize 部分。
%\documentclass[margin=5mm, varwidth]{standalone}
\documentclass[a4paper]{article}
\usepackage[margin=7mm, paperwidth=200mm, paperheight=120mm]{geometry}
\usepackage{colortbl}
\usepackage[most]{tcolorbox}
\usepackage{xskak}
\usepackage{chessboard}
\setchessboard{showmover=false}
\colorlet{mycol}{orange}
\colorlet{altcol}{mycol!22}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}<{}}
% xskak.sty ============================
\makeatletter
\xskaknewstyleitem[% copy from styleC
opencommands={\begin{tabular}{L{2em} L{3em} L{3em}}},
closecommands={\end{tabular}},
blackopen=\ldots,
beforenumber={% \cellcolor{brown}
\ifnum\xskak@val@movenr=\MoveNo \cellcolor{mycol}\fi%
},
beforewhite={&%
\ifnum\xskak@val@movenr=\MoveNo %
\ifnum\IsWhitePlayer=1 \cellcolor{mycol} \else \cellcolor{altcol}\fi
\fi},
afterwhite={ },
beforeblack={&
\ifnum\xskak@val@movenr=\MoveNo %
\ifnum\IsWhitePlayer=0 \cellcolor{mycol} \else \cellcolor{altcol} \fi
\fi},
afterblack={ \\[0.125em] },
whiteopen={.\,},% copy from style UF
]{TabularStyle}
\makeatother
\xskaknewstyle[
styleitem=TabularStyle,
font=\bfseries,% optional
]{styleCx}
% ====================================
\begin{document}
\newchessgame[id=MyGame]
%\hidemoves{1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 a6 6. Be3 e6 7. g4 e5 8. Nf5 g6 9. g5}
\hidemoves{1. e4 c6 2. d4 d5
3. Nc3 dxe4 4. Nxe4 Nd7 5. Ng5 Ngf6
6. Bd3 e6 7. N1f3 h6 8. Nxe6 Qe7 9. O-O fxe6 10. Bg6+ Kd8
11. Bf4 b5 12. a4 Bb7 13. Re1 Nd5 14. Bg3 Kc8 15. axb5 cxb5
16. Qd3 Bc6 17. Bf5 exf5 18. Rxe7 Bxe7 19. c4
}
%\printchessgame[id=MyGame, style=styleCx]
% Create MoveIdList ========================
%Test: lastplayer: \xskakgetgame{lastplayer}, lastmovenr: \xskakgetgame{lastmovenr}
\newcommand{\pMoveIdList}{}% Name reservieren
\let\pMoveIdList=\empty% Liste erstellen
\def\LastMoveNr{\xskakgetgame{lastmovenr}}
\pgfmathtruncatemacro\PreLastMoveNr{\LastMoveNr-1}
\foreach \MoveNo in {1,...,\PreLastMoveNr}{%%
\foreach \Player in {w,b}{%
\ifx\empty\pMoveIdList{} \xdef\pMoveIdList{\MoveNo\Player}%
\else%
\xdef\pMoveIdList{\pMoveIdList, \MoveNo\Player}%
\fi
}%
}%%
\def\BlackPlayerId{b}
%\def\WhitePlayerId{w}
\xdef\LastPlayerId{\xskakgetgame{lastplayer}}
\ifx\LastPlayerId\BlackPlayerId%
\xdef\MoveIdList{\pMoveIdList, \xskakgetgame{lastmovenr}w, \xskakgetgame{lastmovenr}b}%
\else%
\xdef\MoveIdList{\pMoveIdList, \xskakgetgame{lastmovenr}w}%
\fi%
%TEST: LastPlayerId: \LastPlayerId, BlackPlayerId: \BlackPlayerId, MoveIdList: \MoveIdList
% =======================================
\foreach[count=\No] \MoveId in \MoveIdList{%%
\pgfmathtruncatemacro\MoveNo{ceil(\No/2)}%
\pgfmathtruncatemacro\IsWhitePlayer{mod(\No,2)}%
\begin{tcbitemize}[sharp corners, raster equal height=rows,
raster column skip=0mm,
boxrule=1.2pt, boxsep=1mm,
colback=white, colbacktitle=lightgray, coltitle=black, fonttitle=\bfseries,
toptitle=1mm, bottomtitle=1mm,
raster every box/.style={toptitle=1mm, bottomtitle=1mm,},
]
\tcbitem[adjusted title={Move \MoveId}] \chessboard[
moveid=\MoveId, setfen=\xskakget{nextfen}]
\tcbitem[adjusted title={Tot. No: \No, IsWhitePlayer: \IsWhitePlayer}
] \printchessgame[style=styleCx]
\end{tcbitemize}
\newpage
}%%
\end{document}
答案1
我能够使用 xskak-loop 创建它。但对于注释,\printchessgame[style=styleCx]
我需要来自的编号保存框\usepackage{xsavebox}
。
\documentclass[a4paper]{article}
\usepackage[margin=7mm, paperwidth=200mm, paperheight=120mm]{geometry}
\usepackage{colortbl}
\usepackage[most]{tcolorbox}
\usepackage{xsavebox}% <--- !
\usepackage{xskak}
\usepackage{chessboard}
\setchessboard{showmover=false}
% Creating a tabular style =========================
\colorlet{mycol}{yellow}
\colorlet{altcol}{mycol!22}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}<{}}
\makeatletter
\xskaknewstyleitem[% copy from styleC
opencommands={\begin{tabular}{l L{2.5em} L{2.5em}}},
closecommands={\end{tabular}},
blackopen=\ldots,
beforenumber={% \cellcolor{brown}
\ifnum\xskak@val@movenr=\MoveNo \cellcolor{mycol}\fi%
},
beforewhite={&%
\ifnum\xskak@val@movenr=\MoveNo %
\ifnum\IsWhitePlayer=1 \cellcolor{mycol} \else \cellcolor{altcol}\fi
\fi},
afterwhite={ },
beforeblack={&
\ifnum\xskak@val@movenr=\MoveNo %
\ifnum\IsWhitePlayer=0 \cellcolor{mycol} \else \cellcolor{altcol} \fi
\fi},
afterblack={ \\[0.125em] },
whiteopen={.\,},% copy from style UF
]{TabularStyle}
\makeatother
\xskaknewstyle[
styleitem=TabularStyle,
font=\bfseries,% optional
]{styleCx}
% =====================================
\begin{document}
\newchessgame
\hidemoves{1. e4 c6 2. d4 d5
3. Nc3 dxe4 4. Nxe4 Nd7 5. Ng5 Ngf6
6. Bd3 e6 7. N1f3 h6 8. Nxe6 Qe7 9. O-O fxe6 10. Bg6+ Kd8
11. Bf4 b5 12. a4 Bb7 13. Re1 Nd5 14. Bg3 Kc8 15. axb5 cxb5
16. Qd3 Bc6 17. Bf5 exf5 18. Rxe7 Bxe7 19. c4#
}
\foreach[count=\No] \MoveNo in {1,...,\xskakgetgame{lastmovenr}}{
% White Player =================
\pgfmathtruncatemacro\IsWhitePlayer{1}
\def\PlayerId{w}
\def\boxname{mybox-\MoveNo\PlayerId}
\xsbox{\boxname}{\printchessgame[style=styleCx]}
%Test: No: \No, MoveNo: \MoveNo, IsWhitePlayer: \IsWhitePlayer, boxname: \boxname \\ \xusebox{\boxname} \\
% Black Player =================
\pgfmathtruncatemacro\IsWhitePlayer{0}
\def\PlayerId{b}
\def\boxname{mybox-\MoveNo\PlayerId}
\xsbox{\boxname}{\printchessgame[style=styleCx]}
%Test: No: \No, MoveNo: \MoveNo, IsWhitePlayer: \IsWhitePlayer, boxname: \boxname \\ \xusebox{\boxname} \\
}
% Test: \xusebox{mybox-1w}, \xusebox{mybox-2b}
\tcbset{myrasterstyle/.style={
sharp corners, raster equal height=rows,
raster column skip=0mm,
boxrule=1.2pt, boxsep=1mm,
colback=white, colbacktitle=lightgray, coltitle=black, fonttitle=\bfseries,
toptitle=1mm, bottomtitle=1mm,
},}
\xskakloop[step=1]{%%
\begin{tcbitemize}[myrasterstyle]
\tcbitem[adjusted title={Move \xskakget{movenr}\xskakget{player}}
] \chessboard[setfen=\xskakget{nextfen}]
\tcbitem[] \xusebox{mybox-\xskakget{movenr}\xskakget{player}}
\end{tcbitemize}
\newpage}%%
\end{document}