public static GridBuilder UpdatedForRequest(this GridBuilder builder, PlacePieceRequest r) { if (r.Piece == PlacePieceRequest.Move.X) { builder.WithXAt(r.Position); } else { builder.WithOAt(r.Position); } return(builder); }
public void Execute(PlacePieceRequest r) { var existingGrid = _persistence.Read(); switch (r?.Piece) { case null: case PlacePieceRequest.Move.O when existingGrid.WhoMovedLast() == Grid.Player.Nobody: case PlacePieceRequest.Move.X when existingGrid.WhoMovedLast() == Grid.Player.PlayerX: return; } if (Grid.PieceType.Blank != existingGrid.Pieces[r.Position]) { return; } var builder = new GridBuilder(existingGrid); _persistence.Save(builder.UpdatedForRequest(r).Build()); }
private void PlacePiece(PlacePieceRequest request) => new PlacePiece(this).Execute(request);