Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        TreeGenerator treeGen = (TreeGenerator)target;



        if (DrawDefaultInspector())
        {
            //treeGen.m_keys = new char[treeGen.m_nbOfRules];
            //treeGen.m_values = new string[treeGen.m_nbOfRules];

            if (treeGen.m_autoUpdate)
            {
                treeGen.GenerateTree();
            }
        }

        if (GUILayout.Button("Generate"))
        {
            treeGen.GenerateTree();
        }

        if (GUILayout.Button("Reset"))
        {
            treeGen.Reset();
        }
    }
Exemplo n.º 2
0
        private static void Run(string outputPath)
        {
            var levelMax = 6;

            foreach (var containersPerLevel in new[] { 2, 3, 4, 5, 8, 10, 16 })
            {
                Console.Write("Containers per level: " + containersPerLevel);
                var fileName = Path.Combine(outputPath, $"base{containersPerLevel}.txt");

                TreeNode last = null;
                using (var writer = new StreamWriter(fileName))
                {
                    PrintHeader(containersPerLevel, levelMax, writer);
                    foreach (var node in TreeGenerator.GenerateTree(containersPerLevel, levelMax))
                    {
                        if (node.NodeId < containersPerLevel + 4)
                        {
                            PrintNode(node, writer);
                            continue;
                        }
                        var digits = node.PathDigits;
                        if (digits[0] == 0 && digits.Max() == 1)
                        {
                            writer.WriteLine();
                            PrintNode(last, writer);
                            PrintNode(node, writer);
                        }
                        last = node;
                    }
                }
                Console.WriteLine(" ok.");
            }
        }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        TreeGenerator treeGen = (TreeGenerator)target;

        if (DrawDefaultInspector())
        {
            if (treeGen.autoUpdate)
            {
                treeGen.GenerateTreeMesh();
            }
        }

        if (GUILayout.Button("Generate"))
        {
            treeGen.GenerateTree();
        }

        if (GUILayout.Button("Generate Next Iteration"))
        {
            treeGen.GenerateNextIteration();
        }

        if (GUILayout.Button("Reset"))
        {
            treeGen.Reset();
        }
    }
Exemplo n.º 4
0
        public static void CanGenerateTreeWithSize()
        {
            const int treeSize = 500;
            Node      root     = TreeGenerator.GenerateTree(treeSize);

            int actualTreeSize = CountTreeNodes(root);

            Assert.Equal(treeSize, actualTreeSize);
        }
Exemplo n.º 5
0
        public static void CanCloneTree()
        {
            const int treeSize = 500;
            Node      root     = TreeGenerator.GenerateTree(treeSize);

            Node cloned = TreeGenerator.CloneTree(root);

            Assert.True(MerkleExercise.CompareTrees(root, cloned));
        }
Exemplo n.º 6
0
 private void OnValidate()
 {
     if (Application.isPlaying)
     {
         tree = TreeGenerator.GenerateTree(nodes);
         CleanDisplay();
         DrawTree(tree);
     }
 }
Exemplo n.º 7
0
        public static void CanDetectSubtrees()
        {
            const int treeSize    = 500;
            Node      bigTreeRoot = TreeGenerator.GenerateTree(treeSize);

            Node randomBigTreeNode = TreeGenerator.PickRandomNode(bigTreeRoot);

            Node subtree = TreeGenerator.CloneTree(randomBigTreeNode);

            Assert.True(MerkleExercise.IsSubtree(bigTreeRoot, subtree));
        }
Exemplo n.º 8
0
        public void Tree_2_Full_Depth2()
        {
            var expectedIds   = "0,1,2,3,4,5,6,7,8";
            var expectedPaths = "R,Ra,Rb,RA,RAa,RAb,RB,RBa,RBb";

            var nodes = TreeGenerator.GenerateTree(2, 2)
                        .ToArray();

            Assert.AreEqual(expectedIds, string.Join(',', nodes.Select(n => n.NodeId.ToString())));
            Assert.AreEqual(expectedPaths, string.Join(',', nodes.Select(n => n.PathToken)));
        }
Exemplo n.º 9
0
        public static void CanFiddleWithTree()
        {
            const int treeSize = 500;
            Node      root     = TreeGenerator.GenerateTree(treeSize);

            Node cloned = TreeGenerator.CloneTree(root);

            TreeGenerator.FiddleWithTree(cloned);

            // a fiddled tree should never be identical
            Assert.False(MerkleExercise.CompareTrees(root, cloned));
        }
Exemplo n.º 10
0
    public void Build()
    {
        world.mechanics.stats.mapSize           = mapSize;
        world.mechanics.stats.limitTemperatures = limitTemperatures;
        Tilemap baseGroundTilemap = world.graphics.grid.worldBaseGround_.baseGroundTilemap;
        Tilemap grassTilemap      = world.graphics.grid.grassTilemap;
        Tilemap sandTilemap       = world.graphics.grid.sandTilemap;

        for (int yPosition = 0; yPosition < mapSize.y; yPosition++)
        {
            float   calculatedTemperature = (((limitTemperatures.y - limitTemperatures.x) * yPosition) / mapSize.y) + limitTemperatures.x;
            float   maxMoisture           = -(50 * (calculatedTemperature - possibleLimitTemperatures.y) / (possibleLimitTemperatures.x - possibleLimitTemperatures.y)) + 100;
            float   minMoisture           = 100 - maxMoisture;
            Vector2 moistureLimits        = new Vector2(maxMoisture, minMoisture);
            for (int xPosition = 0; xPosition < mapSize.x; xPosition++)
            {
                float      calculatedMoisture = (((moistureLimits.x - moistureLimits.y) * (xPosition - 0)) / (mapSize.x - 1 - 0)) + moistureLimits.y;
                Vector3Int position           = new Vector3Int(xPosition, yPosition, 0);

                //Generate ground components
                Tile ground = groundGenerator.GenerateGround(calculatedTemperature, calculatedMoisture);
                baseGroundTilemap.SetTile(position, ground);

                //Generate trees
                Tree_ tree = treeGenerator.GenerateTree(calculatedTemperature, calculatedMoisture);
                if (tree != null)
                {
                    if (Random.Range(1, 4) == 1)
                    {
                        if (Random.Range(1, 100) <= ((TreeStats_)tree.mechanics_.stats_).biome.treeDensity)
                        {
                            Tree_ newTree = Instantiate(tree, baseGroundTilemap.CellToWorld(position), Quaternion.identity);
                            newTree.transform.SetParent(trees.transform);
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 11
0
 void Start()
 {
     tree = TreeGenerator.GenerateTree(nodes);
     DrawTree(tree);
 }