# Chess Example

The chess example provided along with the SDK download of Graphiti illustrates how one could build a chess game editor using the Graphiti framework. It registers an editor for this that allows the user to create a chess board, add the initial set of pieces to that board and move them according to the chess rules (note that the order of the moves is not restricted, so you might make two moves of e.g. a light figure without an intermediate dark move). Besides taking the opponents pieces is supported and one can plan moves by drawing move connections; these connections highlight the allowed target squares and allow to connect moves to each other (demonstrating the "connection on connection" feature of Graphiti).")

## Chess Example Plugin

The example plugin org.eclipse.graphiti.examples.chess is available as executable but also as source in the SDK download and within our repository under the examples folder. While the example is easy enough for quickly understanding it, it allows to demonstrate some features of Graphiti that are not explained in the tutorial.

## EMF Model

The plugin contains a small EMF model to define a chess game.

Note that the generated model files were modified at certain spots to ease the example coding:

- The board contains functionality to retrieve a square represented its file and rank realized via an EMF operation
- On creation of a board also all of its squares are created and correctly initialized.
- Squares provide EMF operations to calculate their X- and Y-location for placement on the board.

## Special Graphiti Features

The following special Graphiti features are shown in the Chess example:

- Allowing and restricting moving and resizing on squares and pieces; for pieces only moves are allowed that are allowed in chess.
- A usecase for the hooks during connection creation is shown in CreateChessMoveFeature; this is used to highlight squares a move is allowed to.
- How to connect a connection to another connection is also shown in the CreateChessMoveFeature.
- The ChessFeatureProvider shows how it is possible to disable the delete functionality in the UI and still be able to programmatically use it via the Graphiti framework.