protected float MaxDistance()
        {
            IEnumerable <BugPart> p = from part in mBugParts orderby Math.Abs(Mathn.Distance(transform.position.x, transform.position.z, part.transform.position.x, part.transform.position.z)) ascending select part;

            foreach (BugPart item in p)
            {
                return(Math.Abs(Mathn.Distance(transform.position.x, transform.position.z, item.transform.position.x, item.transform.position.z)) + (0.5f * item.transform.lossyScale.x));
            }

            return(transform.lossyScale.x);
        }
Exemple #2
0
        private BugStructur Crossover(BugStructur other, BugStructur that)
        {
            BugStructur buffer = new BugStructur();

            other.CalculatePoses();
            that.CalculatePoses();

            int MaxX = (int)Mathn.GetBigger(other.MaxX(), that.MaxX());
            int MaxY = (int)Mathn.GetBigger(other.MaxY(), that.MaxY());
            int MinX = (int)Mathn.GetBigger(other.MinX(), that.MinX());
            int MinY = (int)Mathn.GetBigger(other.MinY(), that.MinY());

            for (int x = MinX; x <= MaxX; x++)
            {
                for (int y = MinY; y <= MaxY; y++)
                {
                    BugPartData th = that.GetPartData(new Vector2(x, y));
                    BugPartData ot = that.GetPartData(new Vector2(x, y));

                    if (th == null && ot == null)
                    {
                        continue;
                    }

                    if (ot == th)
                    {
                        buffer.AddVecPart(new Vector2(x, y), th.Fuction);
                        continue;
                    }

                    if (th != null && ot != null)
                    {
                        buffer.AddVecPart(new Vector2(x, y), mRandom.NextBool() ? th.Fuction : ot.Fuction);
                        continue;
                    }

                    if (th == null)
                    {
                        th = ot;
                    }

                    if (mRandom.NextBool())
                    {
                        buffer.AddVecPart(new Vector2(x, y), th.Fuction);
                    }
                }
            }

            buffer.WriteVecParts();
            return(buffer);
        }