예제 #1
0
        public Specimen ReproduseGomo()//создать свою копию
        {
            this.wantReproduse = false;
            Random r = new Random();

            int      immun         = this.immun;
            int      maxAge        = this.maxAge;
            int      sex           = this.sex;
            int      health        = this.health;
            int      x             = this.x;
            int      y             = this.y;
            int      MutateChanse  = this.MutateChanse;
            int      freqReproduse = this.freqReproduse;
            int      speed         = this.maxWay;
            Specimen newS          = new Specimen(immun, maxAge, sex, health, x, y, MutateChanse, freqReproduse, speed);

            newS.maxWay = freqReproduse;
            newS.Mutate();
            if (this.isSick)
            {
                newS.TryBeginSick(this.ill);
            }

            return(newS);
        }
예제 #2
0
        public Specimen TryReproduseGetero(Specimen secondParent)//попытаться размножиться с партнером
        {
            Specimen nSpecimen = null;
            int      realDist  = 0;

            realDist = Convert.ToInt32(Math.Sqrt(((this.x - secondParent.x) * (this.x - secondParent.x)) + ((this.y - secondParent.y) * (this.y - secondParent.y))));

            if (realDist <= reproduseDistanse && this.sex != secondParent.sex)
            {
                //int tmp = GetProb(this.quality, secondParent.quality);//отбор партнера по качеству
                // if (tmp > 0)
                nSpecimen = this.ReproduseGetero(ref secondParent);
            }
            return(nSpecimen);
        }
예제 #3
0
        Specimen ReproduseGetero(ref Specimen secondParent)//размножиться с партнером
        {
            this.wantReproduse         = false;
            secondParent.wantReproduse = false;
            Random r = new Random();

            int      immun         = Convert.ToInt32((this.immun + secondParent.immun) / 2);
            int      maxAge        = Convert.ToInt32((this.maxAge + secondParent.maxAge) / 2);
            int      sex           = r.Next(1, 3);
            int      health        = Convert.ToInt32((this.health + secondParent.health) / 2);
            int      x             = Convert.ToInt32((this.x + secondParent.x) / 2);
            int      y             = Convert.ToInt32((this.y + secondParent.y) / 2);
            int      MutateChanse  = Convert.ToInt32((this.MutateChanse + secondParent.MutateChanse) / 2);
            int      freqReproduse = Convert.ToInt32((this.freqReproduse + secondParent.freqReproduse) / 2);
            int      speed         = Convert.ToInt32((this.maxWay + secondParent.maxWay) / 2);
            Specimen newS          = new Specimen(immun, maxAge, sex, health, x, y, MutateChanse, freqReproduse, speed);

            newS.maxWay = freqReproduse;
            newS.Mutate();
            if (this.isSick)//заражение партнера
            {
                secondParent.TryBeginSick(this.ill);
            }
            else
            {
                if (secondParent.isSick)
                {
                    this.TryBeginSick(secondParent.ill);
                }
            }
            //заражение ребенка
            if (this.sex == 1 && this.isSick)
            {
                newS.TryBeginSick(this.ill);
            }
            if (secondParent.sex == 1 && secondParent.isSick)
            {
                newS.TryBeginSick(secondParent.ill);
            }


            return(newS);
        }
예제 #4
0
파일: Life.cs 프로젝트: literale/war
        static void ReproduseFinal() //размножаем всех
        {
            Specimen newS = null;

            if (Specimen.typeOfReproduse > 1)
            {
                for (int i = 0; i < LS.Count(); i++)
                {
                    for (int j = 0; j < LS.Count(); j++)
                    {
                        if (LS[i].wantReproduse && LS[j].wantReproduse)
                        {
                            newS = LS[i].TryReproduseGetero(LS[j]);
                        }
                    }

                    if (LS[i].wantReproduse && LS[i].sex == 1 && Specimen.typeOfReproduse == 3)
                    {
                        newS = LS[i].ReproduseGomo();
                    }
                }
            }
            else
            {
                for (int i = 0; i < LS.Count(); i++)
                {
                    if (LS[i].wantReproduse)
                    {
                        newS = LS[i].ReproduseGomo();
                    }
                }
            }

            if (newS != null)
            {
                LS.Add(newS);
            }
        }
