示例#1
0
        public Agent GenerateNewMigratingAgent(List <Agent> allAgents, Agent currentAgent)
        {
            Agent agent = null;

            AllPoints = new List <Point>();

            for (int i = 0; i < worldSize; i++)
            {
                for (int j = 0; j < worldSize; j++)
                {
                    AllPoints.Add(new Point(i, j));
                }
            }

            var plants = allAgents.Where(a => a.AgentType == AgentTypes.Plant).ToList();

            for (int i = 0; i < plants.Count; i++)
            {
                AllPoints.RemoveAll(p => plants[i].AgentLocation.X == p.X && plants[i].AgentLocation.Y == p.Y);
            }

            List <Point> pointsToRemove = new List <Point>();

            for (int i = 0; i < AllPoints.Count; i++)
            {
                var agents = allAgents.Where(a => a.AgentLocation.X == AllPoints[i].X && a.AgentLocation.Y == AllPoints[i].Y);

                if (agents.Count() >= 2)
                {
                    pointsToRemove.Add(new Point(AllPoints[i].X, AllPoints[i].Y));
                }
            }

            for (int i = 0; i < pointsToRemove.Count; i++)
            {
                AllPoints.RemoveAll(p => p.X == pointsToRemove[i].X && p.Y == pointsToRemove[i].Y);
            }

            int index = rand.Next(0, AllPoints.Count - 1);

            var newP    = new Point(AllPoints.ElementAt(index).X, AllPoints.ElementAt(index).Y);
            var network = currentAgent.GetNetwork();

            // якщо предок травоїдне, то створюємо нового травоїдного
            if (currentAgent.AgentType == AgentTypes.Herbivorous)
            {
                agent = new Herbivorous(newP, currentAgent.GetGeneration() + 1, new NeuralNetwork(network));
            }

            // якщо предок хижак - створюємо нового хижака
            else
            {
                agent = new Predator(newP, currentAgent.GetGeneration() + 1, new NeuralNetwork(network));
            }

            return(agent);
        }
示例#2
0
            public static void Main()
            {
                Implement Imp    = new Implement();
                Animal    animal = new Animal();


                Carnivorous cn = new Carnivorous();
                Herbivorous hb = new Herbivorous();

                Console.WriteLine("Call function with animal obj");
                Imp.callFunction(animal);


                Console.WriteLine("Call function with Carnivorous obj");
                Imp.callFunction(cn);//Decision is take during runttime--We can pass object of Base class Animal or any of its derived class

                //We can call Behaviour method of Child class only with child class object as it is not declared with Virtual keyword
                Console.WriteLine("Call function with Herbivorous obj");

                Imp.callFunction(hb);
                Birds bird = new Birds();

                //Imp.callFunction(bird);--Not possible....We can pass only animal class object or its dervived classes
                Console.WriteLine("Calling the Behaviour method with Carnivorous class obj");
                cn.Behaviour();

                Console.ReadLine();

                //Animal animal1;

                //animal1 = new Animal();
                //animal1.FoodHabits();
                //animal.Behaviour();

                //animal1 = new Carnivorous();
                //animal1.FoodHabits();
                //animal1.Behaviour();

                //animal1= new Herbivorous();
                //animal1.FoodHabits();//Virtual method will call the corresponding method of what is beeing passed
                //animal1.Behaviour();//Normal method Always call the method of Base class only

                ////Carnivorous car = (Carnivorous)new Animal();--Error...Only parent class object can be used for instantiating child class and Viceversa is not possible
            }
示例#3
0
        public override void InitializeAgent()
        {
            base.InitializeAgent();
            LivingBeing = new Herbivorous(50, 0, 0, 50, 0, 10);

            eatCounter          = Metrics.CreateCounter("eatHerbivorous", "How many times herbivorous has eaten");
            reproductionCounter =
                Metrics.CreateCounter("reproductionHerbivorous", "How many times herbivorous has reproduced");
            cumulativeRewardGauge =
                Metrics.CreateGauge("cumulativeRewardHerbivorous", "Cumulative reward of herbivorous");
            lifeGainGauge =
                Metrics.CreateGauge("lifeGainHerbivorous", "Life gain on eat of herbivorous");
            rewardOnActGauge =
                Metrics.CreateGauge("rewardOnActHerbivorous", "Reward on act herbivorous");
            rewardOnEatGauge =
                Metrics.CreateGauge("rewardOnEatHerbivorous", "Reward on eat herbivorous");
            rewardOnReproduceGauge =
                Metrics.CreateGauge("rewardOnReproduceHerbivorous", "Reward on reproduce herbivorous");
            speedGauge =
                Metrics.CreateGauge("speedHerbivorous", "Speed herbivorous");
        }
示例#4
0
        private List <Agent> GenerateHerbivorous()
        {
            List <Point> herbivorousList = new List <Point>();

            herbivorousList.AddRange(AllPoints);

            List <Agent> herbivores = new List <Agent>();

            for (int i = 0; i < amountOfHerbivorous; i++)
            {
                int index = rand.Next(0, herbivorousList.Count() - 1);

                int X = herbivorousList.ElementAt(index).X;
                int Y = herbivorousList.ElementAt(index).Y;

                Agent herbivorous = new Herbivorous(new Point(X, Y), 1, new NeuralNetwork());
                herbivores.Add(herbivorous);
                herbivorousList.RemoveAt(index);
            }
            return(herbivores);
        }
示例#5
0
        private void AddAnimal_Click(object sender, EventArgs e)
        {
            if (NameIn.Text.Trim() != String.Empty)
            {
                FeedType feedType = null;
                switch (FeedTypesList.SelectedItem)
                {
                case FeedTypes.Herbivorous:
                    feedType = new Herbivorous();
                    break;

                case FeedTypes.Omnivorous:
                    feedType = new Omnivorous();
                    break;

                case FeedTypes.Carnivorous:
                    feedType = new Carnivorous();
                    break;
                }
                switch (AnimalTypesList.SelectedItem)
                {
                case Animals.Bird:
                    Animal = new Bird(NameIn.Text.Trim(), DateOfBirthIn.Value, feedType);
                    break;

                case Animals.Fish:
                    Animal = new Fish(NameIn.Text.Trim(), DateOfBirthIn.Value, feedType);
                    break;

                case Animals.Mammal:
                    Animal = new Mammal(NameIn.Text.Trim(), DateOfBirthIn.Value, feedType);
                    break;
                }
                Handled = true;
                Close();
            }
        }
示例#6
0
 public override void InitializeAgent()
 {
     LivingBeing = new Herbivorous(99, 0, 20, 99, 0);
     rayPer      = GetComponent <RayPerception>();
 }
示例#7
0
文件: Game.cs 项目: Manyunka/BadLife
        public override void OnUpdate()
        {
            foreach (Creature d in Creatures)
            {
                d.Update(ref Creatures, ref MapObjects);

                if (d.GetType() == typeof(Woman) && ((Woman)d).IsPregnant)
                {
                    Borns.Add(((Woman)d).GiveBirth());
                }

                if (!d.Visible)
                {
                    Deads.Add(d);
                }
            }

            foreach (Creature d in Borns)
            {
                Creatures.Add(d);
            }

            foreach (Creature d in Deads)
            {
                if (Creatures.Contains(d))
                {
                    Creatures.Remove(d);
                }
            }

            Deads.Clear();
            Borns.Clear();

            if (random.Next(10) == 0)
            {
                Plant p = new Plant(PlantBitmap, 32, 32);

                int x = random.Next(16, 2048);
                int y = random.Next(16, 2048);
                p.SetLocation(x, y);

                int frame = random.Next(7);
                p.SetFrame(frame);
                Creatures.Add(p);
            }
            if (random.Next(20) == 0)
            {
                Herbivorous b = new Herbivorous(BunnyBitmap, 48, 48);

                int x = random.Next(16, 2048);
                int y = random.Next(16, 2048);
                b.SetLocation(x, y);

                int ind = random.Next(4);
                b.SetFrameIndex(ind);
                b.SetFPS(6);

                Creatures.Add(b);
            }
            if (random.Next(20) == 0)
            {
                Predator p = new Predator(FoxBitmap, 48, 48);

                int x = random.Next(16, 2048);
                int y = random.Next(16, 2048);
                p.SetLocation(x, y);

                int ind = random.Next(4);
                p.SetFrameIndex(ind);
                p.SetFPS(6);

                Creatures.Add(p);
            }
        }
