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); }