Пример #1
0
        public RabbitPair GetHalhPairData(RabbitGen rg, ref int pairsCount)
        {
            RabbitGen rabbM = Engine.db().getRabbitGen(rg.MotherId);
            RabbitGen rabbF = Engine.db().getRabbitGen(rg.FatherId);

            if ((rabbM != null) || (rabbF != null))
            {
                pairsCount++;

                RabbitPair rp = new RabbitPair();
                rp._id = pairsCount;
                _RabbitPairs.Add(pairsCount, rp);

                rp.SetParentControl(RabbitsHolder);

                rp.SetMom(rabbM);
                rp.SetDad(rabbF);

                log.Debug(string.Format("Getting parents for rabbit pair #{0:d} mom.", pairsCount));
                GetPairData(rp, ref pairsCount);

                return(rp);
            }
            else
            {
                log.Debug(string.Format("There's no parents :(", pairsCount));
                return(null);
            }
        }
Пример #2
0
        public int simulateRabbits(int monthsOfSimulations, int rabbitLivesThisManyMonths)
        {
            List <RabbitPair> poulation = new List <RabbitPair>();

            //Initial population:
            var rabbit = new RabbitPair
            {
                ageInMonths = 0
            };

            poulation.Add(rabbit);

            for (int i = 1; i < monthsOfSimulations; i++)
            {
                List <RabbitPair> children = new List <RabbitPair>();
                List <RabbitPair> dead     = new List <RabbitPair>();

                foreach (var rab in poulation)
                {
                    //Advance age
                    rab.ageInMonths++;

                    //Children?
                    if (rab.ageInMonths > 1)
                    {
                        children.Add(new RabbitPair
                        {
                            ageInMonths = 0
                        });
                    }

                    //Die?
                    if (rab.ageInMonths == rabbitLivesThisManyMonths)
                    {
                        dead.Add(rab);
                    }
                }

                foreach (var pair in dead)
                {
                    poulation.Remove(pair);
                }

                foreach (var pair in children)
                {
                    poulation.Add(pair);
                }
            }
            return(poulation.Count);
        }
Пример #3
0
        public void DrawRabbit(RabbitGen rbt)
        {
            Dictionary <int, Color> b_colors = new Dictionary <int, Color>();

            b_colors = Engine.db().getBreedColors();
            ProgressPanel.Visible = true;
            RabbitsHolder.Visible = false;
            //_rootRabbitData = rbt;
            _rootRabbit = new RabbitBar();
            _rootRabbit.SetRabbit(rbt);
            _rootRabbit.ReplaceGenomeColors(b_colors);
            _rootRabbit.BackColor      = this.BackColor;
            _rootRabbit.WindowRabbitID = rbt.ID;
            RabbitsHolder.Controls.Add(_rootRabbit);
            ///рисуем мать и отца выделенного кролика
            RabbitPair parents = new RabbitPair();

            _rootRabbitPair = parents;
            _rootRabbitPair.WindowRabbitID = rbt.ID;
            _rootRabbitPair.SearchGoingOn += new EvSearchGoingOn(SearchProc);
            parents.Location = new Point(1000, 100);

            int cnt = 0;

            _RabbitPairs.Clear();
            _RabbitPairs.Add(cnt, parents);
            parents.ReplaceGenomeColors(b_colors);

            RabbitGen rabbF = Engine.db().getRabbitGen(rbt.FatherId);
            RabbitGen rabbM = Engine.db().getRabbitGen(rbt.MotherId);

            parents.SetMom(rabbM);
            parents.SetDad(rabbF);
            parents._id = cnt;
            RabbitsHolder.SuspendLayout();
            parents.SetParentControl(RabbitsHolder);
            GetPairData(parents, ref cnt);

            CenterTree();
            CenterHolder();
            ProgressPanel.Visible = false;
            RabbitsHolder.Visible = true;
            RabbitsHolder.ResumeLayout();

            this.ScrollControlIntoView(_rootRabbit);
            this.ActiveControl = _rootRabbit;
            //RabbitsHolder.AutoScrollMinSize
        }
Пример #4
0
        /// <summary>
        /// Рекурсивно рисует данные по предкам пары Сацец-Самка
        /// </summary>
        /// <param name="mrp"></param>
        /// <param name="pairsCount"></param>
        public void GetPairData(RabbitPair mrp, ref int pairsCount)
        {
            log.Debug(string.Format("Getting data for rabbit pair. (cnt:{0:d})", pairsCount));
            Application.DoEvents();

            if (mrp.GetMom() != null)
            {
                log.Debug(string.Format("Rabbit pair #{0:d} has mom.", pairsCount));
                RabbitPair rp = GetHalhPairData(mrp.GetMom(), ref pairsCount);
                mrp.SetTreeChildFPair(rp);
            }

            if (mrp.GetDad() != null)
            {
                log.Debug(string.Format("Rabbit pair #{0:d} has dad.", pairsCount));
                RabbitPair rp = GetHalhPairData(mrp.GetDad(), ref pairsCount);
                mrp.SetTreeChildMPair(rp);
            }
        }