﻿using System;

namespace StratGA
{
    public class LogicalNode : Node
    {

        public enum LogicalFunction
        {
            AND, OR, NOT
        }

        public LogicalNode(byte depth)
        {

            Random rand = new Random();
            byte probability = (byte)rand.Next(3);

            switch (probability)
            {
                case 0:
                    this.value = "&&";
                    break;
                case 1:
                    this.value = "||";
                    break;
                case 2:
                    this.value = "!";
                    break;
            }

            bool newRelationalNodeLeft = rand.Next(100) <= 20 ? true : false;
            if (newRelationalNodeLeft) this.setLeftChild(new RelationalNode(depth--));
            else this.setLeftChild(new LogicalNode(depth--));

            bool newRelationalNodeRight = rand.Next(100) <= 20 ? true : false;
            if (newRelationalNodeRight) this.setRightChild(new RelationalNode(depth--));
            else this.setRightChild(new LogicalNode(depth--));
        }

        public void setValue(LogicalFunction value)
        {
            switch (value)
            {
                case LogicalFunction.AND:
                    this.value = "&&";
                    break;
                case LogicalFunction.OR:
                    this.value = "||";
                    break;
                case LogicalFunction.NOT:
                    this.value = "!";
                    break;
            }
        }
    }
}
