Esempio n. 1
0
    public void ProcessNeighboursPathFindParameters(
        IMazeElement currentMazeElement,
        IOpenCloseListController openCloseListController,
        IPathFindProcessMetric pathFindProcessMetric
        )
    {
        List <IMazeElement> neighbourMazeElementList = planeBuilder.GetNeighboursOfMazeElement(currentMazeElement);

        foreach (IMazeElement neighbourMazeElement in neighbourMazeElementList)
        {
            if (!openCloseListController.CloseListContains(neighbourMazeElement) && !neighbourMazeElement.IsMazeWall)
            {
                int   discanceToNeighbour = 1;
                float newNeighbourWeight  = currentMazeElement.PathFindWeight + discanceToNeighbour;

                if (newNeighbourWeight < neighbourMazeElement.PathFindWeight || !openCloseListController.OpenListContains(neighbourMazeElement))
                //(openCloseListController.OpenListContains(neighbourMazeElement) && neighbourMazeElement.PathFindWeight < newNeighbourWeight) //||
                //openCloseListController.CloseListContains(neighbourMazeElement) && neighbourMazeElement.PathFindWeight < newNeighbourWeight)
                {
                    neighbourMazeElement.PathFindWeight            = newNeighbourWeight;
                    neighbourMazeElement.PathFindDistanceHeuristic = aStarDistanceHeuristic.GetDistanceBetween(neighbourMazeElement, destinationMazeElement);
                    neighbourMazeElement.PathFindParent            = currentMazeElement;

                    if (!openCloseListController.OpenListContains(neighbourMazeElement))
                    {
                        openCloseListController.AddToOpenList(neighbourMazeElement);
                    }
                }
            }
        }
        pathFindProcessMetric.ProcessJunctionParametersBaseOn(neighbourMazeElementList);
    }
Esempio n. 2
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);
    }