# Chess Pieces

A generalisation to the [8 Queens Problem](8-queens-problem), the following images show the ways in which single chess pieces can be placed on increasing board sizes, such that each piece is not being attacked by another. However, unlike the 8 Queens Problem which has a solution, the following images are only coloured by the depth (number of moves), rather than the number of solutions.

## Examples

The following images show the different ways each piece can be placed on a 3x3 and 4x4 board. You can see them and other variations in the [gallery](https://b-faze.github.io/faze/Piece-Board.html).

### Pawn

![](https://218903290-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdM8iXEiSa6vIC3EFqT%2F-MeVKSIqF80WmKJVppCy%2F-MeWGlqwwWtAHPpqaDYK%2Fpawn.png?alt=media\&token=bea3e852-a6fc-48dd-8066-e42cc1c9cb52)

### Knight

![](https://218903290-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdM8iXEiSa6vIC3EFqT%2F-MeVKSIqF80WmKJVppCy%2F-MeWGpkiZkzuF_APb08m%2Fknight.png?alt=media\&token=71e733cc-8bcf-4bfe-9a76-c14e5dd3ba5b)

### Bishop

![](https://218903290-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdM8iXEiSa6vIC3EFqT%2F-MeVKSIqF80WmKJVppCy%2F-MeWGtu04OvEIXsYwc6m%2Fbishop.png?alt=media\&token=d2b986fe-2ee2-47c9-aafa-1dd91f834489)

### Rook

![](https://218903290-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdM8iXEiSa6vIC3EFqT%2F-MeVKSIqF80WmKJVppCy%2F-MeWGwcpjnlq2A5oNXqQ%2Frook.png?alt=media\&token=57a49bdc-d7b6-4d16-8616-f8195aca313b)

### Queen

![](https://218903290-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdM8iXEiSa6vIC3EFqT%2F-MeVKSIqF80WmKJVppCy%2F-MeWGzfD-70HAB85KQZV%2Fqueen.png?alt=media\&token=ebfb071e-2d4a-4f14-a461-a94b2c9a5741)

### King

![](https://218903290-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdM8iXEiSa6vIC3EFqT%2F-MeVKSIqF80WmKJVppCy%2F-MeWH20g0LclJhX2YfjN%2Fking.png?alt=media\&token=2c3be885-2046-4079-a8a4-4d64087c1c7b)

## Pipeline Summary

```csharp
ReversePipelineBuilder.Create()
    .GallerySave(galleryService, galleryMetaData)
    .Render(new SquareTreeRenderer(rendererConfig))
    .Paint(new PiecesBoardPainter())
    .GameTree(new SquareTreeAdapter(boardSize))
    .Build();
```

### Tree Painter

The tree painter used is the type `PiecesBoardPainter`  which converts the game tree into a colour tree using the following code:

```csharp
    public Tree<Color> Paint(Tree<IGameState<GridMove, SingleScoreResult?>> tree)
    {
        var resultTree = tree.MapValue((x, info) =>
        {
            var result = x.GetResult();
            if (result != null)
                return Math.Max(result.Value, 0);

            return info.Depth;
        });

        var maxValue = resultTree
            .GetLeaves()
            .Max(t => t.Value);

        var colorTree = resultTree
            .MapValue(x => (double)x / maxValue)
            .MapValue(colorInterpolator);

        return colorTree;
    }
```

First the game tree is converted into a `resultTree`. Each node in the tree is either represented by the game's result or, if there are still available moves, the current depth. The result returned by the `PiecesBoardState` is a score equal to the number of pieces successfully placed or -1 if placing a piece resulted in an attack.

The result is then turned into a colour by normalising the score against the best possible one and then using a `colorInterpolator` (default for `PiecesBoardPainter` is `GreyscaleInterpolator`)
