在棋盘上画骑士走法时,是否可以使线看起来像“L”,即先笔直走 2 个方格,然后旋转 90 度再变直?
例如下面这段代码
\chessboard[setwhite={Nd4},
pgfstyle=knightmove,
markmoves={d4-b5, d4-c6, d4-e6, d4-f5, d4-f3, d4-e2, d4-c2, d4-b3},
showmover=false]
但每支箭都像这样
\chessboard[setwhite={Nd4},
pgfstyle=knightmove,
markmoves={d4-b4, b4-b5},
showmover=false]
当然,线条相接的地方只有一个箭头。
答案1
绘图基本上是一组 pgf 命令。您可以复制这样的样式并进行更改,或者使用它来定义自己的样式:
\documentclass{article}
\usepackage{chessboard}
\makeatletter
\cbDefinePgfMoveStyle{knightmove|-}{%
\pgfsetlinewidth{\board@pgf@linewidth}%
\pgfsetarrowsend{\board@pgf@arrow}%
\setlength\len@board@tempx{\dimexpr 0.3em + \board@pgf@shortenstart \relax}%
\pgfsetshortenstart{\len@board@tempx}%
\setlength\len@board@tempx{\board@pgf@shortenend}%
\pgfsetshortenend{\len@board@tempx}%
\pgfextractx{\len@board@tempx}{\pgfpointanchor{#1}{center}}%
\pgfextracty{\len@board@tempy}{\pgfpointanchor{#1}{center}}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfpoint{0pt}{\len@board@tempy}}%
\pgfpathlineto{\pgfpointanchor{#1}{center}}%
\pgfusepath{stroke}}%
\cbDefinePgfMoveStyle{knightmove-|}{%
\pgfsetlinewidth{\board@pgf@linewidth}%
\pgfsetarrowsend{\board@pgf@arrow}%
\setlength\len@board@tempx{\dimexpr 0.3em + \board@pgf@shortenstart \relax}%
\pgfsetshortenstart{\len@board@tempx}%
\setlength\len@board@tempx{\board@pgf@shortenend}%
\pgfsetshortenend{\len@board@tempx}%
\pgfextractx{\len@board@tempx}{\pgfpointanchor{#1}{center}}%
\pgfextracty{\len@board@tempy}{\pgfpointanchor{#1}{center}}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfpoint{\len@board@tempx}{0pt}}%
\pgfpathlineto{\pgfpointanchor{#1}{center}}%
\pgfusepath{stroke}}%
\makeatother
\begin{document}
\chessboard[setwhite={Nd4},
pgfstyle=knightmove|-,
markmoves={d4-b5, d4-c6, d4-e6, d4-f5, d4-f3, d4-e2, d4-c2, d4-b3},
showmover=false]
\chessboard[setwhite={Nd4},
pgfstyle=knightmove-|,
markmoves={d4-b5, d4-c6, d4-e6, d4-f5, d4-f3, d4-e2, d4-c2, d4-b3},
showmover=false]
\end{document}