Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

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

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

eCOabUK.png


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?
 
Last edited:
Go check out new bots and give helpful feedback.
Joined
Jan 31, 2016
Messages
5,413
So I'm designing the tree and trying to balance it however somehow I'll end up with repeated nodes.
Let me illustrate:

eCOabUK.png


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?
No you will not. I have this happen to me as well and it's completely fine :)
 
Joined
Aug 9, 2017
Messages
20
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.
 
Joined
Mar 28, 2017
Messages
286
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.

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
 
Joined
Jun 24, 2014
Messages
172
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.

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).

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

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.
 
Joined
Feb 21, 2016
Messages
60
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.

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.

JavaScript:
public class Root extends TreeBot
{

    @Override
    public TreeTask createRootTask()
    {
        return new BranchA(new BranchB(), new LeafA());
    }
}

public class BranchA extends BranchTask
{
    public BranchA(TreeTask failure, TreeTask success)
    {
        failureTreeTask = failure;
        successTreeTask = success;
    }

    private TreeTask failureTreeTask;
    private TreeTask successTreeTask;

    @Override
    public TreeTask failureTask()
    {
        return failureTreeTask;
    }

    @Override
    public TreeTask successTask()
    {
        return successTreeTask;
    }

    @Override
    public boolean validate()
    {
        // Do some validation
        return false;
    }
}
 
Joined
Nov 3, 2013
Messages
609
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.
 
Top