public Data GenerateFloor(int floorCount) { var data = new Data(); data.buildItems = new List <WarehouseBuildItemRequest>(); var newGrounds = Enumerable.Repeat(MaxSize, MaxSize) .Select(x => Enumerable.Repeat(false, x).ToList()) .ToList(); // Start with middle newGrounds[(int)(MaxSize * 0.5f)][(int)(MaxSize * 0.5f)] = true; var placementScores = new Dictionary <Vector2Int, PlacementScore>(); var randSeed = (int)(DateTime.UtcNow - DateTime.UtcNow.Date).TotalMilliseconds; Debug.Log("seed: " + randSeed); var rand = new System.Random(randSeed); var skipCount = 0; for (var i = 1; i < floorCount; ++i) { newGrounds.ForEach((val, position) => { placementScores[position] = PlacementScore.CalculateScore(newGrounds, position); }); var newPlacementPosition = PlacementScore.ChoosePlacement(placementScores, rand); if (newPlacementPosition == null) { ++skipCount; continue; } newGrounds[newPlacementPosition.Value.x][newPlacementPosition.Value.y] = true; } if (skipCount > 0) { Debug.Log($"WarehouseManager.GenerateFloor-> Skipped {skipCount} attempts."); } // newGrounds[2][2] = false; // newGrounds[1][1] = true; // newGrounds[2][1] = true; newGrounds = newGrounds.Where(x => x.Any(y => y)).ToList(); if (newGrounds.HasItems()) { var count = newGrounds[0].Count - 1; for (var i = count; i >= 0; --i) { if (newGrounds.All(x => !x[i])) { newGrounds.ForEach(x => x.RemoveAt(i)); } } } data.columns = newGrounds.Count; data.rows = newGrounds[0].Count; data.missingGround = newGrounds.ForEach((ground, position) => { return(ground ? null : new WarehouseMissingGround(position.x, position.y)); }) .WithNonNull() .ToHashSet(); return(data); }
public PlacementNode(TextureAtlasNode sourceNode) { SourceNode = sourceNode; Score = new PlacementScore(); Placement = new PlacementPosition(0, 0, false, 0, 0); }