Пример #1
0
        public void ShouldCountConnectedComponents()
        {
            KnotHash    kh   = new KnotHash();
            GridCreator g    = new GridCreator(kh);
            var         grid = g.Generate("flqrgnkx");

            Defragmentor f = new Defragmentor();

            Assert.Equal(1242, f.CountUsedGroups(grid));
        }
Пример #2
0
        public void ShouldCalculateUsedSpace()
        {
            KnotHash    kh   = new KnotHash();
            GridCreator g    = new GridCreator(kh);
            var         grid = g.Generate("flqrgnkx");

            Defragmentor f = new Defragmentor();

            Assert.Equal(8108, f.GetUsedSpace(grid));
        }
Пример #3
0
        static void Main(string[] args)
        {
            KnotHash     kh     = new KnotHash();
            GridCreator  d      = new GridCreator(kh);
            Defragmentor f      = new Defragmentor();
            var          square = d.Generate("nbysizxe");

            // Part one
            Console.WriteLine(f.GetUsedSpace(square));

            // Part two
            Console.WriteLine(f.CountUsedGroups(square));
        }
Пример #4
0
        public void GenerateGrids()
        {
            KnotHash    kh   = new KnotHash();
            GridCreator g    = new GridCreator(kh);
            var         grid = g.Generate("flqrgnkx");

            Assert.Equal(128, grid.Length);

            foreach (var row in grid)
            {
                Assert.Equal(128, row.Length);
            }
        }
Пример #5
0
        void OnGUI()
        {
            EditorGUILayout.LabelField("Select grid prefab", EditorStyles.boldLabel);
            m_GridPrefab = EditorGUILayout.ObjectField(m_GridPrefab, typeof(GameObject), true, null) as GameObject;
            if (!m_GridPrefab)
            {
                m_GridPrefab = Resources.Load("GridNode") as GameObject;
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Grid size options", EditorStyles.boldLabel);
            m_XAmount    = Mathf.Clamp(EditorGUILayout.IntField("Number of X nodes", m_XAmount), 1, 100);
            m_YAMount    = Mathf.Clamp(EditorGUILayout.IntField("Number of Y nodes", m_YAMount), 1, 100);
            m_RandomCost = EditorGUILayout.Toggle("Randomize cost", m_RandomCost);

            EditorGUILayout.Space();

            if (GUILayout.Button("Genrate"))
            {
                GenerateGrid();
            }

            EditorGUILayout.Space();

            GameObject grid = GameObject.Find(m_GridParentName);

            if (grid)
            {
                if (GUILayout.Button("Remove grid"))
                {
                    DestroyImmediate(grid);
                    EditorSceneManager.MarkAllScenesDirty();
                }
            }

            if (m_WillGenerate)
            {
                if (grid)
                {
                    Debug.Log("Another grid was found, removing it");
                    DestroyImmediate(grid);
                }

                GeneticGenerator gen = FindObjectOfType <GeneticGenerator> ();
                if (gen)
                {
                    gen.X = m_XAmount;
                    gen.Y = m_YAMount;
                }

                GridCreator creator = new GridCreator();
                creator.Generate(new GameObject(m_GridParentName), m_GridPrefab, m_XAmount, m_YAMount, GridCreator.AdjacentMode.XFIRST);
                FindObjectOfType <GridController> ().Creator = creator;
                FindObjectOfType <GridController> ().UpdateEditorColors();

                m_WillGenerate = false;
                EditorSceneManager.MarkAllScenesDirty();
            }
            else
            {
                GridController controller = FindObjectOfType <GridController> ();
                if (controller)
                {
                    if (GUILayout.Button("Re-assign adjacent nodes"))
                    {
                        controller.Creator.Reassign(GridCreator.AdjacentMode.XFIRST);
                        controller.UpdateEditorColors();
                        EditorSceneManager.MarkAllScenesDirty();
                    }
                }
            }
        }