public void SetInstruction(InstructionObject I)
 {
     instructionText.text = I.InstructionText;
     closeButton.onClick.RemoveAllListeners();
     closeButton.onClick.AddListener(I.canvasEvent.Invoke);
     closeButton.gameObject.SetActive(false);
 }
Example #2
0
    // Create List of Instruction Objects to insert as node into DoublyLinkedList
    public static List <InstructionObject> CreateInstructList(InstructionObject toInsert)
    {
        InstructionList = new List <InstructionObject>();
        InstructionList.Add(toInsert);

//		foreach (InstructionObject testing in InstructionList)
//		{
//			Debug.Log (testing.TranscriptionSimObject.MainType + " " + testing.TranscriptionSimObject.Subtype + " " + testing.TranscriptionSimObject.StartPosition);
//		}

        return(InstructionList);
    }
Example #3
0
        public static void Step1(string[] instructions)
        {
            Dictionary <string, UInt16> circuitBoardGates = new Dictionary <string, UInt16>();
            List <InstructionObject>    arrInstructions   = new List <InstructionObject>();

            foreach (string instruction in instructions)
            {
                InstructionObject InstObj = new InstructionObject();

                InstObj.OrgLine = instruction;

                if (instruction.Contains("AND"))
                {
                    InstObj.Action = 1;
                    InstObj.Data   = instruction.Replace(" AND ", ";").Replace(" -> ", ";").Split(';');
                }
                else if (instruction.Contains("OR"))
                {
                    InstObj.Action = 2;
                    InstObj.Data   = instruction.Replace(" OR ", ";").Replace(" -> ", ";").Split(';');
                }
                else if (instruction.Contains("LSHIFT"))
                {
                    InstObj.Action = 3;
                    InstObj.Data   = instruction.Replace(" LSHIFT ", ";").Replace(" -> ", ";").Split(';');
                }
                else if (instruction.Contains("RSHIFT"))
                {
                    InstObj.Action = 4;
                    InstObj.Data   = instruction.Replace(" RSHIFT ", ";").Replace(" -> ", ";").Split(';');
                }
                else if (instruction.Contains("NOT"))
                {
                    InstObj.Action = 5;
                    InstObj.Data   = instruction.Replace("NOT ", "").Replace(" -> ", ";").Split(';');
                }
                else
                {
                    InstObj.Action = 6;
                    InstObj.Data   = instruction.Replace(" -> ", ";").Split(';');
                }

                arrInstructions.Add(InstObj);
            }

            while (arrInstructions.Count > 0)
            {
                for (int i = 0; i < arrInstructions.Count; i++)
                {
                    InstructionObject instruction = arrInstructions[i];

                    bool canBeSolved = true;

                    UInt16 value = 0;
                    UInt16 op1   = 0;
                    UInt16 op2   = 0;

                    if (circuitBoardGates.ContainsKey(instruction.Data[0]))
                    {
                        op1 = circuitBoardGates[instruction.Data[0]];
                    }
                    else if (!UInt16.TryParse(instruction.Data[0], out op1))
                    {
                        canBeSolved = false;
                    }

                    if (instruction.Data.Length > 2)
                    {
                        if (circuitBoardGates.ContainsKey(instruction.Data[1]))
                        {
                            op2 = circuitBoardGates[instruction.Data[1]];
                        }
                        else if (!UInt16.TryParse(instruction.Data[1], out op2))
                        {
                            canBeSolved = false;
                        }
                    }

                    if (canBeSolved)
                    {
                        switch (instruction.Action)
                        {
                        case 1:
                            value = (UInt16)(op1 & op2);
                            break;

                        case 2:
                            value = (UInt16)(op1 | op2);
                            break;

                        case 3:
                            value = (UInt16)(op1 << op2);
                            break;

                        case 4:
                            value = (UInt16)(op1 >> op2);
                            break;

                        case 5:
                            value = (UInt16)(~op1);
                            break;

                        case 6:
                            value = op1;
                            break;
                        }

                        circuitBoardGates[instruction.Data[instruction.Data.Length - 1]] = value;

                        arrInstructions.Remove(instruction);
                    }
                }
            }

            int signalOnWire = circuitBoardGates["a"];

            WireOverrideValue = signalOnWire;

            Console.WriteLine("Answer Part 1 : " + signalOnWire);
        }
