在 xskak 循环中添加不同的可能性

在 xskak 循环中添加不同的可能性

我想使用 xskak 循环添加不同的可能性来继续游戏。我使用了以下代码,该代码在每种可能性中从头开始游戏,而不是从原始游戏的最后一步继续。如何做到这一点?

\documentclass{beamer}
\usepackage{xskak, chessboard}
\setbeamertemplate{navigation symbols}{}
\makeatletter
\providecommand\xskak@beforecomment{} %ups a bug, definition is missing
\makeatother
\begin{document}
\newcommand\getmovestyle[1]{%
\ifthenelse
  {\equal{#1}{N}}%knight move
  {\def\mymovestyle{[clockwise=false,style=knight]curvemove}}%
  {\ifthenelse
    {\equal{#1}{}}% castling
    {\def\mymovestyle{curvemove}}%
    {\def\mymovestyle{straightmove}}}}%

\begin{center}
\newchessgame %don't add math here  \[\newchessgame\].  no need for \newchessgame\longmoves
\hidemoves{
1. d4 e6 2. e4 d5 3. Nc3 c5 4. Nf3 Nc6 5. exd5 exd5 6. Be2 Nf6 7. O-O Be7 8. Bg5 O-O 9. dxc5 Be6 10. Nd4 Bxc5 11. Nxe6 fxe6 12. Bg4 Qd6 13. Bh3 Rae8 14. Qd2 Bb4 15. Bxf6 Rxf6 16. Rad1 Qc5 17. Qe2 Bxc3 18. bxc3 Qxc3 19. Rxd5 Nd4 20. Qh5 Ref8 21. Re5 Rh6 22. Qg5  Rxh3 23. Rc5 
Qg3 \xskakcomment{white was offered the Queen in three ways, and he could not accept it by any means, else white would face an inevitable mate. white resigned. Qg3 was indeed one of the best moves ever played.}
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[normalboard,% do not use \[\chessboard[ ]\]
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,     coloremph, color=red!50, markstyle=circle, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
  \par           % new paragraph 
  }% End of \xskakloop...

\storegame{game1}% to store game to memory

\restoregame{game1}% to restore game from memory
\hidemoves{
24. Qxg3  \xskakcomment{Possibility1}
Ne2+ 25. Kh1 Nxg3+ 26. Kg1 Nxf1 27. gxh3 
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[normalboard,% do not use \[\chessboard[ ]\]
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,     coloremph, color=red!50, markstyle=circle, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
  \par           % new paragraph 
  }% End of \xskakloop...

\restoregame{game1}% to restore game from memory
\hidemoves{
24. hxg3  \xskakcomment{Possibility2}
Ne2# 
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[normalboard,% do not use \[\chessboard[ ]\]
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,     coloremph, color=red!50, markstyle=circle, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
  \par           % new paragraph 
  }% End of \xskakloop...

\restoregame{game1}% to restore game from memory
\hidemoves{
24. fxg3  \xskakcomment{Possibility3}
Ne2+ 25. Kh1 Rxf1# 
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[normalboard,% do not use \[\chessboard[ ]\]
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,     coloremph, color=red!50, markstyle=circle, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
  \par           % new paragraph 
  }% End of \xskakloop...

\restoregame{game1}% to restore game from memory
\hidemoves{
24. Qxg3  \xskakcomment{Possibility4}
Ne2+ 25. Kh1 Nxg3+ 26. fxg3 Rxf1# 
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[normalboard,% do not use \[\chessboard[ ]\]
 pgfstyle=\mymovestyle, color=blue!50,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to,     coloremph, color=red!50, markstyle=circle, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
  \par           % new paragraph 
  }% End of \xskakloop...
\end{center}
\end{document}

答案1

您可以使用键 initmoveid 和 stopmoveid 来限制循环。

您还可以使用另一个 fen 和 moveid 开始新游戏。

\documentclass[parskip=half-,landscape]{scrartcl}
\usepackage{xskak}
\usepackage{chessboard}

\makeatletter
\providecommand\xskak@beforecomment{} %ups a bug, definition is missing
\makeatother

\begin{document}
\newchessgame[id=Main] % main game
\hidemoves{1. d4 e6 2. e4 d5 3. Nc3 c5 4. Nf3 Nc6 5. exd5 exd5 6. Be2 Nf6 7. O-O Be7 8. Bg5 O-O 9. dxc5 Be6 10. Nd4 Bxc5 11. Nxe6 fxe6 12. Bg4 Qd6 13. Bh3 Rae8 14. Qd2 Bb4 15. Bxf6 Rxf6 16. Rad1 Qc5 17. Qe2 Bxc3 18. bxc3 Qxc3 19. Rxd5 Nd4 20. Qh5 Ref8 21. Re5 Rh6 22. Qg5  Rxh3 23. Rc5 Qg3} 


\minisec{Variation 1}

\newchessgame[id=var,  %var
  setfen=\XskakMainlastfen, %fen from Main
  moveid=\XskakMainnextmoveid
 ]
\hidemoves{24. Qxg3  \xskakcomment{Possibility1}
Ne2+ 25. Kh1 Nxg3+ 26. Kg1 Nxf1 27. gxh3}

\xskakloop[initmoveid=24w,stopmoveid=25b]{% restrict the loop
 \begin{tabular}{c}
 \chessboard[tinyboard,setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
 \end{tabular}
  \quad 
  }%


\minisec{Variation 2}

\newchessgame[id=var,  %var
  setfen=\XskakMainlastfen,
  moveid=\XskakMainnextmoveid
 ]
\hidemoves{24. hxg3  \xskakcomment{Possibility2} Ne2# }

\xskakloop{%
\begin{tabular}{c}
 \chessboard[tinyboard,setfen=\xskakget{nextfen}]\\
  \xskakget{opennr}%print the move number
  \xskakget{lan} %print the move
  \xskakget{nag} % print the comment
\end{tabular}  
  \quad 
  }%


\end{document}

在此处输入图片描述

答案2

我想到了一个主意,使用 setfen 来存储游戏的最后位置,然后 restorefen 并添加新的可能性。对其他每种可能性都重复此操作。我使用了以下代码:

\chessboard[setfen=,storefen=XX]
\newchessgame[restorefen=XX]
\hidemoves{1.hxg3  Ne2#}

相关内容