如何在棋盘上画出皇后的走法?

如何在棋盘上画出皇后的走法?

我在网上看到一个讲座,题目是使用回溯法解决 8 皇后问题。下面是棋盘的图。如何使用 Latex 制作它?(我尝试使用 Chessboard 包,但结果非常不同)

\documentclass{article}
\usepackage{chessboard}
\storechessboardstyle{8x8}{maxfield=d8}
\begin{document}
\chessboard[style=4x4,setwhite={Qd4}, pgfstyle=straightmove,
arrow=to,linewidth=0.2ex,
color=red,
pgfstyle=straightmove,
markmoves={d4-h8,d4-a7,d4-a1,d4-g1,d4-d8,d4-d1,d4-a4,d4-h4},
shortenstart=1ex,showmover=false]
\end{document}

在此处输入图片描述

答案1

也许是一个开始:

\documentclass{standalone}
\usepackage[LSB,LSBC3,T1]{fontenc}
\usepackage{chessboard}
\storechessboardstyle{8x8}{%
  maxfield=h8,
  borderwidth=10mm,
  boardfontencoding=LSBC3,
  color=white,
  colorwhitebackfields,
  color=black,
  colorblackbackfields,
  blackfieldmaskcolor=black,
  whitepiececolor=yellow,
  whitepiecemaskcolor=red,
  addfontcolors,
  pgfstyle=border,
  color=white,
  markregion=a1-h8,
  }
\begin{document}
  \chessboard[
    style=8x8,
    setwhite={Qa8,Qb4,Qc1,Qd3,Qe6,Qf2,Qg7,Qh5},
    pgfstyle=straightmove,
    arrow=stealth,
    linewidth=.5ex,
    padding=1ex,
    color=blue!75!white,
    pgfstyle=straightmove,
    shortenstart=1ex,
    showmover=true,
    markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3},
  ]
\end{document}

更精致的棋盘

对于更直的箭:

\documentclass{standalone}
\usepackage[LSB,LSBC3,T1]{fontenc}
\usepackage{chessboard}
\usetikzlibrary{arrows.meta}
\makeatletter
\cbDefinePgfMoveStyle{mystraightmove}{%
    \pgfsetlinewidth{\board@pgf@linewidth}%
    \setlength\len@board@tempx{\dimexpr 0.1em + \board@pgf@shortenstart \relax}%
    \pgfsetshortenstart{\len@board@tempx}%
    \setlength\len@board@tempx{\board@pgf@shortenend}%
    \pgfsetshortenend{\len@board@tempx}%
    \pgfsetarrowsend{\board@pgf@arrow}%
    \pgfsetrectcap
    \pgfpathmoveto{\pgfpointorigin}%
    \pgfpathlineto{\pgfpointanchor{#1}{center}}%
    \pgfusepath{stroke}}%
\makeatother
\storechessboardstyle{8x8}{%
  maxfield=h8,
  borderwidth=10mm,
  boardfontencoding=LSBC3,
  color=white,
  colorwhitebackfields,
  color=black,
  colorblackbackfields,
  blackfieldmaskcolor=black,
  whitepiececolor=yellow,
  whitepiecemaskcolor=red,
  addfontcolors,
  pgfstyle=border,
  color=white,
  markregion=a1-h8,
  }
\begin{document}
  \chessboard[
    style=8x8,
    setwhite={Qa8,Qb4,Qc1,Qd3,Qe6,Qf2,Qg7,Qh5},
    pgfstyle=mystraightmove,
    linewidth=.5ex,
    padding=1ex,
    color=blue!75!white,
    arrow={Triangle[width=1.5ex, length=1ex]},
    shortenstart=1ex,
    shortenend=-.5ex,
    showmover=false,
    markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3},
  ]
\end{document}

更直的箭

我试图找出一种方法将箭头包裹在 pgf 透明组中,这样我就可以让它们部分透明而不会出现奇怪的效果。然而,当我尝试这样做时,箭头完全消失了,我不明白为什么。

相关内容