Exemple #1
0
    public void FindPath(int startCellId, int endCellId, PathFindAlg type, Action <List <int> > action)
    {
        List <int> path;

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        switch (type)
        {
        case PathFindAlg.Bfs:
            path = BfsSearch(startCellId, endCellId);
            break;

        case PathFindAlg.Astar:
            path = AStarSearch(startCellId, endCellId);
            break;

        case PathFindAlg.BeamSearch:
            path = BeamSearch(startCellId, endCellId);
            break;

        default:
            path = null;
            break;
        }
        sw.Stop();
        Debug.Log(sw.Elapsed);

        OnSearchEnd(action, path);
    }
    public void FindPath(int startCellId, int endCellId, PathFindAlg type, Action <List <int> > action)
    {
        List <int> path;

        switch (type)
        {
        case PathFindAlg.Bfs:
            path = BfsSearch(startCellId, endCellId);
            break;

        case PathFindAlg.Astar:
            path = AStarSearch(startCellId, endCellId);
            break;

        case PathFindAlg.BeamSearch:
            path = BeamSearch(startCellId, endCellId);
            break;

        default:
            path = null;
            break;
        }

        OnSearchEnd(action, path);
    }
Exemple #3
0
 // Key for getting the correct pathfinder from the dictionary
 private int Key(
     PathFindAlg pfa,
     Heuristic h = Heuristic.EuclideanDist,
     bool early  = false)
 {
     if (pfa == PathFindAlg.Dijkstra)
     {
         return(0);
     }
     else
     {
         return(1 | ((early ? 0 : 1) << 1) | (int)h << 2);
     }
 }
    public void FindPath(int startCellId, int endCellId, PathFindAlg type, Action <List <int> > action = null)
    {
        switch (type)
        {
        case PathFindAlg.Bfs:
            BfsSearch(startCellId, endCellId, action);
            break;

        case PathFindAlg.Astar:
            AStarSearch(startCellId, endCellId, action);
            break;

        case PathFindAlg.BeamSearch:
            BeamSearch(startCellId, endCellId, action);
            break;

        default:
            break;
        }
    }
    public void FindPathRequest(int startCellId, int endCellId, PathFindAlg type, Action <List <int> > action = null)
    {
        PathFindReq req = new PathFindReq();

        req.startCellId = startCellId;
        req.endCellId   = endCellId;
        req.type        = type;
        req.action      = action;

        foreach (var request in m_Requests)
        {
            if (request.startCellId == startCellId &&
                request.endCellId == endCellId &&
                request.type == type &&
                request.action == action)
            {
                return;
            }
        }

        m_Requests.Enqueue(req);
    }