Exemplo n.º 1
0
        /// <summary>
        /// 数据来源AStar 表格地图的直线寻路结果
        /// </summary>
        /// <returns><c>true</c>, if path was found, <c>false</c> otherwise.</returns>
        /// <param name="grid">Grid.</param>
        public bool FindPath(CStarGrid grid)
        {
            CStarNode startNode = grid.StartNode;
            CStarNode endNode   = grid.EndNode;

            SetData(startNode.Col, startNode.Row, endNode.Col, endNode.Row);
            return(Find(grid));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds the path.
        /// result do not has the start node itself
        /// </summary>
        /// <returns><c>true</c>, if path was found, <c>false</c> otherwise.</returns>
        /// <param name="grid">传入需要进行寻路的地图</param>
        /// <param name="closeToDestination">If set to <c>false</c>, 寻路结果不包含终点</param>
        public bool FindPath(CStarGrid grid, bool closeToDestination = false)
        {
            m_grid            = grid;
            m_findClosestNode = closeToDestination;
            m_open.Clear();
            m_closed.Clear();

            m_startNode = m_grid.StartNode;
            m_endNode   = m_grid.EndNode;
            //终点不可通行, 我就不寻路了
            if (!m_endNode.Walkable)
            {
                return(false);
            }

            m_startNode.G = 0;
            m_startNode.H = Heuristic(m_startNode);
            m_startNode.F = m_startNode.G + m_startNode.H;
            bool result = Search();

            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 传入地图可通行数据构建寻路对象
 /// </summary>
 public CTilePathPlanner(CStarGrid map)
 {
     m_starGrid = map;
 }
Exemplo n.º 4
0
 /// <summary>
 /// 初始化整个系统
 /// </summary>
 public void Initialize(int mapNumCols, int mapNumRows)
 {
     m_mapWalkableData = new CStarGrid();
     m_mapWalkableData.Init(mapNumCols, mapNumRows);
     m_pathPlanner = new CTilePathPlanner(m_mapWalkableData);
 }