- Joined
- Mar 16, 2018
- Messages
- 2
- Thread Author
- #1
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:
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.
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)
EDIT: MUCH improved pseudo-code.
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.
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
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: