Esempio n. 1
0
        /// <summary>
        /// Run when we have picked a node to solve when it's in the same position as the goal node.
        /// This will set up all the node information which can be returned to provide a solution.
        /// </summary>
        /// <param name="nextNode">Next open node in the solution.</param>
        private void FinaliseNodeDetails(Node <T> nextNode)
        {
            _traceManager.WriteLine("FinaliseNodeDetails", "path");
            _goalNode.Parent   = nextNode.Parent;
            _goalNode.ComeFrom = nextNode.ComeFrom;
            if (nextNode != _startNode)
            {
                Node <T> nodeChild  = _goalNode;
                Node <T> nodeParent = _goalNode.Parent;
                while (nodeChild != _startNode)
                {
                    // Set the direction
                    switch (nodeChild.ComeFrom)
                    {
                    case Direction.South:
                        nodeParent.GoTo = Direction.North;
                        break;

                    case Direction.North:
                        nodeParent.GoTo = Direction.South;
                        break;

                    case Direction.West:
                        nodeParent.GoTo = Direction.East;
                        break;

                    case Direction.East:
                        nodeParent.GoTo = Direction.West;
                        break;

                    case Direction.Up:
                        nodeParent.GoTo = Direction.Down;
                        break;

                    case Direction.Down:
                        nodeParent.GoTo = Direction.Up;
                        break;

                    case Direction.Nowhere:
                        nodeParent.GoTo = Direction.Nowhere;
                        break;
                    }
                    _finalDirections.AddFirst(nodeParent.GoTo);
                    nodeChild  = nodeParent;
                    nodeParent = nodeParent.Parent;
                }
            }
            _traceManager.DisplayContentsOfLinkedList(_finalDirections, "path");
            _searchState = SearchState.SearchStateSucceeded;
        }