5.3 Subsystem Rules (Blackbox)


This subsystem accounts for the rules of chess according to the International Chess Federation (FIDE). It determines all valid moves for a position and decides whether it is a check, a checkmate or a stalemate.


The subsystem provides its functionality via the Java interface

Default implementation of the interface is class

Interface ChessRules Fig.: Interface ChessRules

Method Short description
getStartingPosition Returns the starting position of the game. White begins.
getLegalMoves Returns the set of all legal moves for a given position. The current player is determined from the position parameter. In case of a mate or stalemate an empty collection is the result. Thus the method never returns null.
isCheck Checks whether the king of the given colour is attacked by the opponent.
isCheckmate Checks whether the given position is a mate. I.e. the king of the current player is under attack, and no legal move changes this. The player to move has lost the game.
isStalemate Checks whether the given position is a stalemate. I.e. the current player has no valid move, but the king is not under attack. The game is considered a draw.

Table: Methods of interface ChessRules

→ Concept 8.2 Chess Domain Model describes the types used in the interface as call and return parameters (Move, Position, Colour). Refer to the source code documentation (javadoc) for more details.


The implementation is located below the packages

Open Issues

Apart from the stalemate, the subsystem can not recognize any draw. In particular, the following rules are not implemented (→ Risk 11.2 “Risk: Effort of implementation”):

  • 50 moves rule
  • Threefold repetition