Exemplo n.º 1
0
    private IGraph <Vector2> GetMazeGraph()
    {
        IGraph <Vector2> graph = new AdjacencyListGraph <Vector2>();

        IGraphNode <Vector2>[,] nodes = new IGraphNode <Vector2> [size, size];

        for (int y = 0; y < size; ++y)
        {
            for (int x = 0; x < size; ++x)
            {
                nodes[y, x] = graph.AddNode(new Vector2(x, y));
            }
        }

        for (int i = 1; i < size; ++i)
        {
            graph.AddUndirectedEdge(nodes[i - 1, 0], nodes[i, 0], Random.Range(0f, 1f));
            graph.AddUndirectedEdge(nodes[0, i - 1], nodes[0, i], Random.Range(0f, 1f));
        }

        for (int y = 1; y < size; ++y)
        {
            for (int x = 1; x < size; ++x)
            {
                graph.AddUndirectedEdge(nodes[y - 1, x], nodes[y, x], Random.Range(0f, 1f));
                graph.AddUndirectedEdge(nodes[y, x - 1], nodes[y, x], Random.Range(0f, 1f));
            }
        }

        IMSTStrategy <Vector2> strategy = new KruskalsAlgorithm <Vector2>();

        return(new MSTResultGraph <Vector2>(graph, strategy));
    }