The bluegammon.logic package contains logic aspects of the backgammon game.

Concepts and Structures

The central class in this package is the BoardMediator - this class is active during game play and mediates between the BoardState class and the BoardCanvas class in the bluegammon.gui package.

The BoardMediator is accessed statically since it itself do not hold any state. The logic game state belongs to the BoardState singleton. This class is updated instantly upon changes, e.g. piece movements. The gui state belongs to the BoardCanvas singleton, and can have transient states - for example, when a piece is moved, it is not registered on destination in the BoardCanvas until the movement animation has finished.

The BoardState can be observed by a BoardStateListener, which is reported upon backgammon events, piece movements, change in turns, finish of game, etc. The BoardMediator implements this interface and starts appropriate animations or sets the appropriate gui state in the BoardCanvas on events. The BoardCanvas in turn reports user interaction to a LocalPlayer, which, depending on the gui or board state, invokes actions on the BoardMediator.

As for the actual backgammon logic, the classes Board, BoardState, and Rules comprises the representation of a backgammon board, manipulation of pieces, Player and turns, and special rules, respectively.