答案1
我为 Omega 类制作了棋盘,如果您适当修改此代码,另一个应该很容易获得。
棋盘的尺寸由以下线条决定:
\newcommand{\maxx}{10}
它将创建一个 10x10 的板,(A-J
,0-9
)。笔记:如果您在棋盘上有棋子,而您以某种方式减少数字,使棋子“超出”棋盘,则会出现错误。因此,如果您的棋盘为 8x8,则您不能在 上放置棋子h9
。
正如评论中所建议的那样,这些部分是字体字符,因此对于额外的字符,您可能需要找到支持它们的字体,或者以其他方式创建它们。对于冠军,我上传了一张.eps
图片到文档中。您可以.svg
从维基百科页面(在 Creative Commons 下)并将其转换为该格式,以便您可以将其包含进去。记得删除背景颜色。
命令
显示所有可能的举动
\showmoves{<position>}{<piece>}{<list of coordinates>}
piece
此命令定义一个放置在的单个position
,后跟一串坐标(c5
例如的形式),显示当前棋子可以移动到的所有方格。单次移动
\showmoves{<position>}{<piece>}{<coordinate>}
例如
\showmoves{c1}{\pawn}{c2}
,如果棋子是\knight
,指示移动的箭头将自动变成正方形。在所有其他情况下,它将是一条直线。这样做是为了与国际象棋指南中通常指示移动的方式保持一致。工件定位
\showmoves{<position>}{<piece>}{} % <-- this must be there, even if empty
正如您将在下面的输出中看到的,您可以写入示例\showmoves{c1}{\rook}{}
,它将放置棋子而无需进行任何移动。
变化(按时间顺序):
- 切换到单个命令来显示定位、单个移动或移动列表;
包含用于排版“方形”动作的代码
knight
(后来用于作品wizard
)。目前,
wizard
标明四条“直”边最后的。
已知的问题:
我不知道为什么,但是方块稍微偏移了。一旦我找到原因,我会立即修复代码。
输出
代码
\documentclass[tikz,margin=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{chessboard} % for the chess pieces
\usepackage{etoolbox} % for if statements
\definecolor{dark}{RGB}{209,139,71}
\definecolor{light}{RGB}{255,206,158}
\usetikzlibrary{arrows, calc}
\tikzset{
every node/.style={font=\Huge},
label/.style={draw=red, text depth=1ex, text height=1ex, inner sep=0, outer sep=0, font=\ttfamily, text=gray, minimum size=1cm},
cell/.style={minimum size=1cm, outer sep=0, inner sep=0},
hdr/.style={font=\ttfamily\normalsize, text=gray, minimum size=1cm, fill=black, draw},
}
\makeatletter
\newcommand{\myalph}[1]{\expandafter\@alph{#1}}
\makeatother
\newcommand{\maxx}{10} % change this for changing the chessboard size
% extra pieces
\newcommand{\bchamp}{\includegraphics[scale=.8]{bchamp}}
\newcommand{\wwiz}{\includegraphics[scale=.8]{wwiz}}
\newcommand\showmoves[3]{%
\node[draw, thick, minimum size=1cm] (a) at (#1) {#2};
\foreach \crdx [%
count=\nate starting from 0
] in {#3}{%
\pgfmathsetmacro\alter{int(mod(\nate,4))}
\pgfmathsetmacro\etan{int(mod(\nate,3))}
\pgfmathsetmacro\etanb{int(mod(\nate,5))}
\expandafter\ifstrequal{#2}{\knight}{%
\ifnum\alter<2\relax
\ifodd\etan
\draw[thick,-*] ([xshift=5mm]a) |- (\crdx);
\else
\draw[thick,-*] ([xshift=-5mm]a) |- (\crdx);
\fi
\else
\ifodd\etanb
\draw[thick,-*] ([yshift=-5mm]a) -| (\crdx);
\else
\draw[thick,-*] ([yshift=5mm]a) -| (\crdx);
\fi
\fi
}{%
\expandafter\ifstrequal{#2}{\wwiz}{%
\ifnum\nate>7
\draw[thick,-*] (a) -- (\crdx);
\else
\ifnum\alter<2\relax
\ifodd\etan
\draw[thick,-*] ([xshift=5mm]a) |- (\crdx);
\else
\draw[thick,-*] ([xshift=-5mm]a) |- (\crdx);
\fi
\else
\ifodd\etanb
\draw[thick,-*] ([yshift=-5mm]a) -| (\crdx);
\else
\draw[thick,-*] ([yshift=5mm]a) -| (\crdx);
\fi
\fi
\fi
}{
\draw[thick,-*] (a) -- (\crdx);
}
}
}
}
\begin{document}
\begin{tikzpicture}[x=1cm]
% chessboard
\foreach \y [count=\nrow starting from 0] in {1,2,...,\maxx} {
\foreach \x in {1,2,...,\maxx} {
\pgfmathsetmacro\color{int(mod(\y + \x, 2)) ? "dark" : "light"}
\coordinate (\myalph{\x}\nrow) at (\x-.5,\y-.5);
\fill[draw=\color,fill=\color] (\x-1,\y-1) rectangle (\x,\y);
%\node[font=\ttfamily] at (\myalph{\x}\nrow) {\myalph{\x}\nrow}; % uncomment to see the cell names
}
}
% rows and columns
\foreach \coord [count=\rows starting from 0] in {1,...,\maxx}{
\path (0,\coord-.5) node[hdr, left] {\rows} -- (\maxx,\coord-.5) node[hdr, right] {\rows};
\path (\coord-.5,0) node[hdr, below] {\myalph{\coord}} -- (\coord-.5,\maxx) node[hdr, above] {\myalph{\coord}};
}
% corners
\foreach \xx/\yy [count=\countw starting from 1] in {-1/-1,10/-1,10/10,-1/10}{
\pgfmathtruncatemacro\angle{90*\countw}
\pgfmathtruncatemacro\angleb{350*\countw} % label={93:w\countw}, label={-15:w\countw},
\ifodd\countw
\node[cell, rotate=\angle-90, inner sep=0, draw=light, fill=light] (n\countw) at (\xx+.5,\yy+.5) {};
\else
\node[cell, rotate=\angle-90, inner sep=0, draw=dark,fill=dark] (n\countw) at (\xx+.5,\yy+.5) {};
\fi
}
\showmoves{c1}{\rook}{} % no moves, just placing piece
\showmoves{c7}{\bchamp}{a9,c9,e9,c8,a7,b7,d7,e7,c6,a5,c5,e5}
\showmoves{h2}{\knight}{g4,i4,j3,j1,i0,g0,f1,f3}
\showmoves{h7}{\wwiz}{g9,i9,j8,j6,i5,g5,f6,f8,i8,i6,g6,g8}
\end{tikzpicture}
\end{document}