public void CreateNatural(List <uint> types) { BoolGrid pathable = Tyr.Bot.MapAnalyzer.Pathable; BoolGrid unPathable = pathable.Invert(); Point2D naturalExit = Tyr.Bot.BaseManager.NaturalDefensePos; BoolGrid naturalWalls = unPathable.GetConnected(new Point2D() { X = 0, Y = 0 }).Crop((int)naturalExit.X - 12, (int)naturalExit.Y - 12, (int)naturalExit.X + 12, (int)naturalExit.Y + 12); List <BoolGrid> sides = naturalWalls.GetGroups(); Dictionary <BoolGrid, int> counts = new Dictionary <BoolGrid, int>(); foreach (BoolGrid side in sides) { counts.Add(side, side.Count()); } sides.Sort((BoolGrid a, BoolGrid b) => counts[b] - counts[a]); List <Point2D> building1Positions = Placable(sides[0], Tyr.Bot.MapAnalyzer.Placement, BuildingType.LookUp[types[0]].Size, false); List <Point2D> building2Positions = Placable(sides[1], Tyr.Bot.MapAnalyzer.Placement, BuildingType.LookUp[types[3]].Size, false); int naturalHeight = Tyr.Bot.MapAnalyzer.MapHeight((int)Tyr.Bot.BaseManager.Natural.BaseLocation.Pos.X, (int)Tyr.Bot.BaseManager.Natural.BaseLocation.Pos.Y); building1Positions = building1Positions.FindAll((p) => Tyr.Bot.MapAnalyzer.MapHeight((int)p.X, (int)p.Y) == naturalHeight); building2Positions = building2Positions.FindAll((p) => Tyr.Bot.MapAnalyzer.MapHeight((int)p.X, (int)p.Y) == naturalHeight); FindWall(types, building1Positions, building2Positions, Tyr.Bot.MapAnalyzer.Placement, false); //DrawResult(unPathable, naturalWalls, building1Positions, building2Positions); }
private void DetermineWall(BoolGrid ramp, BoolGrid unPathable) { BoolGrid rampAdjacent = unPathable.GetAdjacent(ramp); BoolGrid rampSides = unPathable.GetConnected(rampAdjacent, 5); List <BoolGrid> sides = rampSides.GetGroups(); BoolGrid shrunkenStart = StartArea.Shrink(); List <Point2D> building1Positions = Placable(sides[0], shrunkenStart).ToList(); List <Point2D> building2Positions = Placable(sides[1], shrunkenStart).ToList(); float wallScore = 1000; foreach (Point2D p1 in building1Positions) { foreach (Point2D p2 in building2Positions) { if (System.Math.Abs(p1.X - p2.X) < 3 && System.Math.Abs(p1.Y - p2.Y) < 3) { continue; } float newScore = SC2Util.DistanceGrid(p1, p2); if (newScore >= wallScore) { continue; } for (float i = -2.5f; i < 3; i++) { if (CheckPylon(SC2Util.Point(p1.X + 2.5f, p1.Y + i), p1, p2)) { wallScore = newScore; building1 = p1; building2 = p2; building3 = SC2Util.Point(p1.X + 2.5f, p1.Y + i); } if (CheckPylon(SC2Util.Point(p1.X - 2.5f, p1.Y + i), p1, p2)) { wallScore = newScore; building1 = p1; building2 = p2; building3 = SC2Util.Point(p1.X - 2.5f, p1.Y + i); } if (CheckPylon(SC2Util.Point(p1.X + i, p1.Y + 2.5f), p1, p2)) { wallScore = newScore; building1 = p1; building2 = p2; building3 = SC2Util.Point(p1.X + i, p1.Y + 2.5f); } if (CheckPylon(SC2Util.Point(p1.X + i, p1.Y - 2.5f), p1, p2)) { wallScore = newScore; building1 = p1; building2 = p2; building3 = SC2Util.Point(p1.X + i, p1.Y - 2.5f); } } } } }
public void Create(List <uint> types) { foreach (uint type in types) { Wall.Add(new WallBuilding() { Type = type }); } BoolGrid unPathable = Tyr.Bot.MapAnalyzer.UnPathable; BoolGrid ramp = Tyr.Bot.MapAnalyzer.Ramp; BoolGrid rampAdjacent = unPathable.GetAdjacent(ramp); BoolGrid rampSides = unPathable.GetConnected(rampAdjacent, 5); List <BoolGrid> sides = rampSides.GetGroups(); List <Point2D> building1Positions = Placable(sides[0], Tyr.Bot.MapAnalyzer.StartArea, BuildingType.LookUp[types[0]].Size); List <Point2D> building2Positions = Placable(sides[1], Tyr.Bot.MapAnalyzer.StartArea, BuildingType.LookUp[types[2]].Size); float wallScore = 1000; foreach (Point2D p1 in building1Positions) { foreach (Point2D p2 in building2Positions) { if (System.Math.Abs(p1.X - p2.X) < 0.1f + (BuildingType.LookUp[types[0]].Size.X + BuildingType.LookUp[types[2]].Size.X) / 2f && System.Math.Abs(p1.Y - p2.Y) < 0.1f + (BuildingType.LookUp[types[0]].Size.Y + BuildingType.LookUp[types[2]].Size.Y) / 2f) { continue; } float newScore = SC2Util.DistanceGrid(p1, p2); if (newScore >= wallScore) { continue; } Wall[0].Pos = p1; Wall[2].Pos = p2; wallScore = newScore; } } HashSet <Point2D> around1 = new HashSet <Point2D>(); GetPlacableAround(Tyr.Bot.MapAnalyzer.StartArea, Wall[0].Pos, Wall[0].Size, Wall[1].Size, around1); HashSet <Point2D> around2 = new HashSet <Point2D>(); GetPlacableAround(Tyr.Bot.MapAnalyzer.StartArea, Wall[2].Pos, Wall[2].Size, Wall[1].Size, around2); around1.IntersectWith(around2); foreach (Point2D pos in around1) { Wall[1].Pos = new Point2D() { X = pos.X + 0.5f, Y = pos.Y + 0.5f }; break; } }