Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. package com.yasper.tree;
  2.  
  3. import com.runemate.game.api.script.Execution;
  4. import com.runemate.game.api.script.framework.LoopingBot;
  5.  
  6. /**
  7. * Class defining a TreeBot structure. Explores the implemented binary tree for current state and performed action.
  8. *
  9. * @author Jasper
  10. */
  11. public abstract class TreeBot extends LoopingBot {
  12.  
  13.  
  14. /**
  15. * Root of the TreeBot
  16. */
  17. public abstract TreeBotNode root();
  18.  
  19.  
  20. /**
  21. * Looping method to start at the root
  22. */
  23. @Override
  24. public final void onLoop() {
  25. evaluate(root());
  26. }
  27.  
  28. /**
  29. * Recursive method to traverse the binary tree structure
  30. *
  31. * @param node being evaluated
  32. */
  33. private void evaluate(TreeBotNode node) {
  34. if (node instanceof TreeBotLeaf) {
  35. TreeBotLeaf leaf = (TreeBotLeaf) node;
  36. for (int i = 0; i < leaf.repeat() && !leaf.traverse(); i++) {
  37. Execution.delay(leaf.sleep());
  38. }
  39. } else {
  40. if (node.traverse()) {
  41. evaluate(node.right());
  42. } else {
  43. evaluate(node.left());
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement