private void BuildCorridor(IMap map, MapCell currentCell)
        {
            MapCell nextCell;
            var direction = Dir.Zero;

            bool success;
            do
            {
                _directionPicker.LastDirection = direction;
                _directionPicker.ResetDirections();
                var emptySide = currentCell.Sides
                    .Single(s => s.Value != Side.Wall)
                    .Key;
                success = false;
                do
                {
                    direction = _directionPicker.NextDirectionExcept(emptySide);
                    success = map.TryGetAdjacentCell(currentCell, direction, out nextCell);

                    if (success)
                    {
                        map.CreateCorridorSide(currentCell, nextCell, direction, Side.Empty);
                    }
                } while (_directionPicker.HasDirections && !success);

                if (!success)
                {
                    return;
                }
            } while (currentCell.IsDeadEnd);
        }
        private void BuildCorridors(IMap map)
        {
            if (map.Any(c => c.IsVisited))
            {
                throw new InvalidOperationException(
                    "Map should not contain visited cells.");
            }

            MapCell nextCell;
            var direction = Dir.Zero;

            var currentCell = map.PickRandomCell();
            map.Visit(currentCell);
            bool success;
            do
            {
                _directionPicker.LastDirection = direction;
                _directionPicker.ResetDirections();
                success = TryPickRandomUnvisitedAdjacentCell(
                    map, currentCell, out nextCell, out direction);
                if (success)
                {
                    map.CreateCorridorSide(currentCell, nextCell, direction, Side.Empty);
                    map.Visit(nextCell);
                    currentCell = nextCell;
                    nextCell = null;
                }
                else
                {
                    currentCell = map.PickNextRandomVisitedCell(currentCell);
                }
            }
            while (!map.AllVisited);
        }