예제 #1
0
    public List <IMazeElement> FindPath()
    {
        startMazeElement.PathFindWeight = 0;
        openCloseListController.AddToOpenList(startMazeElement);

        while (openCloseListController.OpenListCount() > 0 && destinationReach == false)
        {
            IMazeElement currentMazeElement = openCloseListController.GetMazeElementWithLowestWeight();

            Debug.Log(currentMazeElement.Index);
            openCloseListController.RemoveFirstElementFromOpenList(currentMazeElement);
            openCloseListController.AddToCloseList(currentMazeElement);

            pathFindProcessMetric.IncreaseNumberOfVisitedNodes();
            if (currentMazeElement == destinationMazeElement)
            {
                destinationReach = true;
                continue;
            }
            currentMazeElement.Tag = "PathFindSolution";

            neighboursPathFindParametersProcessor.ProcessNeighboursPathFindParameters(currentMazeElement, openCloseListController, pathFindProcessMetric);
        }
        List <IMazeElement> listFromStartToDestination = DestinationPath.GetListFromStartToDestination(destinationMazeElement);

        pathFindProcessMetric.SetPathLengthExpressedInNumberOfNodes(listFromStartToDestination.Count);

        return(listFromStartToDestination);
    }
예제 #2
0
    public List <IMazeElement> FindPath()
    {
        List <IMazeElement> unexploredWalkableMazeElementsList = unexploredMazeElements.GetUnexploredList();
        bool destinationReach = false;

        startMazeElement.PathFindWeight = 0;

        while (unexploredWalkableMazeElementsList.Count > 0 && destinationReach == false)
        {
            unexploredWalkableMazeElementsList.Sort((x, y) => x.PathFindWeight.CompareTo(y.PathFindWeight));
            IMazeElement currentMazeElement = unexploredWalkableMazeElementsList[0];

            pathFindProcessMetric.IncreaseNumberOfVisitedNodes();
            if (currentMazeElement == destinationMazeElement)
            {
                destinationReach = true;
                continue;
            }
            unexploredWalkableMazeElementsList.Remove(currentMazeElement);

            List <IMazeElement> neighbourMazeElementList = planeBuilder.GetNeighboursOfMazeElement(currentMazeElement);

            ProcessNeighboursPathFindParameters(neighbourMazeElementList, unexploredWalkableMazeElementsList, currentMazeElement);
        }

        List <IMazeElement> listFromStartToDestination = DestinationPath.GetListFromStartToDestination(destinationMazeElement);

        pathFindProcessMetric.SetPathLengthExpressedInNumberOfNodes(listFromStartToDestination.Count);

        return(DestinationPath.GetListFromStartToDestination(destinationMazeElement));
    }