![如何在使用 xskakloop(移动历史记录)时标记当前移动和所有先前的移动](https://linux22.com/image/446614/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%BD%BF%E7%94%A8%20xskakloop%EF%BC%88%E7%A7%BB%E5%8A%A8%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95%EF%BC%89%E6%97%B6%E6%A0%87%E8%AE%B0%E5%BD%93%E5%89%8D%E7%A7%BB%E5%8A%A8%E5%92%8C%E6%89%80%E6%9C%89%E5%85%88%E5%89%8D%E7%9A%84%E7%A7%BB%E5%8A%A8.png)
和
movenr={1},
markmove=\xskakget{movefrom}-\xskakget{moveto},
movenr={2},
markmove=\xskakget{movefrom}-\xskakget{moveto},
movenr={3},
markmove=\xskakget{movefrom}-\xskakget{moveto},
......
......
我可以标记的动作movenr
。
使用 xskakloop 时,如何标记当前移动和所有先前移动?
\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{xskak}
\usepackage{chessboard}
\setchessboard{showmover=false, margin=false}
\begin{document}
\section{Loop}
\newchessgame[setwhite={Ba8}]
\mainline{1. Be4 ... 2. Bh7 ... 3. Bg8 ... 4. Ba2 ...}
\setchessboard{pgfstyle=straightmove, color=red,}
\xskakloop[step=2,]{%
\begin{tabular}{c}
\chessboard[tinyboard, setfen=\xskakget{nextfen},
movenr={1},
markmove=\xskakget{movefrom}-\xskakget{moveto},
movenr={2},
markmove=\xskakget{movefrom}-\xskakget{moveto},
movenr={3},
markmove=\xskakget{movefrom}-\xskakget{moveto},
movenr={4},
markmove=\xskakget{movefrom}-\xskakget{moveto},
] \\[1em]
movenr: \xskakget{movenr}, lastmovenr: \xskakgetgame{lastmovenr} \\
\xskakget{opennr}\xskakget{lan}%
\end{tabular}\quad}%
\end{document}
答案1
有\mynamedef
,\mynameuse
来自 https://tex.stackexchange.com/a/635757/46023
\documentclass{article}
% https://tex.stackexchange.com/a/635757/46023
\makeatletter
\def\mynamedef#1#2{\expandafter\xdef\csname#1\endcsname{#2}}
\let\mynameuse\@nameuse
\makeatother
\usepackage{xskak}
\usepackage{chessboard}
\setchessboard{showmover=false,
pgfstyle=straightmove, color=red,}
\begin{document}
\newchessgame[setwhite={Ba8}]
\mainline{1. Be4 ... 2. Bh7 ... 3. Bg8 ... 4. Ba2 ...}
\section{markmove Lists}
\def\Player{w}
\foreach \Moveno in {1,...,\xskakgetgame{lastmovenr}}{%%
\let\List=\empty% create List
\foreach \moveno in {1,...,\Moveno}{%
%\noindent Test: \moveno % Test 1/3
\xskakset{moveid=\moveno\Player}
\xdef\movefromto{\xskakget{movefrom}-\xskakget{moveto}}
%\movefromto % Test 2/3
\ifx\empty\List{} \xdef\List{\movefromto}%
\else \xdef\List{\List, \movefromto}%
\fi%
}% \\% Test 3/3
\mynamedef{List\Moveno}{\List}% List1, List2, ....
}%%
\subsection{Test}
\foreach \Moveno in {1,...,\xskakgetgame{lastmovenr}}{%%
List\Moveno: \mynameuse{List\Moveno} \\}%%
\section{xskak Loop}
\xskakloop[step=2,]{%
\begin{tabular}{c}
\chessboard[tinyboard, setfen=\xskakget{nextfen},
markmoves={\mynameuse{List\xskakget{movenr}}},
] \\[1em]
movenr: \xskakget{movenr}, lastmovenr: \xskakgetgame{lastmovenr} \\
\xskakget{opennr}\xskakget{lan} \\
markmoves: \mynameuse{List\xskakget{movenr}}
\end{tabular}\quad}%
\end{document}