/// <summary> /// Finds the shortest path from the given start to the given goal. /// Does not include the "start" pos in the list. /// Returns "null" if a path wasn't found. /// IMPORTANT: The returned list is reused for other calls to this method, /// so treat it as a temp variable! /// </summary> /// <param name="heuristicCalc"> /// The heuristic/path length calculator, /// or "null" if the default one (manhattan distance) should be used. /// </param> public List <Vector2i> FindPath(Vector2i start, Pathfinding.Goal <Vector2i> goal, Pathfinding.PathFinder <Vector2i> .CostCalculator heuristicCalc = null) { return(FindPath(start, goal, tempPath, heuristicCalc) ? tempPath : null); }
public static void InitializeLayerPathing(ConfigSettings config, Polygons extraPathingConsideration, List <ExtruderLayers> extruders) { for (int layerIndex = 0; layerIndex < extruders[0].Layers.Count; layerIndex++) { if (MatterSlice.Canceled) { return; } LogOutput.Log("Generating Outlines {0}/{1}\n".FormatWith(layerIndex + 1, extruders[0].Layers.Count)); long avoidInset = config.ExtrusionWidth_um * 3 / 2; var allOutlines = new Polygons(); for (int extruderIndex = 0; extruderIndex < extruders.Count; extruderIndex++) { allOutlines.AddRange(extruders[extruderIndex].Layers[layerIndex].AllOutlines); } var boundary = allOutlines.GetBounds(); var extraBoundary = extraPathingConsideration.GetBounds(); boundary.ExpandToInclude(extraBoundary); boundary.Inflate(config.ExtrusionWidth_um * 10); var pathFinder = new Pathfinding.PathFinder(allOutlines, avoidInset, boundary, config.AvoidCrossingPerimeters); // assign the same pathing to all extruders for this layer for (int extruderIndex = 0; extruderIndex < extruders.Count; extruderIndex++) { extruders[extruderIndex].Layers[layerIndex].PathFinder = pathFinder; } } }
public static void Initialize() { _boardTiles = new BoardTile(); SetUpTheTiles(); Figures = new FigureGraph(); AllFigures = new List <Figure>(); _activeAllyFigures = new List <Figure>(); _activeEnemyFigures = new List <Figure>(); Pathfinding.PathFinder pathFindingAlgorithm = new Pathfinding.PathFinder(new Dijkstra(8, 8, 8)); pathFindingAlgorithm.SetGraph(Figures); MatchManager.Instance.OnStateChage += matchState => { switch (matchState) { case Enums.MatchState.Preparation: RecoverFromBattle(); List <Figure> sacrifices = new List <Figure>(); foreach (Figure figure in AllFigures) { sacrifices.AddRange(CheckForUpgrades(figure, false)); } foreach (Figure figure in sacrifices) { AllFigures.Remove(figure); } foreach (Figure figure in _activeEnemyFigures) { figure.Destroy(); } break; case Enums.MatchState.Disposal: SellExcessFigures(); break; case Enums.MatchState.Stretching: PrepareForBattle(); break; case Enums.MatchState.Battle: if (_activeAllyFigures.Count == 0) { TakeDamage(); } break; } }; _pieceCounter = new PieceCounter(); }
/// <summary> /// Outputs the shortest path from the given start to the given goal /// into the "outPath" list. /// Does not include the "start" pos in the list. /// Returns whether a path was actually found. /// </summary> /// <param name="heuristicCalc"> /// The heuristic/path length calculator, /// or "null" if the default one (manhattan distance) should be used. /// </param> public bool FindPath(Vector2i start, Pathfinding.Goal <Vector2i> goal, List <Vector2i> outPath, Pathfinding.PathFinder <Vector2i> .CostCalculator heuristicCalc = null) { if (heuristicCalc == null) { pathing.CalcCosts = Graph.AStarEdgeCalc; } else { pathing.CalcCosts = heuristicCalc; } return(pathing.FindPath(start, goal, float.PositiveInfinity, false, outPath)); }
private void CommonInit() { Groups = new Group.GroupSet(this); IsPaused = new Stat <bool, Map>(this, false); pathingGraph = new Graph(this); pathing = new Pathfinding.PathFinder <Vector2i>(pathingGraph, null); unitsByPos = new GridSet <Unit>(Tiles.Dimensions); //When the tile grid changes size, reset "unitsByPos". Tiles.OnTileGridReset += (grid, oldSize, newSize) => { unitsByPos = new GridSet <Unit>(newSize); foreach (Unit u in units) { unitsByPos.AddValue(u, u.Pos); } }; }