Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.yasper.tree;
- import com.runemate.game.api.script.Execution;
- import com.runemate.game.api.script.framework.LoopingBot;
- /**
- * Class defining a TreeBot structure. Explores the implemented binary tree for current state and performed action.
- *
- * @author Jasper
- */
- public abstract class TreeBot extends LoopingBot {
- /**
- * Root of the TreeBot
- */
- public abstract TreeBotNode root();
- /**
- * Looping method to start at the root
- */
- @Override
- public final void onLoop() {
- evaluate(root());
- }
- /**
- * Recursive method to traverse the binary tree structure
- *
- * @param node being evaluated
- */
- private void evaluate(TreeBotNode node) {
- if (node instanceof TreeBotLeaf) {
- TreeBotLeaf leaf = (TreeBotLeaf) node;
- for (int i = 0; i < leaf.repeat() && !leaf.traverse(); i++) {
- Execution.delay(leaf.sleep());
- }
- } else {
- if (node.traverse()) {
- evaluate(node.right());
- } else {
- evaluate(node.left());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement