using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LNodeSummation : LNode
{
    List<LNode> inputs = new List<LNode>();
    List<float> weights = new List<float>();
    
    public LNodeSummation()
    { 
    }

    public void AddNode(LNode node)
    {
        inputs.Add(node);
        this.weights.Add(1);
    }

    public void AddNode(LNode node, float weight)
    {
        this.inputs.Add(node);
        this.weights.Add(weight);
    }

    // Calculates average of nodes weight by a weight
    public override float getOutput()
    {
        float output = 0f;
        float weight = 0;
        for (int i = 0; i < inputs.Count; i++) {         
            output += inputs[i].getOutput() * weights[i];
            weight += weights[i];
        }

        output /= weight;
        
        return Mathf.Clamp01(output);
    }

}