示例#8
0
文件: Game.cs 项目: Manyunka/BadLife
        public override void OnLoadContent()
        {
            int tileSize = 64;

            TileBitmap = new Bitmap(@"Images/tiles.png");
            Tiles      = new Tile[3];
            Tiles[0]   = new Tile(TileBitmap.Clone(new Rectangle(0, 0, tileSize, tileSize), System.Drawing.Imaging.PixelFormat.Undefined));
            Tiles[1]   = new Tile(TileBitmap.Clone(new Rectangle(tileSize, 0, tileSize, tileSize), System.Drawing.Imaging.PixelFormat.Undefined));
            Tiles[2]   = new Tile(TileBitmap.Clone(new Rectangle(tileSize * 2, 0, tileSize, tileSize), System.Drawing.Imaging.PixelFormat.Undefined));

            int row = 2048 / tileSize;
            int col = 2048 / tileSize;

            TileMap = new TileMap(Tiles, row, col, tileSize);

            random = new Random();
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    if (random.Next(3) == 0)
                    {
                        if (random.Next(2) == 0)
                        {
                            TileMap.SetTile(i, j, 1);
                        }
                        else
                        {
                            TileMap.SetTile(i, j, 2);
                        }
                    }
                }
            }

            Creatures = new List <Creature>();

            PlantBitmap = new Bitmap(@"Images/plants.png");
            for (int i = 0; i < 300; i++)
            {
                Plant p = new Plant(PlantBitmap, 32, 32);

                int x = random.Next(16, 2048);
                int y = random.Next(16, 2048);
                p.SetLocation(x, y);

                int frame = random.Next(7);
                p.SetFrame(frame);
                Creatures.Add(p);
            }

            BunnyBitmap = new Bitmap(@"Images/bunny.png");
            for (int i = 0; i < 30; i++)
            {
                Herbivorous b = new Herbivorous(BunnyBitmap, 48, 48);

                int x = random.Next(16, 2048) + 16;
                int y = random.Next(16, 2048) + 16;
                b.SetLocation(x, y);

                int ind = random.Next(4);
                b.SetFrameIndex(ind);
                b.SetFPS(6);

                Creatures.Add(b);
            }

            FoxBitmap = new Bitmap(@"Images/fox.png");
            for (int i = 0; i < 20; i++)
            {
                Predator f = new Predator(FoxBitmap, 48, 48);

                int x = random.Next(16, 2048) + 16;
                int y = random.Next(16, 2048) + 16;
                f.SetLocation(x, y);

                int ind = random.Next(4);
                f.SetFrameIndex(ind);
                f.SetFPS(6);
                Creatures.Add(f);
            }

            ManBitmap   = new Bitmap(@"Images/man.png");
            WomanBitmap = new Bitmap(@"Images/woman.png");
            for (int i = 0; i < 15; i++)
            {
                Human h;
                if (random.Next(2) == 0)
                {
                    h = new Man(ManBitmap, 32, 48);
                }
                else
                {
                    h = new Woman(WomanBitmap, 32, 48);
                }

                int x = random.Next(16, 2048) + 16;
                int y = random.Next(16, 2048) + 16;
                h.SetLocation(x, y);

                int ind = random.Next(4);
                h.SetFrameIndex(ind);
                h.SetFPS(6);
                Creatures.Add(h);
            }

            /*Fox = new Predator(FoxBitmap, 48, 48);
             * Fox.SetFrameIndex(2);
             * Fox.SetFrame(1);
             * Fox.SetLocation(500, 500);
             * Fox.SetFPS(6);*/

            MapObjects = new List <MapObject>();

            Borns = new List <Creature>();
            Deads = new List <Creature>();
        }