Exemplo n.º 1
0
 static bool hasWestconnection(int i, int j, MazeGraph <T> G)
 {
     if (j == 0)
     {
         return(true);
     }
     else
     {
         return(G.hasEdge(G.GetNode(i, j), G.GetNode(i, j - 1)));
     }
 }
Exemplo n.º 2
0
 static bool hasNorthconnection(int i, int j, MazeGraph <T> G)
 {
     if (i == G.rows - 1)
     {
         return(true);
     }
     else
     {
         return(G.hasEdge(G.GetNode(i, j), G.GetNode(i + 1, j)));
     }
 }
Exemplo n.º 3
0
 static bool hasSouthconnection(int i, int j, MazeGraph <T> G)
 {
     if (i == 0)
     {
         return(true);
     }
     else
     {
         return(G.hasEdge(G.GetNode(i, j), G.GetNode(i - 1, j)));
     }
 }
Exemplo n.º 4
0
        private static void DivideHorizontally(int row, int col, int height, int width)
        {
            int divideCell = rand.Next(height - 1);
            int passage_at = rand.Next(width);

            for (int i = 0; i < width; ++i)
            {
                if (i != passage_at)
                {
                    int r         = row + divideCell;
                    int c         = col + i;
                    int node      = g.GetNode(r, c);
                    int southnode = g.GetNode(r + 1, c);
                    g.removeEdge(node, southnode);
                    g.removeEdge(southnode, node);
                }
            }
            Divide(row, col, divideCell + 1, width);
            Divide(row + divideCell + 1, col, height - divideCell - 1, width);
        }
Exemplo n.º 5
0
 public static MazeGraph <T> Execute(MazeGraph <T> G)
 {
     InitializeVariables(G);
     for (int i = 0; i < g.rows; ++i)
     {
         List <int> group = new List <int>();
         for (int j = 0; j < g.cols; ++j)
         {
             group.Add(j);
             if (!(j < g.cols - 1) || ((i < g.rows - 1) && rand.Next(2) == 0))
             {
                 int connectAt = group[rand.Next(0, group.Count)];
                 g.addEdge(g.GetNode(i, connectAt), g.GetNode(i + 1, connectAt), default(T));
                 g.addEdge(g.GetNode(i + 1, connectAt), g.GetNode(i, connectAt), default(T));
                 group.Clear();
             }
             else
             {
                 g.addEdge(g.GetNode(i, j), g.GetEast(i, j), default(T));
                 g.addEdge(g.GetEast(i, j), g.GetNode(i, j), default(T));
             }
         }
     }
     return(g);
 }
Exemplo n.º 6
0
 public void GenerateObj(MazeGraph <T> G, bool ceil = false)
 {
     xsize = G.rows;
     ysize = G.cols;
     using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Application.dataPath + "/Resources/objeto1.obj")) {
         for (int i = 0; i < G.rows; ++i)
         {
             for (int j = 0; j < G.cols; ++j)
             {
                 sb.Clear();
                 V = new System.Numerics.Vector3[] {
                     new System.Numerics.Vector3(i, j, 0),
                     new System.Numerics.Vector3(i, j + 1, 0),
                     new System.Numerics.Vector3(i + 1, j, 0),
                     new System.Numerics.Vector3(i + 1, j + 1, 0),
                     new System.Numerics.Vector3(i, j, 1),
                     new System.Numerics.Vector3(i, j + 1, 1),
                     new System.Numerics.Vector3(i + 1, j, 1),
                     new System.Numerics.Vector3(i + 1, j + 1, 1)
                 };
                 WriteWall(V, 0);
                 if (!G.hasEdge(G.GetNode(i, j), G.GetNode(i + 1, j)) || i == G.rows - 1)
                 {
                     WriteWall(V, 1);
                 }
                 if (!G.hasEdge(G.GetNode(i, j), G.GetNode(i - 1, j)) || i == 0)
                 {
                     WriteWall(V, 2);
                 }
                 if (!G.hasEdge(G.GetNode(i, j), G.GetNode(i, j + 1)) || j == G.cols - 1)
                 {
                     WriteWall(V, 3);
                 }
                 if (!G.hasEdge(G.GetNode(i, j), G.GetNode(i, j - 1)) || j == 0)
                 {
                     WriteWall(V, 4);
                 }
                 if (ceil)
                 {
                     WriteWall(V, 5);
                 }
                 file.Write(sb.ToString());
             }
         }
     }
 }
