Introduction
To be able to play the game, the engine has to know the board layout, where all of the pieces are located throughout the game, and all relevant information about each position. In the case of Western Chess, the board and pieces are the following:
- A board is 8 by 8 squares (64 in total), alternating in a light and dark color. The squares are normally called light/white or dark/black, even if the squares on a real board often have other colors.
- A set of pieces consists of 1 king, 1 queen, 2 rooks, 2 bishops, 2 knights and 8 pawns. The two sets are given distinct colors to differentiate them during play. Same as with the squares, these sets are normally called white and black, even if they have other colors.

Credits: Photographed it
myself using a Canon DSLR
Sidenote: Mentioning this explicitly may seem pedantic, but there are lots of different chess-like games: for example, there is Chinese Chess (XiangQi) and its cousin Korean Chess (Janggi), Japan has its own version called Shogi, which has different variants. Of course we have the ancestors of Western Chess, Shatranj and Chaturanga. If you still haven’t had enough, there is Thai chess (Makruk) and even Fairy Chess with lots of different board sizes and pieces. A unique chess-like game is Arimaa, which was specifically created to be more difficult for computers than Western Chess. I’m sure I still didn’t mention more than a few chess-like games, but I don’t want this sidenote to become a chapter on its own.
And… for all of these games, engines have been written. Some engines even play more than one chess variant. The variant of chess the engine plays can influence the board representation you choose to use. Now you see why it’s important to clarify that Rustic plays Western Chess. (In the future it may support one variant of Western Chess: Fischer Random Chess, also called Chess960.)
The nice thing is that, if you understand how to implement one variant, you can implement whatever variant you want… but with some variants, you may have problems finding a user interface to use with your engine.
The data structure used by the engine to track the location of the pieces and other information about the ongoing game is called the board representation. It can be constructed in many different ways. The most obvious and intuitive would be to just give every piece its own number, and put all of them in an 8x8 array, like this (in pseudo-code):
// Empty square
const ES = 0
// White pieces
const WK = 1; // King
const WQ = 2; // Queen
const WR = 3; // Rook
const WB = 4; // Bishop
const WN = 5; // Knight
const WP = 6; // Pawn
// Black pieces
const BK = 7;
const BQ = 8;
const BR = 9;
const BB = 10;
const BN = 11;
const BP = 12;
// Starting position
board = [
[BR, BN, BB, BQ, BK, BB, BN, BR],
[BP, BP, BP, BP, BP, BP, BP, BP],
[ES, ES, ES, ES, ES, ES, ES, ES],
[ES, ES, ES, ES, ES, ES, ES, ES],
[ES, ES, ES, ES, ES, ES, ES, ES],
[ES, ES, ES, ES, ES, ES, ES, ES],
[WP, WP, WP, WP, WP, WP, WP, WP],
[WR, WN, WB, WQ, WK, WB, WN, WR]
];
This is easy to understand and it will work. Lots of board representations have been devised in the last 60 years. See the page about Board Representation on the Chess Programming Wiki for more information.
Every board representation comes with its own strengths and weaknesses. A strength can be as simple as “easy to understand” or “easy to write code for”, while a weakness can be “uses lots of memory” or “very slow to use for move generation.” The choice of board representation depends on what you want to optimize.
In Rustic, we use the bitboard approach (CPW page) to achieve maximum speed. At first this is harder to understand compared to the array approach mentioned above, but once you are familiar with it, this representation becomes very natural to work with and write code for. Modern computers are 64-bit, and a (Western!) chess board has 64 squares… this is a match made in heaven.
Now that you know what a board representation is, why we need it, and which sort of representation we will be using, we can start looking into how Rustic tackles this part of the engine. The next section will explain how the board representation is organized.