|
- /**
- * @file MinMaxTree.java
- * @brief
- * File containing the Pacman Min-Max Tree class.
- *
- * @author Christos Choutouridis 8997 cchoutou@ece.auth.gr
- * @author Konstantina Tsechelidou 8445 konstsec@ece.auth.gr
- */
- package gr.auth.ee.dsproject.node;
-
- /**
- * @brief
- * A tree-like data structure containing move nodes to apply the min-max
- * algorithm.
- * @note
- * This is NOT a real tree. We do not insert node based on a key etc...
- */
- public class MinMaxTree
- {
- private Node89978445 root;
-
- /*
- * ============ Constructors ==============
- */
- /**
- * @brief
- * The simple constructor. Just initialize the root to null
- */
- public MinMaxTree () {
- root = null; // No root yet
- }
-
- /**
- * @brief
- * A constructor with root
- */
- public MinMaxTree (Node89978445 root) {
- setRoot (root);
- }
-
- /*
- * ========= setter ============
- */
- /** Set root */
- public Node89978445 setRoot (Node89978445 root) {
- return this.root = root;
- }
-
- /*
- * ========== Tree-like methods =============
- */
- /**
- * @brief
- * Insert a node to a parent directly.
- * This is NOT a real tree. We do not insert node based on a key
- * @param node Node to insert
- * @param parent The parent in witch to insert
- * @return Reference to inserted node
- * If insert fail, returns null
- */
- public static Node89978445 insert (Node89978445 node, Node89978445 parent) {
- if (parent.children.add (node)) {
- node.parent = parent;
- return node;
- }
- else
- return null;
- }
-
- /**
- * @brief
- * Find the child with the minimum evaluation value of a
- * specific parent and return a reference to it
- * @param parent The parent of children we scan
- * @return Reference to the child with the minimum evaluation value
- * If parent has no children null.
- */
- public static Node89978445 minChild (Node89978445 parent)
- {
- Node89978445 node = null;
- double ev, min = Globals.EVAL_MAX+1;
-
- for (int i=0 ; i<parent.children.size() ; ++i) {
- if ((ev = parent.children.get(i).getEvaluation()) < min) {
- min = ev;
- node = parent.children.get (i);
- }
- }
- return node;
- }
-
- /**
- * @brief
- * Find the child with the maximum evaluation value of a
- * specific parent and return a reference to it
- * @param parent The parent of children we scan
- * @return Reference to the child with the maximum evaluation value
- * If parent has no children null.
- */
- public static Node89978445 maxChild (Node89978445 parent)
- {
- Node89978445 node = null;
- double ev, max = Globals.EVAL_MIN-1;
-
- for (int i=0 ; i<parent.children.size() ; ++i) {
- if ((ev = parent.children.get(i).getEvaluation()) > max) {
- max = ev;
- node = parent.children.get (i);
- }
- }
- return node;
- }
-
-
- }
|