Пример #1
0
        public void BaseTest()
        {
            var dfs       = new DFS <int>();
            var emptyList = new List <int>();

            // No elements to traverse
            Assert.Equal(emptyList, dfs.Find(0, 1));
            // Add bogey nodes and edge
            dfs.AddEdge(0, 1);
            // Target vertex does not exist
            Assert.Equal(emptyList, dfs.Find(0, 5));
        }
Пример #2
0
    public void Find(int _method = 0)
    {
        bool _found = false;

        switch (_method)
        {
        case 0:                 //DFS
            _found = depth.Find(_start);
            _path  = depth.GetPath();
            break;

        case 1:                 //BFS
            _found = breadth.Find(_start);
            _path  = breadth.GetPath();
            break;

        case 2:                 //A*
            _found = astar.Find(_start, _goal);
            _path  = astar.GetPath();
            break;
        }

        GameObject t = GameObject.Find("GUI");

        //Search for end-node.
        if (_found)
        {
            t.SendMessage("SetMessage", "A path was found!");

            if (Debug.isDebugBuild)
            {
                string _out = "";

                foreach (Node n in _path)
                {
                    _out += n.name + " ";
                }
                Debug.Log(_out);
            }
        }
        else
        {
            t.SendMessage("SetMessage", "A path could not be found!");

            if (Debug.isDebugBuild)
            {
                Debug.Log("Search: Path Could not be found!");
            }
        }
    }