You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.3 KiB

  1. /**
  2. * @file Node.java
  3. *
  4. * @author
  5. * Anastasia Foti AEM:8959
  6. * <anastaskf@ece.auth.gr>
  7. *
  8. * @author
  9. * Christos Choutouridis AEM:8997
  10. * <cchoutou@ece.auth.gr>
  11. */
  12. package host.labyrinth;
  13. import java.util.ArrayList;
  14. /**
  15. * Node object for minimax tree.
  16. */
  17. class Node {
  18. /** @name Constructors */
  19. /** @{ */
  20. /** Null initialize constructor */
  21. Node () { }
  22. /** The main constructor for the Node */
  23. Node (Node parent, int nodeDepth, int [] nodeMove, Board nodeBoard, double nodeEvaluation) {
  24. this.parent = parent;
  25. this.children = null;
  26. this.nodeDepth = nodeDepth;
  27. this.nodeMove = nodeMove;
  28. this.nodeBoard = nodeBoard;
  29. this.nodeEvaluation = nodeEvaluation;
  30. this.path = null;
  31. }
  32. /** A special constructor for creating a root Node */
  33. Node (Board nodeBoard) {
  34. this.parent = null;
  35. this.children = null;
  36. this.nodeDepth = 0;
  37. this.nodeMove = new int [4];
  38. this.nodeBoard = nodeBoard;
  39. this.nodeEvaluation = 0;
  40. this.path = null;
  41. }
  42. /**@} */
  43. /** @name Get/Set interface */
  44. /** @{ */
  45. /** Get parent */
  46. Node getParent() { return parent; }
  47. /** get children */
  48. ArrayList<Node>
  49. getChildren() { return children; }
  50. /** get nodeDepth */
  51. int getNodeDepth() { return nodeDepth; }
  52. /** get nodeMove */
  53. int[] getNodeMove() { return nodeMove; }
  54. /** get nodeBoard */
  55. Board getNodeBoard() { return nodeBoard; }
  56. /** get nodeEvluation */
  57. double getNodeEvaluation (){ return nodeEvaluation; }
  58. /** get path */
  59. Node getPath() { return path; }
  60. /** set parent */
  61. void setParent(Node parent) { this.parent = parent; }
  62. /** set children */
  63. void setChildren(ArrayList<Node> children) {
  64. this.children = children;
  65. }
  66. /** set nodeDepth */
  67. void setNodeDepth(int nodeDepth) {
  68. this.nodeDepth = nodeDepth;
  69. }
  70. /** set nodeMove */
  71. void setNodeMove(int[] nodeMove) {
  72. this.nodeMove = nodeMove;
  73. }
  74. /** set nodeBoard */
  75. void setNodeBoard(Board nodeBoard) {
  76. this.nodeBoard = nodeBoard;
  77. }
  78. /** set nodeEvaluation */
  79. void setNodeEvaluation(double nodeEvaluation) {
  80. this.nodeEvaluation = nodeEvaluation;
  81. }
  82. /** set path */
  83. void setPath (Node path) {
  84. this.path = path;
  85. }
  86. /**@}*/
  87. /** @name Public API */
  88. /** @{ */
  89. /**
  90. * Add a child to the tree
  91. * @param child The child to add
  92. * @return the status of the operation
  93. */
  94. boolean addChild (Node child) {
  95. if (children == null)
  96. children = new ArrayList<>();
  97. return children.add(child);
  98. }
  99. /**@}*/
  100. /** @name Data members */
  101. /** @{ */
  102. private Node parent; /**< Back reference to parent Node */
  103. private ArrayList<Node> children; /**< Fwd reference to leaf Nodes */
  104. private int nodeDepth; /**< The Node's depth */
  105. private int[] nodeMove; /**< The Node's move data [tile, initTile, points, roll]*/
  106. private Board nodeBoard; /**< Reference to Board's copy of the current node*/
  107. private double nodeEvaluation; /**< The Node's evaluation result */
  108. private Node path; /**< The minimax evaluation path */
  109. /**@}*/
  110. }