3

Lately I've been getting more and more interested in chess variants (such as Omega chess and Courier chess). How would I go about typesetting the board of such chess variants, and how would I show how a new piece can behave?

hkBst
  • 545
  • 2
  • 10
  • There are some packages. I'll post an answer later. It might be a problem the fact that the omega example has extra pieces like the champion. – Alenanno Jan 24 '16 at 11:39
  • The chessboard is no problem, but the pieces are usually implemented as font characters. An easy (but slow) solution would be to use TikZ. – John Kormylo Jan 24 '16 at 16:00
  • I'm thinking I might have misunderstood your question. Let me know if that's the case. Did you want to know how to type the extra pieces too? I'm afraid the champion doesn't exist in Unicode... – Alenanno Jan 25 '16 at 18:35
  • I have updated the answer to satisfy your second question. – Alenanno Jan 25 '16 at 23:45
  • I found an article which specifically mentions Omega chess and hexagonal chess. – hkBst Feb 23 '16 at 17:59

1 Answers1

7

I did the chessboard for the Omega class, the other one should be easy to obtain if you modify this code appropriately.

The size of the chessboard is determined by the line:

\newcommand{\maxx}{10}

It will create a 10x10 board, (A-J, 0-9). Note: if you have a piece on the board and you reduce the number in a way that the piece would be "outside" of the board, you'll get an error. So if you have a 8x8 board, you cannot have a piece on h9.

As was suggested in the comments, the pieces are font characters, so for the extra characters you might have to find a font that supports them, or create them in some other way. For the champion, I uploaded a .eps picture to the document. You can get an .svg from the Wikipedia page (under Creative Commons) and convert it to that format so you can include it. Remember to remove the background color.

Commands

  1. Show all possible moves

    \showmoves{<position>}{<piece>}{<list of coordinates>}
    

    This command defines a single piece placed at position followed by a list of coordinates (in the form of c5 for example), which show all the squares the current piece can move to.

  2. Single move

    \showmoves{<position>}{<piece>}{<coordinate>}
    

    An example would be \showmoves{c1}{\pawn}{c2}. If the piece is \knight, the arrow that indicates the move will be automatically squared. In all other cases, it'll be a straight line. This was decided in order to be consistent with how moves are usually indicated in chess guides.

  3. Piece positioning

    \showmoves{<position>}{<piece>}{} % <-- this must be there, even if empty
    

As you will see in the output below, you can write for example \showmoves{c1}{\rook}{} and it will place the piece without any moves.

Changes (in chronological order):

  • Switch to a single command to show positioning, single moves or moves list;
  • Included code for typesetting knight "squared" movements (later used for the wizard piece).

    For the moment, the four "straight" edges for the wizard must be indicated last.

Known issues:

I don't know why, but the squares are slightly shifted. I'll fix the code as soon as I identify the cause.

Output

enter image description here

Code

\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}
Alenanno
  • 37,338
  • I found http://graphicdesign.stackexchange.com/questions/7168/how-to-convert-svg-to-eps about converting the svg to eps format. Basically says to use inkscape. Is that what you did to do the conversion? – hkBst Jan 27 '16 at 17:16
  • About the line: \pgfmathsetmacro\color{mod(\y + \x, 2) ? "dark" : "light"}. The " quote marks got auto converted in my emacs to `` and '', so I had to resort to insert-char QUOTATION-MARK to correct this issue. – hkBst Jan 27 '16 at 17:16
  • @hkBst ah OK. I don't use Emacs. For the conversion, I don't have inkscape, so I used a website. I can link it to you if you want. – Alenanno Jan 27 '16 at 17:27
  • yeah that might save me some trouble :) – hkBst Jan 27 '16 at 17:57
  • @hkBst http://image.online-convert.com/convert-to-eps – Alenanno Jan 27 '16 at 20:13
  • BTW the wizard makes a (1,3) jump, not a (1,2) like the knight. – hkBst Jan 31 '16 at 11:18