Exemplo n.º 1
0
    public CollectPath(Point s, Point e, int index)
    {
        workList = new List <Point>();
        pathList = new List <Point>();

        if (index == 1)
        {
            var path = new PathFinderAStar(new NodeAS(s.i, s.j, true), new NodeAS(e.i, e.j, true));

            foreach (var node in path.workList)
            {
                workList.Add(new Point(node.i, node.j));
            }

            foreach (var node in path.pathList)
            {
                pathList.Add(new Point(node.i, node.j));
            }

            time = path.time;
        }
        else if (index == 2)
        {
            var path = new PathFinderDijkstra(new NodeDi(s.i, s.j, true), new NodeDi(e.i, e.j, true));

            foreach (var node in path.workList)
            {
                workList.Add(new Point(node.i, node.j));
            }

            foreach (var node in path.pathList)
            {
                pathList.Add(new Point(node.i, node.j));
            }

            time = path.time;
        }
        else if (index == 3)
        {
            var path = new PathFindingJPF(new NodeJPS(s.i, s.j, true), new NodeJPS(e.i, e.j, true));

            foreach (var node in path.workList)
            {
                workList.Add(new Point(node.i, node.j));
            }

            foreach (var node in path.pathList)
            {
                pathList.Add(new Point(node.i, node.j));
            }

            time = path.time;
        }
    }
Exemplo n.º 2
0
 public Navigator(Vector2 dimensions, float granularity, Func<Vector2, bool> isAccessible)
 {
     Debug.Assert(dimensions.X > 0 && dimensions.Y > 0);
     Debug.Assert(granularity > 0);
     _granularity = granularity;
     var pathFinderGrid = new byte[AWMathHelper.CeilingPowerTwo(CoordinateToIndex(dimensions.X)), CoordinateToIndex(dimensions.Y)];
     for (var gridY = 0; gridY < pathFinderGrid.GetLength(1); gridY++)
         for (var gridX = 0; gridX < pathFinderGrid.GetLength(0); gridX++)
             pathFinderGrid[gridX, gridY] = isAccessible(IndicesToVector2(gridX, gridY)) ? (byte)1 : (byte)0;
     _pathFinder = new PathFinderAStar(pathFinderGrid)
     {
         HeuristicEstimate = 1,
         SearchLimit = 20000,
     };
 }