Example #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);
        }
Example #2
0
        public override bool Equals(object?obj)
        {
            AminoAcid testAcid = obj as AminoAcid;

            if (testAcid == null)
            {
                return(false);
            }

            if (testAcid.X == X && testAcid.Y == Y)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        private static void PrintProtein(AminoAcid proteinHead, int size)
        {
            StringBuilder sb   = new StringBuilder();
            AminoAcid     node = proteinHead;

            string[,] charArray = new string[size * 2, size * 2];
            int halfSize = size / 2;

            while (node != null)
            {
                string nodeName = node.Type.ToString() + size;
                charArray[node.X + halfSize + 1, node.Y + halfSize + 1] = nodeName;
                node = node.Previous;
                --size;
            }

            for (int i = 0; i < charArray.GetLength(0); i++)
            {
                for (int j = 0; j < charArray.GetLength(1); j++)
                {
                    if (charArray[i, j] != null)
                    {
                        sb.Append(charArray[i, j].PadRight(3));
                    }
                    else
                    {
                        sb.Append(' ', 3);
                    }
                }
                sb.Append(Environment.NewLine);
            }

            string output = sb.ToString();

            System.Console.WriteLine(output);
        }
        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);
        }