Пример #1
0
        private void btnPrviUDubinu_Click(object sender, EventArgs e)
        {
            inicijalizacijaPretrage();
            DeepFirstSearch dfs      = new DeepFirstSearch();
            State           sp       = pocetnoStanje;
            State           solution = dfs.search(sp);

            if (solution != null)
            {
                resenje = solution.path();
            }
            displayPanel1.Refresh();
        }
Пример #2
0
    public void Search(int algrithm)
    {
        ClearPath();
        SearchAlgrithm ag = (SearchAlgrithm)algrithm;
        PathFind       pathFind;

        switch (ag)
        {
        case SearchAlgrithm.BFS:
            pathFind = new BreadthFirstSearch();
            break;

        case SearchAlgrithm.DFS:
            pathFind = new DeepFirstSearch();
            break;

        case SearchAlgrithm.Dijkstra:
            pathFind = new DijkstraSearch();
            break;

        case SearchAlgrithm.Greedy:
            pathFind = new GreedyBestFirstSearch();
            break;

        case SearchAlgrithm.AStar:
            pathFind = new AStarSearch();
            break;

        default:
            pathFind = new AStarSearch();
            break;
        }
        Node start = graph.GetNode((int)mapView.startPos.x, (int)mapView.startPos.y);
        Node end   = graph.GetNode((int)mapView.endPos.x, (int)mapView.endPos.y);

        if (pathFind.Find(graph, start, end))
        {
            path = pathFind.GetPath();
            Queue <Node> searchSteps = pathFind.GetSearchSteps();
            mainUI.labelSearchDesc.text = pathFind.Name() + " " + pathFind.SearchResultDesc();
            mainUI.SearchConsoleTxt     = "";
            StartCoroutine(DrawSearchSteps(searchSteps, path));
        }
        else
        {
            mainUI.labelConsole.text = "no path to the target point from the start point";
        }
    }