3

I want to make an animation of how a knight moves along a 4 x 8 board visiting each square exactly once. If a square is visited once i want to put an "X" inside the square so that we understand that it already been visited by the knight. I am unable to achieve this.

I have attached a minimal working example! Kindly help.

\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}
TeXnician
  • 33,589
C.S.
  • 1,379
  • @TeXnician : How did you make sure the MWE looks nice? – C.S. Jul 26 '18 at 15:28
  • I selected the code and clicked the code button ({}). – TeXnician Jul 26 '18 at 15:29
  • There comes a point where getting a package to do what you want is harder than not using the package. See https://tex.stackexchange.com/questions/168281/how-to-draw-a-chessboard-with-numbers/168304?s=1|48.1534#168304 – John Kormylo Jul 26 '18 at 19:41
  • @JohnKormylo Sure, i am willing to accept other means of creating the animation as wel – C.S. Jul 27 '18 at 02:30
  • You will have to use another program to convert a multipage PDF into an animation. I believe Chrome can to it. Just google it. See the animation in https://tex.stackexchange.com/questions/295585/cube-in-tikz-not-drawn-correctly-possibly-a-bug-in-tikz – John Kormylo Jul 27 '18 at 03:36

1 Answers1

4

Adobe Reader is needed to see the animation:

\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}

enter image description here

enter image description here

Ulrike Fischer
  • 327,261