package org.sam.tree;

/**
 * Created by samuel on 31/07/14.
 */
public class FullTree extends Tree {
    public FullTree() {
        root = initFully(2);
    }

    public FullTree(long depth) {
        root = initFully(depth);
    }

    private INode initFully(long depth) {
        if (depth > 0) {
            int functionRandomNumber = rand.nextInt(4); // 4 functions

            if (functionRandomNumber <= 0) {
                return new AddOperationNode(initFully(depth - 1), initFully(depth -1 ));
            } else if (functionRandomNumber <= 1) {
                return new SubtractionOperationNode(initFully(depth - 1), initFully(depth -1 ));
            } else if (functionRandomNumber <= 2) {
                return new MultiplicationOperationNode(initFully(depth - 1), initFully(depth -1 ));
            } else if (functionRandomNumber <= 3) {
                return new SaveDivisionOperationNode(initFully(depth - 1), initFully(depth -1 ));
            } else {
                return new ConditionalNode(initFully(depth - 1), initFully(depth -1 ), initFully(depth - 1));
            }
        } else {
            int terminalRandomNumber = rand.nextInt(3);

            if (terminalRandomNumber <= 0) {
                return new ConstantNode((long)rand.nextInt(7));
            } else if (terminalRandomNumber <= 1) {
                return new EnemyStoneAtNode(new ConstantNode((long)rand.nextInt(7)), new ConstantNode((long)rand.nextInt(7)));
            } else {
                return new PlayerStoneAtNode(new ConstantNode((long)rand.nextInt(7)), new ConstantNode((long)rand.nextInt(7)));
            }
        }
    }
}

@@ -225,24 +225,221 @@
 th);%0A    %7D%0A%0A
+    /**%0A     * Recursive method to init a tree.%0A     * The idea behind the if-else-clauses is to provide a custom distribution of functions.%0A     * @param depth of the tree.%0A     * @return%0A     */%0A
     private 
@@ -489,24 +489,49 @@
 epth %3E 0) %7B%0A
+            // Functions%0A
             
@@ -1329,32 +1329,57 @@
        %7D else %7B%0A
+            // Terminals%0A
             int 

add comments