Example #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);
    }
Example #2
0
 public AStarPathFinder(
     IMazeElement _startMazeElement,
     IMazeElement _destinationMazeElement,
     IOpenCloseListController _openCloseListController,
     INeighboursPathFindParametersProcessor _neighboursPathFindParametersProcessor,
     IPathFindProcessMetric _pathFindProcessMetric)
 {
     startMazeElement        = _startMazeElement;
     destinationMazeElement  = _destinationMazeElement;
     openCloseListController = _openCloseListController;
     neighboursPathFindParametersProcessor = _neighboursPathFindParametersProcessor;
     pathFindProcessMetric = _pathFindProcessMetric;
 }
    public DijkstraPathFinder(IPlaneBuilder _planeBuilder,
                              IUnexploredMazeElements _unexploredMazeElements,
                              IMazeElement _startMazeElement,
                              IMazeElement _destinationMazeElement,
                              IPathFindProcessMetric _pathFindProcessMetric)
    {
        planeBuilder           = _planeBuilder;
        unexploredMazeElements = _unexploredMazeElements;

        startMazeElement       = _startMazeElement;
        destinationMazeElement = _destinationMazeElement;

        pathFindProcessMetric = _pathFindProcessMetric;
    }
    public virtual IPathFindAlgo CreatePathFindAlgo(
        EPathFindAlgorithms ePathFindAlgorithm,
        IMazeSpecialElementsSeeker pathFindAlgoBoundary,
        List <IMazeElement> pathFromStartToEnd,
        IPlaneBuilder planeBuilder,
        List <IMazeElement> unexploredMazeElementsList,
        List <IMazeElement> openList,
        List <IMazeElement> closeList,
        IPathFindProcessMetric pathFindProcessMetric)
    {
        PathFindAlgo pathFindAlgo = null;

        switch (ePathFindAlgorithm)
        {
        case EPathFindAlgorithms.DijkstraAlgorithm:

            pathFindAlgo = new PathFindAlgo(
                pathFindAlgoBoundary,
                pathFromStartToEnd,
                new DijkstraPathFinder(
                    planeBuilder,
                    new UnexploredMazeElements(
                        planeBuilder,
                        unexploredMazeElementsList),
                    pathFindAlgoBoundary.FindStartPlaceForPathFinding(),
                    pathFindAlgoBoundary.FindDestinationPlaceForPathFinding(),
                    pathFindProcessMetric),
                new MazeRestarter(
                    planeBuilder));

            break;

        case EPathFindAlgorithms.EuclideanAStar:

            pathFindAlgo = new PathFindAlgo(
                pathFindAlgoBoundary,
                pathFromStartToEnd,
                new AStarPathFinder(
                    pathFindAlgoBoundary.FindStartPlaceForPathFinding(),
                    pathFindAlgoBoundary.FindDestinationPlaceForPathFinding(),
                    new OpenCloseListController(
                        openList,
                        closeList),
                    new NeighboursPathFindParametersProcessor(
                        planeBuilder,
                        pathFindAlgoBoundary.FindDestinationPlaceForPathFinding(),
                        new AStarEuclideanDistanceHeuristic()),
                    pathFindProcessMetric),
                new MazeRestarter(
                    planeBuilder));

            break;

        case EPathFindAlgorithms.ManhattanAStar:

            pathFindAlgo = new PathFindAlgo(
                pathFindAlgoBoundary,
                pathFromStartToEnd,
                new AStarPathFinder(
                    pathFindAlgoBoundary.FindStartPlaceForPathFinding(),
                    pathFindAlgoBoundary.FindDestinationPlaceForPathFinding(),
                    new OpenCloseListController(
                        openList,
                        closeList),
                    new NeighboursPathFindParametersProcessor(
                        planeBuilder,
                        pathFindAlgoBoundary.FindDestinationPlaceForPathFinding(),
                        new AStarManhattanDistanceHeuristic()),
                    pathFindProcessMetric),
                new MazeRestarter(
                    planeBuilder));

            break;
        }


        return(pathFindAlgo);
    }