Exemplo n.º 1
0
        public GARepresentation Duplicate()
        {
            GARepresentation newrep = new GARepresentation(MaxX, MaxY);

            foreach (GAShape gp in Shapes)
            {
                GAShape newgap = gp.Duplicate(newrep);
                newrep.Shapes.Add(newgap);
            }
            newrep.BackgroundColour = BackgroundColour;

            newrep.OpChangeColour = OpChangeColour;
            newrep.OpLinesCurves  = OpLinesCurves;
            newrep.OpPointAdded   = OpPointAdded;
            newrep.OpPointMoved   = OpPointMoved;
            newrep.OpPointRemove  = OpPointRemove;
            newrep.OpSwapPoints   = OpSwapPoints;

            newrep.OpShapeAdd    = OpShapeAdd;
            newrep.OpShapeRemove = OpShapeRemove;
            newrep.OpShapeSplit  = OpShapeSplit;
            newrep.OpShapeMerged = OpShapeMerged;

            newrep.OpShapeSwap = OpShapeSwap;

            newrep.Generation = Generation;
            newrep.Iterations = Iterations;

            newrep.UpdateTotalPoints();

            return(newrep);
        }
Exemplo n.º 2
0
        private void AddShape(ThreadSafeRandom rd, GAProjectProperties prop, int tochange)
        {
            GAShape gap = GAShape.CreateRandom(rd, prop, this);

            Shapes.Insert(tochange, gap);
            OpShapeAdd++;
        }
Exemplo n.º 3
0
        private void Split(Random rd)
        {
            int cur = 0;

            GAShape gp = null;

            Queue <GAShape> nw = new Queue <GAShape>();

            while (cur < PolyPoints.Count && ((PolyPoints.Count - cur) > 2))
            {
                gp = Duplicate(Owner);
                gp.PolyPoints.Clear();
                for (int i = 0; i < 3 + rd.Next(PolyPoints.Count - cur); i++)
                {
                    gp.PolyPoints.Add(PolyPoints[cur++]);
                }
                nw.Enqueue(gp);
            }
            while (cur < PolyPoints.Count)
            {
                gp.PolyPoints.Add(PolyPoints[cur++]);
            }

            gp         = nw.Dequeue();
            PolyPoints = gp.PolyPoints;
            while (nw.Count > 0)
            {
                Owner.Shapes.Add(nw.Dequeue());
            }
        }
Exemplo n.º 4
0
 private static void InitSeedBlocks(int granule, int x, int y, GAShape gap)
 {
     // Blocks
     gap.PolyPoints.Add(new PointF(x, y));
     gap.PolyPoints.Add(new PointF(x + granule, y));
     gap.PolyPoints.Add(new PointF(x + granule, y + granule));
     gap.PolyPoints.Add(new PointF(x, y + granule));
 }
Exemplo n.º 5
0
        private static void InitSeedCircles(int plug, int x, int y, GAShape gap)
        {
            // Spheres
            float hplug = plug / 2;

            gap.PolyPoints.Add(new PointF(x + hplug, y));
            gap.PolyPoints.Add(new PointF(x + plug, y + hplug));
            gap.PolyPoints.Add(new PointF(x + hplug, y + plug));
            gap.PolyPoints.Add(new PointF(x, y + hplug));
        }
Exemplo n.º 6
0
        public GAShape Duplicate(GARepresentation newowner)
        {
            GAShape newgap = new GAShape(newowner);

            newgap.PolyColor = this.PolyColor;
            newgap.Type      = this.Type;

            foreach (Point p in PolyPoints)
            {
                newgap.PolyPoints.Add(new Point(p.X, p.Y));
            }
            return(newgap);
        }
Exemplo n.º 7
0
        private void SwapShapes(ThreadSafeRandom rd, int tochange)
        {
            int toswap = tochange;

            while (toswap == tochange)
            {
                toswap = rd.Next(Shapes.Count);
            }
            GAShape temp = Shapes[tochange];

            Shapes[tochange] = Shapes[toswap];
            Shapes[toswap]   = temp;
            OpShapeSwap++;
        }
Exemplo n.º 8
0
        public void ReadBinary(BinaryReader br)
        {
            Generation = br.ReadUInt32();
            Iterations = br.ReadUInt32();
            MaxX       = br.ReadInt32();
            MaxY       = br.ReadInt32();

            int count = br.ReadInt32();

            Shapes.Clear();

            for (int i = 0; i < count; i++)
            {
                Shapes.Add(GAShape.ReadBinary(this, br));
            }

            byte r = br.ReadByte();
            byte g = br.ReadByte();
            byte b = br.ReadByte();

            BackgroundColour = Color.FromArgb(r, g, b);
        }
Exemplo n.º 9
0
        public static GAShape CreateRandom(ThreadSafeRandom rd, GAProjectProperties prop, GARepresentation owner)
        {
            List <GAShapeType> lt = new List <GAShapeType>();

            if (prop.UsePoints)
            {
                lt.Add(GAShapeType.Circle);
            }
            if (prop.UseLines)
            {
                lt.Add(GAShapeType.Line);
            }
            if (prop.UseCurves)
            {
                lt.Add(GAShapeType.Curve);
            }
            if (prop.UseFilledPolygons)
            {
                lt.Add(GAShapeType.FilledPolygon);
            }
            if (prop.UseFilledPolycurves)
            {
                lt.Add(GAShapeType.FilledPolycurve);
            }
            //if (prop.UsePaths) lt.Add(GAShapeType.Path);

            if (lt.Count == 0)
            {
                throw new Exception("GASHape.CreateRandom - No Shapes Allowed");
            }

            GAShape output = null;

            switch (lt[rd.Next(lt.Count)])
            {
            case GAShapeType.Circle:
                output = new GAShapeCircle(owner);
                break;

            case GAShapeType.Line:
                output = new GAShapeLine(owner);
                break;

            case GAShapeType.Curve:
                output = new GAShapeCurve(owner);
                break;

            case GAShapeType.FilledPolygon:
                output = new GAShapeFilledPolygon(owner);
                break;

            case GAShapeType.FilledPolycurve:
                output = new GAShapeFilledPolycurve(owner);
                break;

            case GAShapeType.Path:
                output = new GAShapePath(owner);
                break;
            }

            output.Randomize(rd, prop);
            return(output);
        }