public static Pather.AStar Search(IEnumerable <Point> starts, int stepSize, Point goal, int goalRange, bool avoidPools = true) { var goalEdge = Trig.CalcInnerEdgeOfCircle(new Circle(goal, goalRange)); var additionalNeighboors = goalEdge.Where(n => IsPassable(n)).ToHashSet(); Func <Point, IEnumerable <Point> > getNeighboors = p => { return(Trig.CalcInnerEdgeOfCircle(new Circle(p, stepSize)) .Concat(additionalNeighboors) .Where(n => IsPassable(n, avoidPools) && Trig.IsInRange(p, n, stepSize))); }; var astar = new Pather.AStar( starts, p => Trig.IsInRange(p, goal, goalRange), (a, b) => 1, p => (int)Math.Ceiling(Trig.Distance(p, goal) / (double)stepSize), getNeighboors); return(astar); }
public static Point Spawn(int plantType, Point goal, int goalRange, bool avoidPools = true) { if (AI.me.Spores < AI.sporeCosts[plantType]) { return(new Point(-1, -1)); } var uprootRange = Bb.GetUprootRange(plantType); var starts = Bb.ourMother.Concat(Bb.ourSpawners); var goalEdge = Trig.CalcInnerEdgeOfCircle(new Circle(goal, goalRange)); var additionalNeighboors = goalEdge.Where(n => IsPassable(n)).ToHashSet(); Func <Point, IEnumerable <Point> > getNeighboors = p => { var stepSize = Bb.plantLookup.ContainsKey(p) ? p.GetPlant().Range : uprootRange; return(Trig.CalcInnerEdgeOfCircle(new Circle(p, stepSize)) .Concat(additionalNeighboors) .Where(n => IsPassable(n, avoidPools) && Trig.IsInRange(p, n, stepSize))); }; var astar = new Pather.AStar( starts, p => Trig.IsInRange(p, goal, goalRange) && IsPassable(p, avoidPools), (a, b) => 1, p => (int)Math.Ceiling(Trig.Distance(p, goal) / (double)uprootRange), getNeighboors); if (astar.Path.Count() > 1) { var p = astar.Path.ElementAt(1); AI.me.germinate(p.x, p.y, plantType); Bb.spawning.Add(p); return(p); } return(new Point(-1, -1)); }