“The game of chess is played between two opponents who move their pieces on a square board called a ‘chessboard’.””
from the FIDE Laws of Chess
The different modules of DokChess exchange chess-specific data. This includes the game situation on the chessboard (position) for instance, as well as opponent’s and own moves. All interfaces use the same domain objects as call and return parameters.
This section contains a brief overview of these data structures and their relationships. All the classes and enumeration types (enums) are located in the org.dokchess.domain package. See the source documentation (javadoc) for details.
A chess piece is characterized by colour (black or white) and type (king, queen, and so on). In the DokChess domain model, a piece does not know its location on the board. The Piece class is immutable, and so are all other domain classes.
Fig.: A piece has a colour and a type
A chessboard consists of 8 x 8 squares, which are arranged in 8 rows called ranks (1-8) and 8 columns called files (a-h). The Square class describes one of these. Since a square can be occupied by only one piece, source and target squares are sufficient to specify a move (the Move class). The only exception is the promotion of a pawn on the opponent’s baseline. Here, the player decides which piece type they want to convert the pawn to (typically, but not necessarily, a queen). Castling moves are represented as king moves over two squares in the corresponding direction. The additional attributes for the moving piece and whether the move is a capture are useful for the analysis tasks of the engine.
Fig.: A move from square to square
The Position class describes the current situation on the board. In particular, these are the piece locations on the board, which are internally represented as a two-dimensional array (8 x 8). If a square is not occupied, null is stored in the array. To complete the game situation, the Position class includes information about which side moves next, which castlings are still possible (if any), and whether capturing en passant is allowed.
Fig.: A position describes a game state
The Position class is immutable as well. Therefore, the performMove() method returns a new position with the modified game situation (→ decision V.9.2 “Are position objects changeable or not?”).