Search Unity

Tree generation algorithm

Discussion in 'Scripting' started by Darkkingdom, Apr 26, 2020.

  1. Darkkingdom

    Darkkingdom

    Joined:
    Sep 2, 2014
    Posts:
    81
    Hey folks,

    currently I'm trying to code a random tree generator like this:

    • Each node represents a different occurrence like a fight, checkpoint or tressurechest
    • The nodes are connected as shown, that's the path where the player can travel
    • The dashed contections are shortcuts
    Edit:
    What I'm having trouble with, is the generation of the branchs.
    Like what are some possible rules how the branch could...
    • split
    • end
    • create a shortcut to another branch
    And I think I need some comprehensive rules for the whole tree.
    So each random tree is a bit different in his structur but has around the same amount of nodes, splits, shortcuts etc.


    I rack my brain trying to get solution for this, but I can't get to a good result.
    So a bit of pseudo code would really help me out


    Thank you very much :)
     
    Last edited: Apr 27, 2020
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    It's basically just a linked list.. with "optimizations"

    Each node holds a reference to where he can lead.

    Code (CSharp):
    1. public class Node {
    2.  
    3. List<Node> pathTo;
    4.  
    5. }
    is the basic idea, or is that not what you're having a problem with?
     
    Darkkingdom likes this.
  3. Darkkingdom

    Darkkingdom

    Joined:
    Sep 2, 2014
    Posts:
    81
    Hey SparrowsNest thanks for the answer!
    Oh sorry I think I didn't descripted it clear enough^^

    What I'm having trouble with, is the generation of the branchs.
    Like what are some possible rules how the branch could...
    • split
    • end
    • create a shortcut to another branch
    And I think I need some comprehensive rules for the whole tree.
    So each random tree is a bit different in his structur but has around the same amount of nodes, splits, shortcuts etc.
     
  4. Darkkingdom

    Darkkingdom

    Joined:
    Sep 2, 2014
    Posts:
    81
    Has anyone an idea :)?