Exemplo 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);
    }
Exemplo n.º 2
0
 public AStarPathFinder(
     IMazeElement _startMazeElement,
     IMazeElement _destinationMazeElement,
     IOpenCloseListController _openCloseListController,
     INeighboursPathFindParametersProcessor _neighboursPathFindParametersProcessor,
     IPathFindProcessMetric _pathFindProcessMetric)
 {
     startMazeElement        = _startMazeElement;
     destinationMazeElement  = _destinationMazeElement;
     openCloseListController = _openCloseListController;
     neighboursPathFindParametersProcessor = _neighboursPathFindParametersProcessor;
     pathFindProcessMetric = _pathFindProcessMetric;
 }