using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace island
{
    public class Generation
    {
        public TGrass Grass;
        public Animal Rabbit;
        public Animal Wolf;

        public int GenerationCount = 0;

        int MaxGrass = 200;
        int MaxRabbit = 500;
        int MaxWolf = 50;

        public TGrass InitGrass;
        public Animal InitRabbit;
        public Animal InitWolf;

        public Generation()
        {
            Random rnd = new Random();            
            Grass = new TGrass( 
                rnd.Next(MaxGrass),
                rnd.NextDouble()
                );
            Rabbit = new Animal(
                rnd.Next(MaxRabbit),
                rnd.NextDouble(),
                rnd.NextDouble(),
                rnd.NextDouble()
                );
            Wolf = new Animal(
                rnd.Next(MaxWolf),
                rnd.NextDouble(),
                rnd.NextDouble(),
                rnd.NextDouble()
                );
            InitGrass = Grass;
            InitRabbit = Rabbit;
            InitWolf = Wolf;
        }
        public long CheckGeneration()
        {
            if ((Grass.Count > 0) && (Rabbit.Count > 0) && (Wolf.Count > 0))
                return Grass.Count + Rabbit.Count + Wolf.Count;
            else
                return 0;
        }
        public void Life()
        {
            // 1.
            Grass.Grow();
            // 2.
            Rabbit.Dead();
            // 3.
            Grass.Count = Rabbit.Eat(Grass.Count);
            // 4.
            Rabbit.Born();
            // 5.
            Rabbit.Count = Wolf.Eat(Rabbit.Count);
            // 6.
            Wolf.Born();
            // 7.
            Wolf.Dead();

            GenerationCount++;
        }
        public override String ToString()
        {
            return "про траву: "+Grass.ToString() + '\n' +
                   "про кроликов: "+Rabbit.ToString() + '\n' +
                   "про волков: "+Wolf.ToString();
        }
        public String ToStringInit()
        {
            return "ТРАВА: " + InitGrass.ToString() + '\n' +
                   "КРОЛИКИ: " + InitRabbit.ToString() + '\n' +
                   "ВОЛКИ: " + InitWolf.ToString();
        }

    }
}
