xskak 展示某些动作

xskak 展示某些动作

使用以下代码,是否可以仅显示带有注释的动作而不是所有动作?

\documentclass{beamer}
\usepackage{xskak, chessboard}
\usepackage{verbatim}
\setbeamertemplate{navigation symbols}{}

\makeatletter
\providecommand\xskak@beforecomment{}
\makeatother

\newcommand\getmovestyle[1]{
\ifthenelse
  {\equal{#1}{N}}
  {\def\mymovestyle{[clockwise=false,style=knight]curvemove}}
      {\ifthenelse
    {\equal{#1}{}}
    {\def\mymovestyle{curvemove}}
    {\def\mymovestyle{straightmove}}}}

\begin{document}

\begin{center}
\newchessgame
\chessboard{}

Ruy Lopez Opening: Scotch Game Example \\

\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 \xskakcomment{ This is Ruy Lopez Opening }
 4. dxe5 Nxe4 5. g3 f6 6. exf6 Qxf6 7. Qe2 d5 8. Bg5 
 Qe6  \xskakcomment{ Good move }
 9. Nbd2 Be7 10. Bf4 Nb4 11. Qb5+ Bd7 
 12. Nd4 \xskakcomment{ Bad response }
 Nxc2+ 13. Kd1 Nxd4 14. Qxb7 O-O 15. Be3 Nb5 16. Bxb5 Rab8 17. Qxc7 Bxb5 18. Bxa7 Nxf2+ 19. Bxf2 Qe2+ 20. Kc1 Rbc8 21. Re1 Rxc7+ 22. Kb1 
 Bd3# \xskakcomment{ Final move }
}
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[normalboard,
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,  markstyle=\dots\, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}
  \xskakget{lan}
  \xskakget{nag}
  \par
  }%
\end{center}

\end{document}

答案1

您可以测试 nag-data 是否为空。请注意,较短的 NAG(例如 $4)也在此字段中:

\documentclass{article}
\usepackage{xskak}
\usepackage{chessboard}
\usepackage{etoolbox}
\makeatletter
\providecommand\xskak@beforecomment{}
\makeatother

\newcommand\getmovestyle[1]{
\ifthenelse
  {\equal{#1}{N}}
  {\def\mymovestyle{[clockwise=false,style=knight]curvemove}}
      {\ifthenelse
    {\equal{#1}{}}
    {\def\mymovestyle{curvemove}}
    {\def\mymovestyle{straightmove}}}}

\begin{document}

\begin{center}
\newchessgame

Ruy Lopez Opening: Scotch Game Example \\

\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 \xskakcomment{ This is Ruy Lopez Opening }
 4. dxe5 Nxe4 5. g3 f6 6. exf6 Qxf6 7. Qe2 d5 8. Bg5
 Qe6  \xskakcomment{ Good move }
 9. Nbd2 Be7 10. Bf4 Nb4 11. Qb5+ Bd7
 12. Nd4 \xskakcomment{ Bad response }
 Nxc2+ 13. Kd1 Nxd4 14. Qxb7 O-O 15. Be3 Nb5 16. Bxb5 Rab8 17. Qxc7 Bxb5 18. Bxa7 Nxf2+ 19. Bxf2 Qe2+ 20. Kc1 Rbc8 21. Re1 Rxc7+ 22. Kb1
 Bd3# \xskakcomment{ Final move }
}

\xskakloop{%
\ifcsempty{Xskak.\xskakgetgame{gameid}.\xskakget{movenr}.\xskakget{player}.nag}
{}
{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,  markstyle=\dots\, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}
  \xskakget{lan}
  \xskakget{nag}
  \par
  }}%
\end{center}

\end{document}

在此处输入图片描述

相关内容