Storing the board state of Hexagonal chess in a multi-dimensional array

104 Views Asked by At

Chess is normally played on a square board. This means, the board state can be easily represented in a square 8x8 2-dimensional array.

On the other hand, Gliński's hexagonal chess is played on a hexagonal board.

A hexagonal chess board with 91 hexagons

I want to store this position in a multi-dimensional array. That is, an array with a specific length in each dimension.

I want the distance between chess pieces in the array to represent their actual distance on the chess board as closely as possible.

That means, a 91x1 array would superficially solve the problem but would not be representative of their actual locations on the board.

1

There are 1 best solutions below

3
On

Use oblique axes (with $120°$ angle instead of $90°$) with origin $O$ in the center of the grid and $x$ axis pointing to the cell numbered 6 in the North-East corner, $y$ axis pointing to the cell numbered 6 in the North-West corner.

For example, the cell where the Black Queen stays has (oblique) coordinates $(4,5)$, the cell where the White King stays has (oblique) coordinates $(-4,-5)$.

A move will be given by adding a vector to the present position

$$\begin{pmatrix}x\\y\end{pmatrix} \to \begin{pmatrix}x+a\\y+b\end{pmatrix}$$

with one of the following 6 forms:

$$\begin{pmatrix}a\\b\end{pmatrix}=\begin{pmatrix}1\\1\end{pmatrix} \ \text{or} \ \begin{pmatrix}1\\0\end{pmatrix} \ \text{or} \ \begin{pmatrix}-1\\0\end{pmatrix} \ \text{or} \ \begin{pmatrix}0\\1\end{pmatrix} \ \text{or} \begin{pmatrix}0\\-1\end{pmatrix} \ \text{or} \ \ \begin{pmatrix}-1\\-1\end{pmatrix}.$$

Coordinates $(x,y)$ are limited in this way:

$$\begin{cases}-5 \le x \le 5\\-5 \le y \le 5\\-5 \le x-y \le 5\end{cases},$$

the last line inequalities being due to vertical sides.