Design
We start with the high-level view of a chess engine communicating with a chess program:
The engine is only one part of the system. It sits behind a defined interface and is responsible for understanding and processing chess positions. The full engine architecture looks like this:
The important detail is that the board is part of the engine. We will return to the engine structure later, but for now we can ignore the surrounding system and focus on a single component: the Board. The board itself is not a single monolithic structure. It is composed of several smaller parts, each responsible for a specific aspect of the game state:
Each of these parts can be implemented independently. Together, they form the complete Board.
This process is called decomposition. Instead of attempting to implement the engine as a single unit, we break it down into smaller subsystems. The Board is one of those subsystems, but it is still too large to implement directly in one step. So we decompose it further until we reach components small enough to implement directly using primitive and base types. We then build the larger system from these smaller parts. This approach is used throughout the engine. Every major component (Board, Move Generator, Search, etc) is constructed in the same way.
With that in mind, we can move from structure to implementation.
The first step is to define the Board struct that will contain these components. We will do that in the next section: Board Struct.