コード例 #1
0
ファイル: ExportToOBJ.cs プロジェクト: mjcs-95/MazeGenerator
 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());
             }
         }
     }
 }
コード例 #2
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)));
     }
 }
コード例 #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)));
     }
 }
コード例 #4
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)));
     }
 }
コード例 #5
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));
    }
コード例 #6
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));
    }
コード例 #7
0
ファイル: Algorithms.cs プロジェクト: mjcs-95/MazeGenerator
 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);
 }