예제 #5
0
파일: War.cs 프로젝트: literale/war
        public void GenereteSpecimen()                        //Генерируем популяцию
        {
            int nSP          = Convert.ToInt32(tbSize.Text);  //размер популяции
            int immun        = tbMidImunn.Value;              //средний иммунитет
            int spImmun      = Convert.ToInt32(tbi.Text);     //разброс иммунитета
            int maxAge       = tbMidMaxAge.Value;             //максимальный возраст особи
            int spMaxAge     = Convert.ToInt32(tbma.Text);    //разброс максимального возраста
            int repDist      = tbRepDist.Value;               //расстояние для размножения
            int health       = tbMidHealth.Value;             //здоровье
            int spHealth     = Convert.ToInt32(tbh.Text);     //разброс здоровья
            int countRep     = Convert.ToInt32(tbr.Text);     //кол-во спариваний в год
            int muteChanse   = tbMuteChansS.Value;            //шанс мутации при появлении новой особи
            int spMuteChanse = Convert.ToInt32(tbmcs.Text);   ////разброс шанса мутаций
            int speed        = Convert.ToInt32(tbspeed.Text); //скорость
            int spSbeed      = Convert.ToInt32(tbspedrasb.Text);

            Life.fx = x;
            Life.fy = y;

            for (int i = 0; i < nSP; i++)
            {
                Specimen newS;
                Random   r      = new Random();
                int      nI     = immun + r.Next(-spImmun, spImmun + 1);
                int      nMA    = (maxAge + r.Next(-spHealth, spHealth + 1)) * 12;
                int      nH     = health + r.Next(-spHealth, spHealth + 1);
                int      nMC    = muteChanse + r.Next(-spMuteChanse, spMuteChanse + 1);
                int      nSpeed = speed + r.Next(-spSbeed, spSbeed + 1);
                int      sex;
                int      nrd = tbRepDist.Value;
                if (Specimen.typeOfReproduse == 1)
                {
                    sex = 3;
                }
                else
                {
                    sex = r.Next(1, 3);
                }
                int nx = r.Next(0, x);
                int ny = r.Next(0, y);
                if (nI < 1)
                {
                    nI = 1;
                }
                if (nMA < 1)
                {
                    nMA = 1;
                }
                if (nH < 1)
                {
                    nH = 1;
                }
                if (nMC < 1)
                {
                    nMC = 1;
                }
                newS        = new Specimen(nI, nMA, sex, nH, nx, ny, nMC, nrd, nSpeed);
                newS.maxWay = nrd;
                Life.LS.Add(newS);


                Random r1 = new Random();
                int    t  = r1.Next(1, 50);
                System.Threading.Thread.Sleep(t);//чтобы генератор успел змениться
            }
        }
예제 #6
0
파일: Life.cs 프로젝트: literale/war
        //Данная функция отвечает за всеобщее размножение. В зависимости от способа размножения она поступает по разному
        // Если способ размножения половой или смешенный, а размер популяции не больше максимального -
        //она проходится по списку всех особей
        //и если обе особи хотят размножаться - она пытается спарить из вызывая функцию TryReproduseGetero,
        // и если размножение прошло успешно - новая особь добавляется в список популяции
        // Если способ размножения смешанный, особи не нашлось подходящего партнера, она женского пола и она хочет спариваться -
        // Вызывается метод ReproduseGomo, который создает копию материнской особи с некоторыми мутациями
        //Если способ размножения - бесполый и особь хочет размножаться - так же вызывается функция ReproduseGomo
        static void ReproduseFinal() //размножаем всех
        {
            Specimen newS = null;

            int n   = LS.Count();
            int pop = Specimen.CountLived();

            if (pop < Specimen.maxPop)
            {
                if (Specimen.typeOfReproduse > 1)
                {
                    for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < n; j++)
                        {
                            if (LS[i].wantReproduse && LS[j].wantReproduse)
                            {
                                newS = LS[i].TryReproduseGetero(LS[j]);
                            }

                            if (newS != null)
                            {
                                LS.Add(newS);
                                LS[i].wantReproduse = false;
                                LS[j].wantReproduse = false;
                                if (Specimen.CountLived() > Specimen.maxPop)
                                {
                                    break;
                                }
                            }
                        }

                        if (LS[i].wantReproduse && LS[i].sex == 1 && Specimen.typeOfReproduse == 3)
                        {
                            newS = LS[i].ReproduseGomo();
                        }

                        if (newS != null)
                        {
                            LS.Add(newS);
                            LS[i].wantReproduse = false;
                            if (Specimen.CountLived() > Specimen.maxPop)
                            {
                                break;
                            }
                        }
                        if (Specimen.CountLived() > Specimen.maxPop)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (LS[i].wantReproduse)
                        {
                            newS = LS[i].ReproduseGomo();
                        }

                        if (newS != null)
                        {
                            LS.Add(newS);
                            LS[i].wantReproduse = false;
                        }
                        if (Specimen.CountLived() > 200)
                        {
                            break;
                        }
                    }
                }
            }
        }