Welcome!

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

Sign up now!

Request Tries In TreeBot

Should this be implemented?

  • Yes, definitely.

  • Yes, with some changes.

  • No, not at all.

  • No, not useful enough.


Results are only viewable after voting.
Joined
Mar 16, 2018
Messages
2
Current Treebot
Each Branch is a validation of a single Boolean.
- Validation is True -> Go to success child
- Validation is False -> Got to failure child

How can we improve upon this?

Well, the main problem with using a BST is that each sub-child can only return a single leaf or a single
branch on success or failure. It can never return multiple leaves and branches.This causes a lot of extra bloat-code that doesn't necessarily have to be there.

Observe:

Lets say there is a weapon in the bank. After searching the bank for the weapon, the current
branch validation returns true and it executes the successTask. Now, you want to both withdraw AND equip it, but you know that once the weapon is in your inventory, the parent branch would validate to false and wouldn't execute another leafTask. This causes you to create an entirely new LeafTask class, AKA LeafWithdrawAndEquip, or at least share variables from child -> parent treeTasks.

Solution

A better way to do this would be to utilize the structure of a Trie by returning a LinkedList or
Queue of TreeTasks on each success or failure.

Then, each of these would be executed in the same order they were put in (FIFO). Anything in this
Queue or LinkedList would be executed before restarting from the root of the tree.
Code:
// in the onLoop, there would be something like this, executing one LEAF per loop,
// branches add items onto the queue.
treetask = q.poll();
while(treetask != null):
    if leaf
       leaf.execute
       break? // only execute 1 task per onLoop?
    else if branch
        if branch.validate
             add all branch.success() to queue
        else
            add all branch.failure to queue
   treetask = q.poll();


Implementing Into the current API:

The TrieBranchTask (or something similar) would act as said above and could be implemented alongside the already existing TreeBot API. No need to create an entirely diofferent bot type.

Observe (using TrieBranchTask)
Lets say there is a weapon in the bank. After searching the bank for the weapon, the current
branch validation returns true and it executes the successTask. Now, you want to both withdraw AND equip it, but you know that once the weapon is in your inventory, the parent branch would validate to false and wouldn't execute another LeafTask.
Now:
new Queue
addToQueue(LeafWithdraw(item))
addToQueue(LeafEquip(item))
return Queue

EDIT:
MUCH improved pseudo-code.
 
Last edited:
Joined
Aug 23, 2015
Messages
1,970
Since you're looking for feedback
  • Treebot is already intimidating enough to a lot of new devs
  • You can always make a custom bot framework that accomplishes this
  • You CAN return to the same leaf just by making the validate in the branch leading to it an OR with logic to handle what you want to accomplish
 
Joined
Mar 16, 2018
Messages
2
Since you're looking for feedback
  • Treebot is already intimidating enough to a lot of new devs
  • You can always make a custom bot framework that accomplishes this
  • You CAN return to the same leaf just by making the validate in the branch leading to it an OR with logic to handle what you want to accomplish

Thanks for the feedback!

1) agreed, but we have really great tutorials here on RuneMate. Also this wouldn't be a completely new AbstractBot type, as the title suggests. It would be another Treetask like that of a BranchTask or LeafTask.

2) I'll Most likely do this, but it would be nice to see implemented into the API because I think it is something other authors could use.

3) I looked into using OR logic in the validate branch, but this seems a little messy to me, which is why i suggested using Tries. This way it is a simple 1 line statement in the successTask or failureTask methods instead of adding completely new variables into the program to expand the validation logic, making it more complex.

At least with the way I am currently structuring my bots, Tries would be extremely useful. I am trying to keep as many branches as I can outside of my main bot class and am only instantiating branches in constructors of other branches.
 
12 year old normie
Joined
Jan 8, 2015
Messages
2,768
I don't quite understand what the usecase is of executing two success tasks at once. Your case about withdrawing and equipping a weapon doesn't really make sense because your argument is that it has to create new branches again to go to withdrawing. The classes however can be stored in variables and just use getters to pass them on as success or failure task. They won't be created over and over again.

I could see how it would require more resources for going through validators again, but your withdrawing leaf would be somewhere else in the tree, hopefully with less bank querying and other nonsense which shouldn't burden your cpu so much.

The queue system is basically taskbot as I read it. You throw a bunch of tasks in a queue and it'll execute the first one of which the validator returns true. Correct me if I'm wrong.
 
Top