Exemplo n.º 1
0
        public AminoAcid Calculate()
        {
            AminoAcid node   = new AminoAcid(Input[0]);
            Random    random = new Random();

            for (int i = 1; i < Input.Length; i++)
            {
                AminoAcid newNode = new AminoAcid(Input[i])
                {
                    X = node.X,
                    Y = node.Y
                };
                int rvalue = random.Next(4);
                switch (rvalue)
                {
                case 0:
                    ++newNode.X;
                    break;

                case 1:
                    --newNode.X;
                    break;

                case 2:
                    ++newNode.Y;
                    break;

                case 3:
                    --newNode.Y;
                    break;
                }
                AminoAcid testNode    = node;
                bool      notRepeated = true;
                while (testNode != null)
                {
                    if (testNode.Equals(newNode))
                    {
                        notRepeated = false;
                        --i;
                        break;
                    }
                    testNode = testNode.Previous;
                }

                if (notRepeated)
                {
                    newNode.Previous = node;
                    node             = newNode;
                }
            }
            return(node);
        }
Exemplo n.º 2
0
        public AminoAcid GenerateProtein()
        {
            AminoAcid node   = new AminoAcid(Input[0]);
            Random    random = new Random();

            int rvalue = -1;

            // To check if node is not locked
            int count = 0;

            for (int i = 1; i < Input.Length; i++)
            {
                if (count == 4)
                {
                    return(null);
                }

                AminoAcid newNode = new AminoAcid(Input[i])
                {
                    X = node.X,
                    Y = node.Y
                };
                if (rvalue == -1)
                {
                    do
                    {
                        rvalue = random.Next(4);
                    } while (rvalue == node.PrevDirection);
                }
                else
                {
                    rvalue = (rvalue + 1) % 4;
                }
                switch (rvalue)
                {
                case 0:
                    newNode.Up();
                    break;

                case 1:
                    newNode.Down();
                    break;

                case 2:
                    newNode.Left();
                    break;

                case 3:
                    newNode.Right();
                    break;
                }
                AminoAcid testNode    = node;
                bool      notRepeated = true;
                while (testNode != null)
                {
                    if (testNode.Equals(newNode))
                    {
                        ++count;
                        notRepeated = false;
                        --i;
                        break;
                    }
                    testNode = testNode.Previous;
                }

                if (notRepeated)
                {
                    newNode.Previous = node;
                    node             = newNode;
                    rvalue           = -1;
                }
            }
            return(node);
        }