/// <summary> /// Create a path finder /// </summary> /// <param name="map">The map to be searched</param> /// <param name="maxSearchDistance">The maximum depth we'll search before giving up</param> /// <param name="allowDiagMovement">True if the search should try diaganol movement</param> /// <param name="heuristic">The heuristic used to determine the search order of the map</param> public AStarPathFinder(ITileBasedMap map, int maxSearchDistance, bool allowDiagMovement, IAStarHeuristic heuristic) { Unit = GameMap.Soldier; _map = map; _maxSearchDistance = maxSearchDistance; _allowDiagMovement = allowDiagMovement; _heuristic = heuristic; _nodes = new Node[_map.GetWidthInTiles(), _map.GetHeightInTiles()]; for (var i = 0; i < _map.GetWidthInTiles(); i++) { for (var j = 0; j < _map.GetHeightInTiles(); j++) { _nodes[i, j] = new Node(i, j); } } }
public float GetCost(ITileBasedMap map, int x, int y, int tx, int ty) { return(Mathf.Abs(tx - x) + Mathf.Abs(ty - y)); }
/// <summary> /// Create a path finder with the default heuristic - closest to target. /// </summary> /// <param name="map">The map to be searched</param> /// <param name="maxSearchDistance">The maximum depth we'll search before giving up</param> /// <param name="allowDiagMovement">True if the search should try diaganol movement</param> public AStarPathFinder(ITileBasedMap map, int maxSearchDistance, bool allowDiagMovement) : this(map, maxSearchDistance, allowDiagMovement, new ClosestHeuristic()) { }