A java snake game for A.U.TH. Data structures class
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.

103 lines
3.0 KiB

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