以下是一个包含两个部分的游戏 - 第一部分 - 开局动作,第二部分 - 然后开始分析进一步的动作。为此,我创建了一个游戏 firstgame1 并使用 \looping{1} 宏显示动作。然后再次创建 firstgame2 直到动作 5w,并使用主线添加更多动作,但我觉得 firstgame2 直到 5w 的就绪状态是循环宏无法正常工作的原因。请建议可以对循环宏进行的任何更改,例如传递游戏循环开始的 moveid 或专家可以建议的任何内容。
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{chessboard}
\usepackage[ps,normal]{skak}
\usepackage{xskak}
\usepackage{minibox}
\usepackage{xcolor}
\usepackage{geometry}
\geometry{
left=1cm,
right=1cm,
top=3cm,
bottom=2cm}
% \looping macro start of code :::
\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}}}}%
\newcommand{\looping}[1]{
% \chessboard[setfen=\xskakgetgame{initfen}]% Show me the empty board.
\xskakloop[step=#1]
{ \begin{tabular}{c}
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
% id=#2,
pgfstyle=\mymovestyle,
color=blue,
markmoves=\xskakget{move},
pgfshortenend=0.3em,
arrow=to,
coloremph,
color=red,
markstyle=circle,
markfield=\xskakget{movefrom},
emphfields=\xskakget{moveto},
setfen=\xskakget{nextfen}]
\\ \xskakget{opennr}\xskakget{san}
\end{tabular}
}% End of \xskakloop...
}
% the looping code - Borrowed from tex.stackexchange
\begin{document}
\title{Learning Chess}
\maketitle
\tableofcontents
\chapter{An Advantage in development}
\section{Rapid development}
\newchessgame[id=firstgame1,white=Mikhail Tal, black=Wolfgang Uhlmann]
\subsubsection{\xskakgetgame{white}--\xskakgetgame{black}}
\mainline{1.e4 e6 2.d4 d5 3. Nd2 c5 4. Ngf3 Nc6 5. Bb5}
% Printing the opening moves step by step : Part 1
\looping{1}
% Part II - created to show the moves after Opening moves.
% Setting the opening move for showing moves using looping macro from 5b move.
\newchessgame[white=Mikhail Tal, black=Wolfgang Uhlmann,id=firstgame2,moveid=5b,
setfen={r1bqkbnr/pp3ppp/2n1p3/1Bpp/3PP/5N/PPP2PPP/R1BQK2R}]
% adding next moves which we need to show in looping macro.
\subsubsection{Further}
\mainline{5...dxe4?!}
\mainline{6. Nxe4 Bd7 7. Ng5}
%current status of the board
\showboard
% Looping macro to show moves from 5b but its not working, I am not able to understand what changes to make to the macro to make it work.
\looping{1}
\end{document}
答案1
如果错误的话,您在第二场游戏中的起始位置会出错:您缺少 d2 上的骑士。
像这样修正 fen:
\newchessgame[white=Mikhail Tal, black=Wolfgang Uhlmann,id=firstgame2,moveid=5b,
setfen={r1bqkbnr/pp3ppp/2n1p3/1Bpp/3PP/5N/PPPN1PPP/R1BQK2R}] %added knight
你第 7 步的代码也是错的。由于 e4 上有一个骑士,f3 上也有一个骑士,所以你必须判断哪一个骑士要移到 g5(例如 f 骑士):
\mainline{6. Nxe4 Bd7 7. Nfg5}