Exemplo n.º 7
0
 public static MazeGraph <T> Execute(MazeGraph <T> G)
 {
     InitializeVariables(G);
     int[] conjuntos = Enumerable.Range(0, g.cols).ToArray <int>();
     for (int i = 0; i < g.rows; ++i)
     {
         for (int j = 0; j < g.cols - 1; ++j)
         {
             if ((i == g.rows - 1 || rand.Next(2) == 1) && !g.hasEdge(g.GetNode(i, j), g.GetNode(i, j + 1)))
             {
                 conjuntos[j + 1] = conjuntos[j];
                 g.addEdge(g.GetNode(i, j), g.GetNode(i, j + 1), default(T));
                 g.addEdge(g.GetNode(i, j + 1), g.GetNode(i, j), default(T));
             }
         }
         if (i < g.rows - 1)
         {
             int[]         siguientesconjuntos = Enumerable.Range((i + 1) * g.cols, g.cols).ToArray <int>();
             HashSet <int> todoslosconjuntos   = new HashSet <int>(conjuntos);
             HashSet <int> conjuntosmovidos    = new HashSet <int>();
             while (!todoslosconjuntos.SetEquals(conjuntosmovidos))
             {
                 for (int j = 0; j < g.cols; ++j)
                 {
                     if (rand.Next(2) == 1 && !conjuntosmovidos.Contains(conjuntos[j]))
                     {
                         conjuntosmovidos.Add(conjuntos[j]);
                         siguientesconjuntos[j] = conjuntos[j];
                         g.addEdge(g.GetNode(i, j), g.GetNode(i + 1, j), default(T));
                         g.addEdge(g.GetNode(i + 1, j), g.GetNode(i, j), default(T));
                     }
                 }
             }
             conjuntos = siguientesconjuntos;
         }
     }
     return(g);
 }
Exemplo n.º 8
0
    //Twistiness
    public float Twistiness(MazeGraph <T> g)
    {
        int twists = 0;

        for (int i = 0; i < g.rows; ++i)
        {
            for (int j = 0; j < g.rows; ++j)
            {
                bool n = g.hasEdge(g.GetNode(i, j), g.GetNode(i + 1, j));
                bool s = g.hasEdge(g.GetNode(i, j), g.GetNode(i - 1, j));
                bool e = g.hasEdge(g.GetNode(i, j), g.GetNode(i, j + 1));
                bool w = g.hasEdge(g.GetNode(i, j), g.GetNode(i, j - 1));
                if ((n & !s & (e || w)) || (!n & s & (e || w)) || (!w & e & (n || s)) || (w & !e & (n || s)))
                {
                    ++twists;
                }
            }
        }
        return(100.0f * twists / (g.rows * g.cols));
    }
Exemplo n.º 9
0
    //Directness
    public float Directness(MazeGraph <T> g)
    {
        int direct = 0;

        for (int i = 0; i < g.rows; ++i)
        {
            for (int j = 0; j < g.rows; ++j)
            {
                bool n = g.hasEdge(g.GetNode(i, j), g.GetNode(i + 1, j));
                bool s = g.hasEdge(g.GetNode(i, j), g.GetNode(i - 1, j));
                bool e = g.hasEdge(g.GetNode(i, j), g.GetNode(i, j + 1));
                bool w = g.hasEdge(g.GetNode(i, j), g.GetNode(i, j - 1));
                if (((n && s) && !w && !e) || ((e && w) && !n && !s))
                {
                    ++direct;
                }
            }
        }
        return(100.0f * direct / (g.rows * g.cols));
    }
Exemplo n.º 10
0
    //LongestPath
    public float LongestPath(MazeGraph <T> G)
    {
        bool[] visited;
        KeyValuePair <KeyValuePair <int, int>, int> LP      = new KeyValuePair <KeyValuePair <int, int>, int>();
        List <KeyValuePair <int, int> >             adycost = new List <KeyValuePair <int, int> >();

        for (int i = 0; i < G.rows; ++i)
        {
            for (int j = 0; j < G.rows; ++j)
            {
                visited = new bool[G.NumVert];
                visited[G.GetNode(i, j)] = true;
                foreach (var n in G.ConnectedNeighbors(i, j))
                {
                    adycost.Add(new KeyValuePair <int, int>(n, 1));
                }
                while (adycost.Count != 0)
                {
                    KeyValuePair <int, int> c = adycost[0];
                    visited[c.Key] = true;
                    if (LP.Value < c.Value)
                    {
                        LP = new KeyValuePair <KeyValuePair <int, int>, int>(new KeyValuePair <int, int>(G.GetNode(i, j), c.Key), c.Value);
                    }
                    foreach (var n in G.ConnectedNeighbors(G.GetCoord(c.Key)[0], G.GetCoord(c.Key)[1]))
                    {
                        if (!visited[n])
                        {
                            adycost.Add(new KeyValuePair <int, int>(n, c.Value + 1));
                        }
                    }
                    adycost.RemoveAt(0);
                }
            }
        }
        return(100.0f * LP.Value / (G.rows * G.cols));
    }