Example #4
0
    //
    // CREATES INSTRUCTION LIST
    //
    public IEnumerator ParseObjects(List <ObjectsOnDNA> AnimateList, List <ObjectsOnDNA> lookAhead, List <ObjectsOnDNA> twoAhead, List <ObjectsOnDNA> threeAhead)
    {
        ///
        /// HANDLES OBJECT CHANGES ---> MOVE, ALTER, DELETE
        ///
        foreach (ObjectsOnDNA cool in AnimateList)
        {
            var found = false;

            if (k == VizGeneration.startStep)
            {
                if (cool.MainType == "'Nucleosome'")
                {
                    InstructionObject initNucCreate = new InstructionObject(cool, "NucleosomeClass.CreateNucleosome");
                    listOfInstructions.Add(initNucCreate);
                }

                if (cool.MainType == "'Transcription_Factor'")
                {
                    InstructionObject initTFCreate = new InstructionObject(cool, "TranscriptionFactorClass.CreateTranscriptionFactor");
                    listOfInstructions.Add(initTFCreate);
                }

                if (cool.MainType == "'Transcriptional_Machinery'")
                {
                    InstructionObject initTMCreate = new InstructionObject(cool, "TranscriptionalMachineryClass.CreateTranscriptionalMachinery");
                    listOfInstructions.Add(initTMCreate);
                }
            }



            if (cool.MainType == "'Nucleosome'")
            {
                foreach (ObjectsOnDNA tests in lookAhead)
                {
                    if (cool.MainType == tests.MainType && cool.Subtype == tests.Subtype && cool.Length == tests.Length)
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
//							Debug.Log("SAME NUCLEOSOME " + cool.StartPosition);
                        }
                        else if (Math.Abs(tests.StartPosition - cool.StartPosition) <= 10)
                        {
                            found = true;
//							Debug.Log ("Time to move" + cool.StartPosition + " to " + tests.StartPosition);

                            var    tempInt1    = tests.StartPosition;
                            string tempString1 = tempInt1.ToString();

                            InstructionObject moveNuc = new InstructionObject(cool, tempString1);
                            listOfInstructions.Add(moveNuc);
                        }
                        else
                        {
//							???
                        }
                    }
                    else if (cool.MainType == tests.MainType && cool.Length == tests.Length)
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
//							Debug.Log ("CHANGE NUCLEOSOME SUBTYPE TO " + tests.Subtype);

                            InstructionObject changeNuc = new InstructionObject(cool, tests.Subtype);
                            listOfInstructions.Add(changeNuc);
                        }
                        else if (Math.Abs(tests.StartPosition - cool.StartPosition) <= 10)
                        {
                            found = true;
//							Debug.Log ("NUCLEOSOME MOVING AND CHANGING SUBTYPE");

                            var    tempInt2    = tests.StartPosition;
                            string tempString2 = tempInt2.ToString();

                            InstructionObject firstChangeNuc = new InstructionObject(cool, tests.Subtype);
                            InstructionObject thenMoveNuc    = new InstructionObject(cool, tempString2);
                            listOfInstructions.Add(firstChangeNuc);
                            listOfInstructions.Add(thenMoveNuc);
                        }
                    }
                }

                // HANDLING DELETION!!!
                if (!found)
                {
                    var waitOnIt = false;

                    foreach (ObjectsOnDNA wait in twoAhead)
                    {
                        if (cool.MainType == wait.MainType && Math.Abs(wait.StartPosition - cool.StartPosition) <= 10 && cool.Length == wait.Length)
                        {
                            InstructionObject subNuc = new InstructionObject(cool, wait.Subtype);
                            listOfInstructions.Add(subNuc);

                            waitOnIt = true;
                        }
                        else
                        {
                            foreach (ObjectsOnDNA longer in threeAhead)
                            {
                                if (cool.MainType == longer.MainType && Math.Abs(longer.StartPosition - cool.StartPosition) <= 10 && cool.Length == longer.Length)
                                {
                                    InstructionObject subNuc = new InstructionObject(cool, longer.Subtype);
                                    listOfInstructions.Add(subNuc);
                                    waitOnIt = true;
                                }
                            }
                        }
                    }

                    if (waitOnIt == false)
                    {
//						Debug.Log ("DELETE " + cool.MainType + " at position " + cool.StartPosition);

                        InstructionObject delNuc = new InstructionObject(cool, "ObjectsOnDNA.DeleteObject");
                        listOfInstructions.Add(delNuc);
                    }
                    else
                    {
//						Debug.Log ("Move it on up.");

                        InstructionObject waitNuc = new InstructionObject(cool, "WAIT");
                        listOfInstructions.Add(waitNuc);
                    }
                }


                //
                // TF HANDLING
                //
            }
            else if (cool.MainType == "'Transcription_Factor'")
            {
                foreach (ObjectsOnDNA tests in lookAhead)
                {
                    if (cool.MainType == tests.MainType && cool.Subtype == tests.Subtype && cool.Length == tests.Length)
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
//							Debug.Log("SAME TF " + cool.StartPosition);
                        }
                    }
                }

                // DELETION
                if (!found)
                {
                    var waitOnIt = false;

                    foreach (ObjectsOnDNA wait in twoAhead)
                    {
                        if (cool.MainType == wait.MainType && cool.Subtype == wait.Subtype && cool.StartPosition == wait.StartPosition && cool.Length == wait.Length)
                        {
                            waitOnIt = true;
                        }
                        else
                        {
                            foreach (ObjectsOnDNA longer in threeAhead)
                            {
                                if (cool.MainType == longer.MainType && cool.Subtype == longer.Subtype && cool.StartPosition == longer.StartPosition && cool.Length == longer.Length)
                                {
                                    waitOnIt = true;
                                }
                            }
                        }
                    }

                    if (waitOnIt == false)
                    {
//						Debug.Log ("DELETE " + cool.MainType + " at position " + cool.StartPosition);
                        InstructionObject delTF = new InstructionObject(cool, "ObjectsOnDNA.DeleteObject");
                        listOfInstructions.Add(delTF);
                    }
                    else
                    {
                        if (UnityEngine.Random.Range(0, 10) <= 10)
                        {
//							Debug.Log ("Move it on up.");

                            InstructionObject waitTF = new InstructionObject(cool, "WAIT");
                            listOfInstructions.Add(waitTF);
                        }
                        else
                        {
//							Debug.Log ("DELETE " + cool.MainType + " at position " + cool.StartPosition);
                            InstructionObject delTF = new InstructionObject(cool, "ObjectsOnDNA.DeleteObject");
                            listOfInstructions.Add(delTF);
                        }
                    }
                }



                //
                // TM HANDLING
                //
            }
            else if (cool.MainType == "'Transcriptional_Machinery'")
            {
                foreach (ObjectsOnDNA tests in lookAhead)
                {
                    if (cool.MainType == tests.MainType && cool.Subtype == tests.Subtype && cool.Length == tests.Length)
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
//							Debug.Log("SAME TM " + cool.StartPosition);
                        }
                        else if (Math.Abs(cool.StartPosition - tests.StartPosition) <= 3)
                        {
                            found = true;
//							Debug.Log ("MOVE TM" + cool.StartPosition + " to " + tests.StartPosition);

                            var    tempInt1    = tests.StartPosition;
                            string tempString1 = tempInt1.ToString();

                            InstructionObject moveTM = new InstructionObject(cool, tempString1);
                            listOfInstructions.Add(moveTM);
                        }
                    }
                    else if (cool.MainType == tests.MainType && cool.Length == tests.Length)
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
//							Debug.Log ("CHANGE TM SUBTYPE TO " + tests.Subtype);

                            InstructionObject changeTM = new InstructionObject(cool, tests.Subtype);
                            listOfInstructions.Add(changeTM);
                        }
                        else if (Math.Abs(cool.StartPosition - tests.StartPosition) <= 3)
                        {
                            found = true;
//							Debug.Log ("TM MOVING AND CHANGING SUBTYPE");

//							var tempInt2 = tests.StartPosition;
                            string tempString2 = tests.StartPosition.ToString();

                            InstructionObject firstChangeTM = new InstructionObject(cool, tests.Subtype);
                            InstructionObject thenMoveTM    = new InstructionObject(cool, tempString2);
                            listOfInstructions.Add(firstChangeTM);
                            listOfInstructions.Add(thenMoveTM);
                        }
                    }
                }

                // HANDLING DELETION!!!
                if (!found)
                {
//					Debug.Log ("DELETE " + cool.MainType + " at position " + cool.StartPosition);
                    InstructionObject delTM = new InstructionObject(cool, "ObjectsOnDNA.DeleteObject");
                    listOfInstructions.Add(delTM);
                }
            }
        }


        ///
        /// HANDLES OBJECT CREATION
        ///
        foreach (ObjectsOnDNA tests in lookAhead)
        {
            var found = false;

            foreach (ObjectsOnDNA cool in AnimateList)
            {
                if (tests.MainType == cool.MainType && cool.Subtype == tests.Subtype && cool.Length == tests.Length)
                {
                    if (tests.MainType == "'Nucleosome'")
                    {
                        if (Math.Abs(cool.StartPosition - tests.StartPosition) <= 10)
                        {
                            found = true;
                        }
                    }
                    else if (tests.MainType == "'Transcriptional_Machinery'")
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
                        }
                        else if (Math.Abs(cool.StartPosition - tests.StartPosition) <= 3)
                        {
                            found = true;
                        }
                    }
                    else if (tests.MainType == "'Transcription_Factor'")
                    {
                        if (cool.StartPosition == tests.StartPosition)
                        {
                            found = true;
                        }
                    }
                }
                else if (cool.Subtype != tests.Subtype && tests.MainType != "'Transcription_Factor'")
                {
                    if (cool.MainType == tests.MainType && cool.StartPosition == tests.StartPosition && cool.Length == tests.Length)
                    {
                        found = true;
                    }
                }


                // IF MOVE AND SUBTYPE CHANGE
                if (cool.MainType == tests.MainType && cool.Length == tests.Length)
                {
                    if (cool.MainType == "'Nucleosome'")
                    {
                        if (Math.Abs(tests.StartPosition - cool.StartPosition) <= 10)
                        {
                            found = true;
                        }
                    }
                    else if (cool.MainType == "'Transcriptional_Machinery'")
                    {
                        if (Math.Abs(cool.StartPosition - tests.StartPosition) <= 3)
                        {
                            found = true;
                        }
                    }
                }
            }

            if (!found)
            {
//				Debug.Log ("CREATE " + tests.MainType + " at Position " + tests.StartPosition);

                if (tests.MainType == "'Nucleosome'")
                {
                    InstructionObject nowCreate = new InstructionObject(tests, "NucleosomeClass.CreateNucleosome");
                    listOfInstructions.Add(nowCreate);
                }
                else if (tests.MainType == "'Transcription_Factor'")
                {
                    InstructionObject nowCreate = new InstructionObject(tests, "TranscriptionFactorClass.CreateTranscriptionFactor");
                    listOfInstructions.Add(nowCreate);
                }
                else if (tests.MainType == "'Transcriptional_Machinery'")
                {
                    InstructionObject nowCreate = new InstructionObject(tests, "TranscriptionalMachineryClass.CreateTranscriptionalMachinery");
                    listOfInstructions.Add(nowCreate);
                }
            }
        }



        ///
        /// RETURN LIST OF INSTRUCTIONS
        ///

        yield return(listOfInstructions);
    }