1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question What's the consensus on repeated elements on a TreeBot?

Discussion in 'Developer Support' started by Daniel, Aug 9, 2017.

  1. Daniel

    Joined:
    Jun 24, 2014
    Messages:
    172
    Likes Received:
    29
    So I'm designing the tree and trying to balance it however somehow I'll end up with repeated nodes.
    Let me illustrate:

    [​IMG]

    Now, someone may say "well, make 'inventory full?' the root node." This was my first approach, but then on later subnodes then "inside area?" will be asked, both on left and right childs of the root node.

    Also, due to the nature of the bot, reaching subtree O should be priority, regardless if the inventory is full or not, so if you're inside the area, and inside the inner area, whether inventory is full or not, some things must be done. If another approach is taken, then some extra logic that shouldn't be needed would be added.

    Having said that, will I be sent to the guillotine for having some nodes that check the same thing and subtrees that are almost identical?
     
    #1 Daniel, Aug 9, 2017
    Last edited: Aug 9, 2017
  2. awesome123man

    awesome123man Go check out new bots and give helpful feedback.

    Joined:
    Jan 31, 2016
    Messages:
    5,413
    Likes Received:
    1,662
    No you will not. I have this happen to me as well and it's completely fine :)
     
  3. Sinning

    Joined:
    Aug 9, 2017
    Messages:
    20
    Likes Received:
    0
    The logic in your node tree doesn't make a whole lot of sense to me, but typically when you have many leaf tasks that are identical or the same its an indicator of a poor design. However, in most bots you're bound to have a few similar leaf tasks in which case its perfectly fine to reuse the same classes.
     
  4. Jux7apose

    Joined:
    Mar 28, 2017
    Messages:
    286
    Likes Received:
    58
    Really? I'd consider that the more nodes you have the better, assuming they're of quality though. that way, you can easily locate code in case of bugs, find where and what is going wrong quickly, etc. Just my thoughts tho
     
  5. Daniel

    Joined:
    Jun 24, 2014
    Messages:
    172
    Likes Received:
    29
    I'm not talking about leaf tasks, but instead branches, where the same check is done 2 (or 3 times at a really, really bad scenario).

    Correct, it's a good approach and it's called modular programming. Just like you wouldn't want to have a main function that does everything.
     
  6. MaskedMouse

    Joined:
    Feb 21, 2016
    Messages:
    60
    Likes Received:
    11
    What you could do is use the same class that does the check but when creating the class pass the actual branch / leaf that you want to use.
    Atleast I just came up with this, not entirely sure if that will work. It did compile so but I haven't run it.
    I had some plans on making more bots but yeah I got to the point as well where multiple times I have to check the same condition in a different branch. What I mostly tried was move that check higher up in the branch if possible. But thats not always possible when you have a complex bot doing so many checks before executing something.

    Anyway have a look at the code, maybe try it out. Not sure if it is working or not.

    Code (Javascript):
    1. public class Root extends TreeBot
    2. {
    3.  
    4.     @Override
    5.     public TreeTask createRootTask()
    6.     {
    7.         return new BranchA(new BranchB(), new LeafA());
    8.     }
    9. }
    10.  
    11. public class BranchA extends BranchTask
    12. {
    13.     public BranchA(TreeTask failure, TreeTask success)
    14.     {
    15.         failureTreeTask = failure;
    16.         successTreeTask = success;
    17.     }
    18.  
    19.     private TreeTask failureTreeTask;
    20.     private TreeTask successTreeTask;
    21.  
    22.     @Override
    23.     public TreeTask failureTask()
    24.     {
    25.         return failureTreeTask;
    26.     }
    27.  
    28.     @Override
    29.     public TreeTask successTask()
    30.     {
    31.         return successTreeTask;
    32.     }
    33.  
    34.     @Override
    35.     public boolean validate()
    36.     {
    37.         // Do some validation
    38.         return false;
    39.     }
    40. }
     
  7. Exia

    Joined:
    Nov 3, 2013
    Messages:
    609
    Likes Received:
    259
    My thoughts on this are: move your repeated nodes up the tree so the check happens closer to the root. Generally you can remove duplicates this way.

    Inventory full/Empty is one of the best root nodes IMO for gathering bots, since if you are full, you empty the inventory (doesn't matter the method), if you are not full, you continue to gather.
     

Share This Page

Loading...