示例#1
0
        private void AddShape(ShapeType shapeType)
        {
            var shape = new ShapeChromosome(shapeType);

            shape.InitializeDNA();

            switch (shapeType)
            {
            case ShapeType.TRIANGLE:
                TriangleShapes.Add(shape);
                break;

            case ShapeType.SQUARE:
                SquareShapes.Add(shape);
                break;

            case ShapeType.CIRCLE:
                ElipseShapes.Add(shape);
                break;

            case ShapeType.PENTAGON:
                PentagonShapes.Add(shape);
                break;
            }
        }
示例#2
0
        public void InitializeFromDNA(IndividualListData individualData)
        {
            this.Adaptation = Convert.ToDouble(individualData.Fitness);

            this.DNAstring.Append(individualData.IndividualDNA);

            ShapeChromosome shapeChromosome;

            string informationBuffer = "";

            PositionDNA positionDNA;

            for (int i = 0; i < DNAstring.Length;)
            {
                if (DNAstring[i] == 'T')
                {
                    i++;

                    while (DNAstring[i] != 'S')
                    {
                        shapeChromosome = new ShapeChromosome(ShapeType.TRIANGLE);

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        shapeChromosome.ColourShape.RedColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.GreenColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.BlueColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.AlphaColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;


                        positionDNA = new PositionDNA(); // 1

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 2

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 3

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        TriangleShapes.Add(shapeChromosome); // TRIANGLE
                    }
                }
                else if (DNAstring[i] == 'S')
                {
                    i++;

                    while (DNAstring[i] != 'E')
                    {
                        shapeChromosome = new ShapeChromosome(ShapeType.SQUARE);

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        shapeChromosome.ColourShape.RedColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.GreenColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.BlueColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.AlphaColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;


                        positionDNA = new PositionDNA(); // 1

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 2

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 3

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 4

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        SquareShapes.Add(shapeChromosome); // SQUARE
                    }
                }
                else if (DNAstring[i] == 'E')
                {
                    i++;

                    while (DNAstring[i] != 'P')
                    {
                        shapeChromosome = new ShapeChromosome(ShapeType.CIRCLE);

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        shapeChromosome.ColourShape.RedColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.GreenColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.BlueColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.AlphaColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;


                        positionDNA = new PositionDNA(); // 1

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 2

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        ElipseShapes.Add(shapeChromosome); // ELIPSE
                    }
                }
                else if (DNAstring[i] == 'P')
                {
                    i++;

                    while (DNAstring[i] != 'X')
                    {
                        shapeChromosome = new ShapeChromosome(ShapeType.PENTAGON);

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        shapeChromosome.ColourShape.RedColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.GreenColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.BlueColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        shapeChromosome.ColourShape.AlphaColour = (byte)Int32.Parse(informationBuffer);
                        informationBuffer = "";
                        i++;


                        positionDNA = new PositionDNA(); // 1

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 2

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 3

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 4

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        positionDNA = new PositionDNA(); // 5

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }


                        positionDNA.PositionX = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;

                        while (DNAstring[i] != ' ')
                        {
                            informationBuffer += DNAstring[i];
                            i++;
                        }

                        positionDNA.PositionY = Int32.Parse(informationBuffer);
                        informationBuffer     = "";
                        i++;
                        shapeChromosome.PositionsShape.Add(positionDNA);

                        PentagonShapes.Add(shapeChromosome); // PENTAGON
                    }
                }
                else if (DNAstring[i] == 'X')
                {
                    return;
                }
                else
                {
                    i++;
                }
            }
        }