Пример #1
0
 private void AddAdjacentCellToOpenList(Node parentNode, int gCost, int cellIndex)
 {
     /* TODO:
      * 1) Create a new node with the cellIndex and parentNode, include the G and H values for the node
      * 2) calculate F for the node
      * 2) finally add to open list
      */
 }
Пример #2
0
        private void ExploreNode(Node parentNode, int columnOffset, int rowOffset, int gCost)
        {
            var adjacentCellIndex = _map.GetAdjacentCellIndex(parentNode.CellIndex, columnOffset, rowOffset);

            // Ignore unwalkable nodes (or nodes outside the grid)
            if (adjacentCellIndex == -1)
                return;

            // TODO: Ignore nodes on the closed list

            if (OpenUpdatePathCost(parentNode, gCost, adjacentCellIndex))
                return;

            AddAdjacentCellToOpenList(parentNode, gCost, adjacentCellIndex);
        }
Пример #3
0
        public void CalculatePath()
        {
            /*
             * TODO:
             * 1) Create the first node using the StartCell property in Map, the parent should be null since its the starting node
             * 2) set the _current node to the node you just created
             */
            var node = new Node(_map.StartCell, null);
            _openList.Add(node);
            _currentNode = node;

            while (true)
            {
                /* TODO
                 * if the open list has no nodes in it break out of the loop
                 *
                 * Find the Node with the smallest F in the open list and set it to _currentNode
                 * If that node has the same cell index as the target cell (in _map) break out of the loop
                 *
                 * Remove the _currentNode from the open list and add it to the closed list
                 * Add all of the nodes adjacent to the _currentNode to the open list
                 *
                 *
                 */

                ExploreNode(_currentNode, -1, -1, 14);
                ExploreNode(_currentNode, 0, -1, 10);
                ExploreNode(_currentNode, 1, -1, 14);
                ExploreNode(_currentNode, -1, 0, 10);
                ExploreNode(_currentNode, 1, 0, 10);
                ExploreNode(_currentNode, -1, 1, 14);
                ExploreNode(_currentNode, 0, 1, 10);
                ExploreNode(_currentNode, 1, 1, 14);
            }
            _map.HighlightPath(_currentNode);
        }
Пример #4
0
 public void HighlightPath(Node node)
 {
     var currentNode = node;
     while (currentNode != null)
     {
         _path.Add(currentNode.CellIndex);
         currentNode = currentNode.Parent;
     }
 }
Пример #5
0
        private bool OpenUpdatePathCost(Node parentNode, int gCost, int cellIndex)
        {
            var adjacentNode = _openList.SingleOrDefault(n => n.CellIndex == cellIndex);
            if (adjacentNode != null)
            {
                if (parentNode.G + gCost < adjacentNode.G)
                {
                    adjacentNode.Parent = parentNode;
                    /*
                    * TODO: calculate the values of G and H for adjacentNode
                    */

                }
                return true;
            }
            return false;
        }
Пример #6
0
        private void UpdatePathCost(int cellIndex, Node parentNode, int gCost)
        {
            var adjacentNode = _openList.SingleOrDefault(n => n.CellIndex == cellIndex);

            if (parentNode.G + gCost < adjacentNode.G)
            {
                adjacentNode.Parent = parentNode;
                /*
                    * TODO: calculate the values of G and H for adjacentNode
                    */

            }
        }