public void IdToToken_Base2_Level4() { // level3 last Assert.AreEqual("RBBb", TreeGenerator.IdToToken(20, 2)); // level4 Assert.AreEqual("RAAA", TreeGenerator.IdToToken(21, 2)); Assert.AreEqual("RAAAa", TreeGenerator.IdToToken(22, 2)); Assert.AreEqual("RAAAb", TreeGenerator.IdToToken(23, 2)); Assert.AreEqual("RAAB", TreeGenerator.IdToToken(24, 2)); Assert.AreEqual("RAABa", TreeGenerator.IdToToken(25, 2)); Assert.AreEqual("RAABb", TreeGenerator.IdToToken(26, 2)); Assert.AreEqual("RABA", TreeGenerator.IdToToken(27, 2)); Assert.AreEqual("RABAa", TreeGenerator.IdToToken(28, 2)); Assert.AreEqual("RABAb", TreeGenerator.IdToToken(29, 2)); Assert.AreEqual("RABB", TreeGenerator.IdToToken(30, 2)); Assert.AreEqual("RABBa", TreeGenerator.IdToToken(31, 2)); Assert.AreEqual("RABBb", TreeGenerator.IdToToken(32, 2)); Assert.AreEqual("RBAA", TreeGenerator.IdToToken(33, 2)); Assert.AreEqual("RBAAa", TreeGenerator.IdToToken(34, 2)); Assert.AreEqual("RBAAb", TreeGenerator.IdToToken(35, 2)); Assert.AreEqual("RBAB", TreeGenerator.IdToToken(36, 2)); Assert.AreEqual("RBABa", TreeGenerator.IdToToken(37, 2)); Assert.AreEqual("RBABb", TreeGenerator.IdToToken(38, 2)); Assert.AreEqual("RBBA", TreeGenerator.IdToToken(39, 2)); Assert.AreEqual("RBBAa", TreeGenerator.IdToToken(40, 2)); Assert.AreEqual("RBBAb", TreeGenerator.IdToToken(41, 2)); Assert.AreEqual("RBBB", TreeGenerator.IdToToken(42, 2)); Assert.AreEqual("RBBBa", TreeGenerator.IdToToken(43, 2)); Assert.AreEqual("RBBBb", TreeGenerator.IdToToken(44, 2)); }
public void IdToToken_Base10_Transitions() { // level0 Assert.AreEqual("R", TreeGenerator.IdToToken(0, 10)); // only one // level1 abcdefghij Assert.AreEqual("Ra", TreeGenerator.IdToToken(1, 10)); // first Assert.AreEqual("Rj", TreeGenerator.IdToToken(10, 10)); // last // level2 Assert.AreEqual("RA", TreeGenerator.IdToToken(11, 10)); // first Assert.AreEqual("RJj", TreeGenerator.IdToToken(120, 10)); // last // level3 Assert.AreEqual("RAA", TreeGenerator.IdToToken(121, 10)); // first Assert.AreEqual("RJJj", TreeGenerator.IdToToken(1220, 10)); // last // level4 Assert.AreEqual("RAAA", TreeGenerator.IdToToken(1221, 10)); // first Assert.AreEqual("RJJJj", TreeGenerator.IdToToken(12220, 10)); // last // level5 Assert.AreEqual("RAAAA", TreeGenerator.IdToToken(12221, 10)); // first Assert.AreEqual("RJJJJj", TreeGenerator.IdToToken(122220, 10)); // last // level6 Assert.AreEqual("RAAAAA", TreeGenerator.IdToToken(122221, 10)); // first Assert.AreEqual("RJJJJJj", TreeGenerator.IdToToken(1222220, 10)); // last // level7 Assert.AreEqual("RAAAAAA", TreeGenerator.IdToToken(1222221, 10)); // first Assert.AreEqual("RJJJJJJj", TreeGenerator.IdToToken(12222220, 10)); // last // level8 Assert.AreEqual("RAAAAAAA", TreeGenerator.IdToToken(12222221, 10)); // first Assert.AreEqual("RJJJJJJJj", TreeGenerator.IdToToken(122222220, 10)); // last // level9 Assert.AreEqual("RAAAAAAAA", TreeGenerator.IdToToken(122222221, 10)); // first Assert.AreEqual("RJJJJJJJJj", TreeGenerator.IdToToken(1222222220, 10)); // last }
public void TokenToId_Base10_Transitions() { // level0 Assert.AreEqual(0, TreeGenerator.TokenToId("R", 10)); // only one // level1 Assert.AreEqual(1, TreeGenerator.TokenToId("Ra", 10)); // first Assert.AreEqual(10, TreeGenerator.TokenToId("Rj", 10)); // last // level2 Assert.AreEqual(11, TreeGenerator.TokenToId("RA", 10)); // first Assert.AreEqual(120, TreeGenerator.TokenToId("RJj", 10)); // last //level3 Assert.AreEqual(121, TreeGenerator.TokenToId("RAA", 10)); // first Assert.AreEqual(1220, TreeGenerator.TokenToId("RJJj", 10)); // last // level4 Assert.AreEqual(1221, TreeGenerator.TokenToId("RAAA", 10)); // first Assert.AreEqual(12220, TreeGenerator.TokenToId("RJJJj", 10)); // last // level5 Assert.AreEqual(12221, TreeGenerator.TokenToId("RAAAA", 10)); // first Assert.AreEqual(122220, TreeGenerator.TokenToId("RJJJJj", 10)); // last // level6 Assert.AreEqual(122221, TreeGenerator.TokenToId("RAAAAA", 10)); // first Assert.AreEqual(1222220, TreeGenerator.TokenToId("RJJJJJj", 10)); // last // level7 Assert.AreEqual(1222221, TreeGenerator.TokenToId("RAAAAAA", 10)); // first Assert.AreEqual(12222220, TreeGenerator.TokenToId("RJJJJJJj", 10)); // last // level8 Assert.AreEqual(12222221, TreeGenerator.TokenToId("RAAAAAAA", 10)); // first Assert.AreEqual(122222220, TreeGenerator.TokenToId("RJJJJJJJj", 10)); // last // level9 Assert.AreEqual(122222221, TreeGenerator.TokenToId("RAAAAAAAA", 10)); // first Assert.AreEqual(1222222220, TreeGenerator.TokenToId("RJJJJJJJJj", 10)); // last // level10 Assert.AreEqual(1222222221, TreeGenerator.TokenToId("RAAAAAAAAA", 10)); // first Assert.AreEqual(12222222220, TreeGenerator.TokenToId("RJJJJJJJJJj", 10)); // last }
public void IdToToken_Base2_Transitions() { // level0 Assert.AreEqual("R", TreeGenerator.IdToToken(0, 2)); // only one // level1 Assert.AreEqual("Ra", TreeGenerator.IdToToken(1, 2)); // first Assert.AreEqual("Rb", TreeGenerator.IdToToken(2, 2)); // last // level2 Assert.AreEqual("RA", TreeGenerator.IdToToken(3, 2)); // first Assert.AreEqual("RBb", TreeGenerator.IdToToken(8, 2)); // last // level3 Assert.AreEqual("RAA", TreeGenerator.IdToToken(9, 2)); // first Assert.AreEqual("RBBb", TreeGenerator.IdToToken(20, 2)); // last // level4 Assert.AreEqual("RAAA", TreeGenerator.IdToToken(21, 2)); // first Assert.AreEqual("RBBBb", TreeGenerator.IdToToken(44, 2)); // last // level5 Assert.AreEqual("RAAAA", TreeGenerator.IdToToken(45, 2)); // first Assert.AreEqual("RBBBBb", TreeGenerator.IdToToken(92, 2)); // last // level6 Assert.AreEqual("RAAAAA", TreeGenerator.IdToToken(93, 2)); // first Assert.AreEqual("RBBBBBb", TreeGenerator.IdToToken(188, 2)); // last // level7 Assert.AreEqual("RAAAAAA", TreeGenerator.IdToToken(189, 2)); // first Assert.AreEqual("RBBBBBBb", TreeGenerator.IdToToken(380, 2)); // last // level8 Assert.AreEqual("RAAAAAAA", TreeGenerator.IdToToken(381, 2)); // first Assert.AreEqual("RBBBBBBBb", TreeGenerator.IdToToken(764, 2)); // last // level9 Assert.AreEqual("RAAAAAAAA", TreeGenerator.IdToToken(765, 2)); // first Assert.AreEqual("RBBBBBBBBb", TreeGenerator.IdToToken(1532, 2)); // last // level10 Assert.AreEqual("RAAAAAAAAA", TreeGenerator.IdToToken(1533, 2)); // first Assert.AreEqual("RBBBBBBBBBb", TreeGenerator.IdToToken(3068, 2)); // last }
void Awake() { if (me == null) { me = this; } }
public ByteTreeSearchBenchmarks() { var comparator = new Comparator(); var brancher = new Brancher(); var evaluator = new Evaluator(); var stateTransitions = new StateTransitions(); _serial = new SerialAlfaBetaSearch <ByteNode, sbyte, sbyte>( evaluator, brancher, comparator, stateTransitions, sbyte.MaxValue, sbyte.MinValue); _serialTree = TreeGenerator.ReadTree(); _dynamic = new DynamicTreeSplitting <AlfaBetaByteNode, sbyte, sbyte>( evaluator, brancher, comparator, stateTransitions ); _dynamicTree = TreeGenerator.ReadAlfaBetaTree(); _cts = new CancellationTokenSource(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); TreeGenerator tree = target as TreeGenerator; tree.GenerateMap(); }
void Awake() { map = GetComponent <Map>(); if (MapName != string.Empty) { Debug.Log("In WorldGenerator, MapName != string.Empty"); FileTerrainGenerator fileTerrainGenerator = new FileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new TerrainGenerator(map); Block[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); Block[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new TreeGenerator[Math.Max(woodBlocks.Length, leavesBlocks.Length)]; for (int i = 0; i < treeGenerator.Length; i++) { Block wood = woodBlocks[i % woodBlocks.Length]; Block leaves = leavesBlocks[i % leavesBlocks.Length]; treeGenerator[i] = new TreeGenerator(map, wood, leaves); } } }
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(); } }
public void Tree_10_CreateNodeByToken_1220() { var node = TreeGenerator.CreateNode("RJJj", 10); Assert.AreEqual(1220, node.NodeId); Assert.AreEqual("RJJj", node.PathToken); }
public void Tree_10_CreateNodeById_1() { var node = TreeGenerator.CreateNode(1, 10); Assert.AreEqual(1, node.NodeId); Assert.AreEqual("Ra", node.PathToken); }
public void Tree_2_CreateNodeByToken_20() { var node = TreeGenerator.CreateNode("RBBb", 2); Assert.AreEqual(20, node.NodeId); Assert.AreEqual("RBBb", node.PathToken); }
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(); } }
public void TokenToId_Base2_Transitions() { // level0 Assert.AreEqual(0, TreeGenerator.TokenToId("R", 2)); // only one // level1 Assert.AreEqual(1, TreeGenerator.TokenToId("Ra", 2)); // first Assert.AreEqual(2, TreeGenerator.TokenToId("Rb", 2)); // last // level2 Assert.AreEqual(3, TreeGenerator.TokenToId("RA", 2)); // first Assert.AreEqual(8, TreeGenerator.TokenToId("RBb", 2)); // last //level3 Assert.AreEqual(9, TreeGenerator.TokenToId("RAA", 2)); // first Assert.AreEqual(20, TreeGenerator.TokenToId("RBBb", 2)); // last // level4 Assert.AreEqual(21, TreeGenerator.TokenToId("RAAA", 2)); // first Assert.AreEqual(44, TreeGenerator.TokenToId("RBBBb", 2)); // last // level5 Assert.AreEqual(45, TreeGenerator.TokenToId("RAAAA", 2)); // first Assert.AreEqual(92, TreeGenerator.TokenToId("RBBBBb", 2)); // last // level6 Assert.AreEqual(93, TreeGenerator.TokenToId("RAAAAA", 2)); // first Assert.AreEqual(188, TreeGenerator.TokenToId("RBBBBBb", 2)); // last // level7 Assert.AreEqual(189, TreeGenerator.TokenToId("RAAAAAA", 2)); // first Assert.AreEqual(380, TreeGenerator.TokenToId("RBBBBBBb", 2)); // last // level8 Assert.AreEqual(381, TreeGenerator.TokenToId("RAAAAAAA", 2)); // first Assert.AreEqual(764, TreeGenerator.TokenToId("RBBBBBBBb", 2)); // last // level9 Assert.AreEqual(765, TreeGenerator.TokenToId("RAAAAAAAA", 2)); // first Assert.AreEqual(1532, TreeGenerator.TokenToId("RBBBBBBBBb", 2)); // last // level10 Assert.AreEqual(1533, TreeGenerator.TokenToId("RAAAAAAAAA", 2)); // first Assert.AreEqual(3068, TreeGenerator.TokenToId("RBBBBBBBBBb", 2)); // last }
protected override TreeBase[] CreateChildren() { NodeType head; int constant = 0; if (Level > MaxLevel) { head = NodeType.End; } else if (typeA.Contains(type)) { head = SynthTree.NodeType.FlagA; } else if (typeB.Contains(type)) { head = SynthTree.NodeType.FlagB; } else { head = SynthTree.NodeType.FlagW; } constantCount.TryGetValue(type, out constant); return(Enumerable.Repeat(head, 1).Concat(Enumerable.Repeat(NodeType.Constant, constant)) .Select(x => TreeGenerator.GetNode(x, Level)) .ToArray()); }
//generate new tree or update existing tree procedurally via the TreeGenerator class public void Generate(bool randomTree = false) { //check if a tree has already been generated TreeGenerator tree = GameObject.FindObjectOfType <TreeGenerator>(); if (tree) { tree.UpdateTree(seed, maxNumVertices, numSides, trunkRadius, radiusStep, branchTipRadius, branchRoundness, segLength, twist, branchProb, numLeaves); if (tree.meshRenderer.sharedMaterial != null) { // randomize bark and platform material only when updating existing mesh with an entirely new randomized tree if (randomTree) { SetMaterials(tree, platform); } } else { SetMaterials(tree, platform); } } else { //otherwise create a new tree from a random seed var proceduralTree = new GameObject(string.Format("Tree_{0:X4}", Random.Range(0, 65536))).AddComponent <TreeGenerator>(); seed = Random.Range(0, 65536); proceduralTree.UpdateTree(seed, maxNumVertices, numSides, trunkRadius, radiusStep, branchTipRadius, branchRoundness, segLength, twist, branchProb, numLeaves); SetMaterials(proceduralTree, platform); SetUIVariables(proceduralTree); } }
protected void InitTrees() { TreeGenerator treeGenerator = FindObjectOfType <TreeGenerator>(); for (int x = 0; x < UnityEngine.Random.Range(0, 5); x++) { float posX = UnityEngine.Random.Range(coord.x * 10.0f - 5, coord.x * 10.0f + 5); float posZ = UnityEngine.Random.Range(coord.z * 10.0f - 5, coord.z * 10.0f + 5); Ray ray = new Ray(new Vector3(posX, (coord.y * 10 - 5), posZ), new Vector3(0, -1, 0)); if (Physics.Raycast(ray, out RaycastHit hit, 10)) { if (hit.transform.tag.Equals("chunk") && hit.point.y > -1 && hit.point.y < 5) { // if (hit.point > 10 && hit.point < 100) Vector3 position = hit.point; GameObject treeType = treeGenerator.shortTrees[UnityEngine.Random.Range(0, treeGenerator.shortTrees.Length)]; Quaternion rotation = Quaternion.Euler(new Vector3(0, UnityEngine.Random.Range(0, 360), 0)); GameObject treeObject = Instantiate(treeType, position, rotation); treeObject.transform.parent = this.transform; entities.Add(new EntityData(position, rotation, EntityType.Tree)); } } } }
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."); } }
public void GenTrees(IWorld world, IGrainFactory grainFactory, ChunkColumnCompactStorage chunk, Random random, BlockWorldPos pos) { int treesPerChunk = _treesPerChunk; if (random.NextDouble() < _extraTreeChance) { ++treesPerChunk; } for (int num = 0; num < treesPerChunk; ++num) { int x = random.Next(12) + 2; int z = random.Next(12) + 2; TreeGenerator treeGenerator = new TreeGenerator(5, false, GetRandomTree(random)); // 获得地表面高度 int h = 0; for (int y = 255; y >= 0; --y) { if (!chunk[x, y, z].IsAir()) { h = y + 1; break; } } treeGenerator.Generate(world, grainFactory, chunk, this, random, new BlockWorldPos(pos.X + x, h, pos.Z + z)); } }
protected override TreeBase[] CreateChildren() { NodeType[] nt; int wc; var ta = NodeType.FlagA | NodeType.FlagType; var tb = NodeType.FlagB | NodeType.FlagType; var tw = NodeType.FlagW | SynthTree.NodeType.FlagType; var fa = Level > MaxLevel ? NodeType.End : NodeType.FlagA; var fb = Level > MaxLevel ? NodeType.End : NodeType.FlagB; var fw = Level > MaxLevel ? NodeType.End : NodeType.FlagW; switch (this.type) { case ModifierType.SeriesA: nt = new[] { fa, ta, tb }; wc = 3; break; case ModifierType.ParallelA: nt = new[] { fa, ta, ta, tb, tb }; wc = 6; break; case ModifierType.UnitA: nt = new[] { fa, tw }; wc = 1; break; case ModifierType.SeriesB: nt = new [] { fb, tb, ta }; wc = 3; break; case ModifierType.ParallelB: nt = new[] { fb, tb, tb, ta, ta }; wc = 6; break; case ModifierType.UnitB: nt = new[] { fb, tw }; wc = 1; break; case ModifierType.UnitW: nt = new[] { fw, tw, }; wc = 1; break; case ModifierType.LoopW: nt = new[] { fw, ta, tb, tw }; wc = 4; break; default: throw new Exception(); } return(nt /*.Concat(Enumerable.Repeat(NodeType.FlagW, wc))*/.Select(x => TreeGenerator.GetNode(x, Level)).ToArray()); }
public Node(Vector3 position, TreeGenerator tree) { this.Position = position; this.Direction = Vector3.up; this.Depth = 0; this.Children = new Node[] { }; this.Tree = tree; }
private TreeGenerator ReadGenerator(ContentReader input) { String source = input.ReadString(); var xml = new XmlDocument(); xml.LoadXml(source); return(TreeGenerator.CreateFromXml(xml)); }
protected override void SetupHandler() { TreeGenerator rg = new TreeGenerator(); Handler.AddInt(NumberOfNodes, rg.NodeCount); Handler.AddInt(MaxDepth, rg.MaxDepth); Handler.AddInt(MaxChildCount, rg.MaxChildCount); }
//set the materials of both the tree bark and the platform grass private static void SetMaterials(TreeGenerator tree, GameObject platform) { //get materials at random Material barkMat = Resources.Load("Materials/BarkMaterials/bark" + Random.Range(1, 19), typeof(Material)) as Material; Material grassMat = Resources.Load("Materials/GrassMaterials/grass" + Random.Range(1, 12), typeof(Material)) as Material; tree.meshRenderer.sharedMaterial = barkMat; platform.GetComponent <Renderer>().material = grassMat; }
public TreeGenerator(ProceduralTree tree, Mesh mesh, TreeGenerator parent = null) : base(mesh, parent) { this.tree = tree; twisting = tree.Twisting; barkColor = tree.BarkColor; foliageType = tree.FoliageStyle; }
public static void CanGenerateTreeWithSize() { const int treeSize = 500; Node root = TreeGenerator.GenerateTree(treeSize); int actualTreeSize = CountTreeNodes(root); Assert.Equal(treeSize, actualTreeSize); }
public static void CanCloneTree() { const int treeSize = 500; Node root = TreeGenerator.GenerateTree(treeSize); Node cloned = TreeGenerator.CloneTree(root); Assert.True(MerkleExercise.CompareTrees(root, cloned)); }
private void OnValidate() { if (Application.isPlaying) { tree = TreeGenerator.GenerateTree(nodes); CleanDisplay(); DrawTree(tree); } }
void Start() { _treeGenerator = FindObjectOfType <TreeGenerator>(); leftRoad = false; rightRoad = false; _scoreManager = FindObjectOfType <ScoreManager>(); _closeEnemy = FindObjectOfType <CloseEnemy>(); closeAnim = GetComponent <Animator>(); side = 1; }
// Start is called before the first frame update void Awake() { instance = this; print("Creating Trie"); string[] englishWords = GetEnglishWords(); for (int i = 0; i < englishWords.Length; i++) { mainTrie.AddWord(englishWords[i]); } }
public void BuildMap() { List<Hexagon> borders = new List<Hexagon>(); _hexagons = new Hexagon[GridManager.instance.gridHeightInHexes * GridManager.instance.gridWidthInHexes]; for (int x = 0; x < GridManager.instance.gridWidthInHexes; x++) for (int y = 0; y < GridManager.instance.gridHeightInHexes; y++) { _hexagons[x + y * GridManager.instance.gridWidthInHexes] = GridManager.instance.CreateHexagonAt(x, y); _hexagons[x + y * GridManager.instance.gridWidthInHexes].ClickEvent += new HexagonEventHandler(GridManager.instance.UserInteraction.OnHexagonClickedEvent); //Making the border array: if (x == 0 || y == 0 || x == GridManager.instance.gridWidthInHexes - 1 || y == GridManager.instance.gridHeightInHexes - 1) borders.Add(_hexagons[x + y * GridManager.instance.gridWidthInHexes]); } HexBorders = new Hexagon[borders.Count]; borders.CopyTo(HexBorders, 0); foreach (var hexagon in _hexagons) { hexagon.SurroundingHexagons = GetSurroundingTiles(hexagon); } treeGenerator = new TreeGenerator(); }