package net.hoo2.auth.dsproject.snake; import java.util.*; /** * @class Node * @brief Represent a node in the Minimax tree * * @author Christos Choutouridis AEM:8997 * @email cchoutou@ece.auth.gr */ class Node { /** @name Constructors */ /** @{ */ /** Null initialize constructor */ Node () { } /** The main constructor for the Node */ Node (Node parent, int nodeDepth, int [] nodeMove, Board nodeBoard) { this.parent = parent; this.children = null; this.nodeDepth = nodeDepth; this.nodeMove = nodeMove; this.nodeBoard = nodeBoard; this.nodeEvaluation = 0; } /** A special constructor for creating a root Node */ Node (Board nodeBoard) { this.parent = null; this.children = null; this.nodeDepth = 0; this.nodeMove = new int [4]; this.nodeBoard = nodeBoard; this.nodeEvaluation = 0; } /**@} */ /** @name Get/Set interface */ /** @{ */ /** Get parent */ Node getParent() { return parent; } /** get children */ ArrayList getChildren() { return children; } /** get nodeDepth */ int getNodeDepth() { return nodeDepth; } /** get nodeMove */ int[] getNodeMove() { return nodeMove; } /** get nodeBoard */ Board getNodeBoard() { return nodeBoard; } /** get nodeEvluation */ double getNodeEvaluation (){ return nodeEvaluation; } /** set parent */ void setParent(Node parent) { this.parent = parent; } /** set children */ void setChildren(ArrayList children) { this.children = children; } /** set nodeDepth */ void setNodeDepth(int nodeDepth) { this.nodeDepth = nodeDepth; } /** set nodeMove */ void setNodeMove(int[] nodeMove) { this.nodeMove = nodeMove; } /** set nodeBoard */ void setNodeBoard(Board nodeBoard) { this.nodeBoard = nodeBoard; } /** set nodeEvaluation */ void setNodeEvaluation(double nodeEvaluation) { this.nodeEvaluation = nodeEvaluation; } /**@}*/ /** @name Public API */ /** @{ */ /** * Add a child to the tree * @param child The child to add * @return the status of the operation */ boolean addChild (Node child) { if (children == null) children = new ArrayList<>(); return children.add(child); } /**@}*/ /** @name Data members */ /** @{ */ private Node parent; /**< Back reference to parent Node */ private ArrayList children; /**< Fwd reference to leaf Nodes */ private int nodeDepth; /**< The Node's depth */ private int[] nodeMove; /**< The Node's move data [tile, initTile, points, roll]*/ private Board nodeBoard; /**< Reference to Board's copy of the current node*/ private double nodeEvaluation; /**< The Node's evaluation result */ /**@}*/ }