Exemple #1
0
    public void InputSet(HashSet <Jewel> set, bool leftInput)
    {
        if (leftInput)
        {
            leftSet = set;
        }
        else
        {
            rightSet = set;
        }

        // some logic to deal with lighting ropes
        int filledSets = 0;

        if (leftSet != null && leftSet.Count > 0)
        {
            filledSets += 1;
        }
        if (rightSet != null && rightSet.Count > 0)
        {
            filledSets += 1;
        }

        if (rope)
        {
            rope.TurnOff();
        }
        if (filledSets > 0)
        {
            if (filledSets == 1)
            {
                if (rope)
                {
                    rope.TurnOn(true);
                }
            }
            else
            {
                if (rope)
                {
                    rope.TurnOn(false);
                }
            }
        }

        HashSet <Jewel> outputSet = new HashSet <Jewel>();

        switch (type)
        {
        case Operators.Union:
            if (leftSet == null && rightSet == null)
            {
                output.InputSet(null);
            }
            else
            {
                if (leftSet == null)
                {
                    leftSet = new HashSet <Jewel>();
                }
                if (rightSet == null)
                {
                    rightSet = new HashSet <Jewel>();
                }
                outputSet.UnionWith(leftSet);
                outputSet.UnionWith(rightSet);
                //Debug.Log("Union left: ");
                //setToString(leftSet);
                //Debug.Log("Union right: ");
                //setToString(rightSet);
                output.InputSet(outputSet);
                //Debug.Log("Union output: ");
                //setToString(outputSet);
            }
            break;

        case Operators.Intersect:
            if (leftSet == null || rightSet == null)
            {
                output.InputSet(null);
            }
            else
            {
                outputSet.UnionWith(leftSet);
                outputSet.IntersectWith(rightSet);
                output.InputSet(outputSet);
                //Debug.Log("Intersect output: ");
                //setToString(outputSet);
            }
            break;

        case Operators.Difference:
            if (rightSet == null)
            {
                output.InputSet(null);
            }
            else
            {
                if (leftSet == null)
                {
                    leftSet = new HashSet <Jewel>();
                }
                foreach (Jewel jewel in leftSet)
                {
                    if (!rightSet.Contains(jewel))
                    {
                        outputSet.Add(jewel);
                    }
                }
                output.InputSet(outputSet);
                //Debug.Log("Difference output: ");
                //setToString(outputSet);
            }
            break;
        }
    }