我想制作一个动画,展示骑士如何在 4 x 8 棋盘上移动,每个方格只访问一次。如果某个方格被访问过一次,我想在方格内放置一个“X”,这样我们就知道骑士已经访问过该方格。我无法实现这一点。
我已附上了一个最小工作示例!请帮忙。
\documentclass[14pt]{extarticle}
\usepackage[margin=1in]{geometry}
\usepackage{xskak,chessboard,amsmath}
\storechessboardstyle{4x8}{maxfield=h4,showmover=false}
\setchessboard{style=4x8,boardfontsize=30pt}
\usepackage{animate}
\makeatletter
\cbDefineNewPiece{white}{C}{\raisebox{\depth}{\cfss@whitepiececolor
$\times$}}
\begin{document}
\begin{center}
\textbf{\Large{Knight's Tour: 1}}\\
\begin{animateinline}[controls]{1}
\chessboard[setblack={Na4}]
\newframe
\chessboard[setblack={Nb2}]
\newframe
\chessboard[setblack={Nc4}]
\newframe
\chessboard[setblack={Nd2}]
\newframe
\chessboard[setblack={Ne4}]
\newframe
\chessboard[setblack={Ng3}]
\newframe
\chessboard[setblack={Nh1}]
\newframe
\chessboard[setblack={Nf2}]
\newframe
\chessboard[setblack={Ng4}]
\newframe
\chessboard[setblack={Nh2}]
\newframe
\chessboard[setblack={Nf1}]
\newframe
\chessboard[setblack={Ne3}]
\newframe
\chessboard[setblack={Nd1}]
\newframe
\chessboard[setblack={Nc3}]
\newframe
\chessboard[setblack={Nb1}]
\newframe
\chessboard[setblack={Na3}]
\newframe
\chessboard[setblack={Nc2}]
\newframe
\chessboard[setblack={Na1}]
\newframe
\chessboard[setblack={Nb3}]
\newframe
\chessboard[setblack={Nd4}]
\newframe
\chessboard[setblack={Ne2}]
\newframe
\chessboard[setblack={Nf4}]
\newframe
\chessboard[setblack={Nh3}]
\newframe
\chessboard[setblack={Ng1}]
\newframe
\chessboard[setblack={Nf3}]
\newframe
\chessboard[setblack={Nh4}]
\newframe
\chessboard[setblack={Ng2}]
\newframe
\chessboard[setblack={Ne1}]
\newframe
\chessboard[setblack={Nd3}]
\newframe
\chessboard[setblack={Nb4}]
\newframe
\chessboard[setblack={Na2}]
\newframe
\chessboard[setblack={Nc1}]
\end{animateinline}
\end{center}
\end{document}
答案1
需要 Adobe Reader 才能观看动画:
\documentclass[14pt]{extarticle}
\usepackage[margin=1in]{geometry}
\usepackage{xskak,chessboard,amsmath}
\storechessboardstyle{4x8}{maxfield=h4,showmover=false}
\setchessboard{style=4x8,boardfontsize=30pt}
\usepackage{animate}
\usepackage{xparse}
\ExplSyntaxOn
\clist_const:Nn \g_crs_knight_travel_clist
{
a4,b2,c4,d2,
e4,g3,h1,f2,
g4,h2,f1,e3,
d1,c3,b1,a3,
c2,a1,b3,d4,
e2,f4,h3,g1,
f3,h4,g2,e1,
d3,b4,a2,c1
}
\clist_new:N\g_crs_knight_visited_clist
\cs_new:Nn \crs_knight_travel:
{
\clist_map_inline:Nn \g_crs_knight_travel_clist
{
\setchessboard{pgfstyle=cross,markfield={\clist_use:Nn\g_crs_knight_visited_clist{,}}}
\chessboard[setblack=N##1]
\clist_gput_right:Nn \g_crs_knight_visited_clist {##1}
\newframe
}
\setchessboard{pgfstyle=cross,markfield={\clist_use:Nn\g_crs_knight_visited_clist{,}}}
\chessboard
}
\NewDocumentCommand\knighttravel{}{
\begin{center}
\textbf{\Large{Knight's~Tour:~1}}\\
\begin{animateinline}[controls]{1}
\crs_knight_travel:
\end{animateinline}
\end{center}
}
\ExplSyntaxOff
\begin{document}
\knighttravel
\end{document}