Exemplo n.º 1
0
        public void reset()
        {
            this.formation = new Formation(screen, slits);
            List <Behavior> fishbhs = new List <Behavior>();

            fishbhs.Add(new InertiaBehavior());
            fishbhs.Add(new RandomBehavior());
            fishbhs.Add(new AlignmentBehavior());
            fishbhs.Add(new SeparationBehavior());
            fishbhs.Add(new CohesionBehavior());
            fishbhs.Add(new RepulsionBehavior());

            List <Behavior> whalebhs = new List <Behavior>();

            whalebhs.Add(new InertiaBehavior());
            whalebhs.Add(new RandomBehavior());
            whalebhs.Add(new AlignmentBehavior());
            whalebhs.Add(new SeparationBehavior());
            whalebhs.Add(new HuntingBehavior());

            //float whaleRatio = 0.02f;
            int whaleNum = 2; //left hand and right hand

            Vector2 pos = Vector2.Zero;
            Vector2 dir = Vector2.Zero;

            for (int i = 0; i < heads; i++)
            {
                pos.X = (float)(screen.X + (rand.NextDouble() * screen.Width) % screen.Width);
                pos.Y = (float)(screen.Y + (rand.NextDouble() * screen.Height) % screen.Height);

                double randAngle = rand.NextDouble() * 2 * Math.PI;
                dir.X = (float)Math.Cos(randAngle);
                dir.Y = (float)Math.Sin(randAngle);

                Animal anm;
                //if (rand.NextDouble() < whaleRatio) {
                //    anm = new Whale(pos, dir);
                //    anm.Behaviors = whalebhs;
                //} else {
                anm           = new Fish(pos, dir);
                anm.Behaviors = fishbhs;
                anm.ZPosition = (float)(rand.NextDouble() * Game1.thickness) % Game1.thickness;
                //}
                formation.add(anm);
            }

            for (int i = 0; i < whaleNum; ++i)
            {
                Animal anm;
                anm                = new Whale(pos, dir);
                anm.Behaviors      = whalebhs;
                anm.iLeftRightHand = -1;
                formation.add(anm);

                anm                = new Whale(pos, dir);
                anm.Behaviors      = whalebhs;
                anm.iLeftRightHand = 1;
                formation.add(anm);
            }
            Updater.Formation  = formation;
            Renderer.Formation = formation;
        }
        public void CollectionNamesTest()
        {
            var a  = new MongoRepository <Animal>();
            var am = new MongoRepositoryManager <Animal>();
            var va = new Dog();

            Assert.IsFalse(am.Exists);
            a.Update(va);
            Assert.IsTrue(am.Exists);
            Assert.IsInstanceOfType(a.GetById(va.Id), typeof(Dog));
            Assert.AreEqual(am.Name, "AnimalsTest");
            Assert.AreEqual(a.CollectionName, "AnimalsTest");

            var cl  = new MongoRepository <CatLike>();
            var clm = new MongoRepositoryManager <CatLike>();
            var vcl = new Lion();

            Assert.IsFalse(clm.Exists);
            cl.Update(vcl);
            Assert.IsTrue(clm.Exists);
            Assert.IsInstanceOfType(cl.GetById(vcl.Id), typeof(Lion));
            Assert.AreEqual(clm.Name, "Catlikes");
            Assert.AreEqual(cl.CollectionName, "Catlikes");

            var b  = new MongoRepository <Bird>();
            var bm = new MongoRepositoryManager <Bird>();
            var vb = new Bird();

            Assert.IsFalse(bm.Exists);
            b.Update(vb);
            Assert.IsTrue(bm.Exists);
            Assert.IsInstanceOfType(b.GetById(vb.Id), typeof(Bird));
            Assert.AreEqual(bm.Name, "Birds");
            Assert.AreEqual(b.CollectionName, "Birds");

            var l  = new MongoRepository <Lion>();
            var lm = new MongoRepositoryManager <Lion>();
            var vl = new Lion();

            //Assert.IsFalse(lm.Exists);   //Should already exist (created by cl)
            l.Update(vl);
            Assert.IsTrue(lm.Exists);
            Assert.IsInstanceOfType(l.GetById(vl.Id), typeof(Lion));
            Assert.AreEqual(lm.Name, "Catlikes");
            Assert.AreEqual(l.CollectionName, "Catlikes");

            var d  = new MongoRepository <Dog>();
            var dm = new MongoRepositoryManager <Dog>();
            var vd = new Dog();

            //Assert.IsFalse(dm.Exists);
            d.Update(vd);
            Assert.IsTrue(dm.Exists);
            Assert.IsInstanceOfType(d.GetById(vd.Id), typeof(Dog));
            Assert.AreEqual(dm.Name, "AnimalsTest");
            Assert.AreEqual(d.CollectionName, "AnimalsTest");

            var m  = new MongoRepository <Bird>();
            var mm = new MongoRepositoryManager <Bird>();
            var vm = new Macaw();

            //Assert.IsFalse(mm.Exists);
            m.Update(vm);
            Assert.IsTrue(mm.Exists);
            Assert.IsInstanceOfType(m.GetById(vm.Id), typeof(Macaw));
            Assert.AreEqual(mm.Name, "Birds");
            Assert.AreEqual(m.CollectionName, "Birds");

            var w  = new MongoRepository <Whale>();
            var wm = new MongoRepositoryManager <Whale>();
            var vw = new Whale();

            Assert.IsFalse(wm.Exists);
            w.Update(vw);
            Assert.IsTrue(wm.Exists);
            Assert.IsInstanceOfType(w.GetById(vw.Id), typeof(Whale));
            Assert.AreEqual(wm.Name, "Whale");
            Assert.AreEqual(w.CollectionName, "Whale");
        }
Exemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     whale       = GameObject.Find("humpbackholder");
     whaleObject = GameObject.Find("humpback");
     whaleScript = whale.GetComponent <Whale>();
 }
Exemplo n.º 4
0
 private int GetNumberOfWhalesInSpecies(Whale whale)
 {
     return(_whaleRepository.GetCount(whale.Species));
 }
Exemplo n.º 5
0
        public override Double Solve()
        {
            Random random = new Random();

            Random r1 = new Random();
            Random r2 = new Random();
            Random L  = new Random();
            Random P  = new Random();

            double b = random.NextDouble() * random.Next(1, whales.Count); // logarithmic spiral
            double a = 2;

            int currentIteration = 0;

            Whale bestSearchAgent = whales.MinBy(item => item.score).DeepClone();

            while (currentIteration < maxIterations)
            {
                foreach (var currentWhale in whales)
                {
                    a = 2 - currentIteration * ((double)2 / maxIterations);
                    double A = 2 * r1.NextDouble() * a - a;
                    double C = 2 * r2.NextDouble();

                    double l = 2 * L.NextDouble() - 1; // [-1; 1]
                    double p = P.NextDouble();

                    if (p < 0.5)
                    {
                        if (Math.Abs(A) < 1)
                        {
                            List <double> D = new List <double>();
                            for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                            {
                                double d_i = Math.Sqrt(Math.Pow((C * bestSearchAgent.position[dimensionIndex] - currentWhale.position[dimensionIndex]), 2));

                                D.Add(d_i);
                            }

                            for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                            {
                                // Updates current whale position
                                currentWhale.position[dimensionIndex] = bestSearchAgent.position[dimensionIndex] - A * D[dimensionIndex];
                            }
                            // Eq. 2.1
                        }
                        else if (Math.Abs(A) >= 1)
                        {
                            int randomXSearchAgent = random.Next(0, this.whales.Count);

                            List <double> D = new List <double>();
                            for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                            {
                                double d_i = Math.Sqrt(Math.Pow((C * this.whales[randomXSearchAgent].position[dimensionIndex] - currentWhale.position[dimensionIndex]), 2));

                                D.Add(d_i);
                            }

                            for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                            {
                                // Updates current whale position
                                currentWhale.position[dimensionIndex] = this.whales[randomXSearchAgent].position[dimensionIndex] - A * D[dimensionIndex];
                            }
                            // Select a random search Agent
                            // Eq 2.8
                        }
                    }
                    else if (p >= 0.5)
                    {
                        List <double> D = new List <double>();
                        for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                        {
                            double d_i = Math.Sqrt(Math.Pow((bestSearchAgent.position[dimensionIndex] - currentWhale.position[dimensionIndex]), 2));

                            D.Add(d_i);
                        }

                        for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                        {
                            // Updates current whale position

                            currentWhale.position[dimensionIndex] = D[dimensionIndex] * Math.Pow(Math.E, b * l) * Math.Cos(2 * Math.PI * l) + bestSearchAgent.position[dimensionIndex];
                        }
                        // E.q. 2.5
                    }
                }

                // Check boundaries
                foreach (var currentWhale in this.whales)
                {
                    for (int dimensionIndex = 0; dimensionIndex < numberOfDimensions; dimensionIndex++)
                    {
                        if (currentWhale.position[dimensionIndex] > upperBoundaries[dimensionIndex])
                        {
                            currentWhale.position[dimensionIndex] = upperBoundaries[dimensionIndex];
                        }
                        else if (currentWhale.position[dimensionIndex] < lowerBoundaries[dimensionIndex])
                        {
                            currentWhale.position[dimensionIndex] = lowerBoundaries[dimensionIndex];
                        }
                    }
                }

                // Calculate fintess function for each agent
                foreach (var currentWhale in this.whales)
                {
                    currentWhale.score = ObjectiveFunction(currentWhale.position);
                }

                var newBestSearchAgent = whales.MinBy(item => item.score).DeepClone();
                if (newBestSearchAgent.score < bestSearchAgent.score)
                {
                    bestSearchAgent = newBestSearchAgent.DeepClone();
                }

                currentIteration++;
                //Console.WriteLine($"Iteration: {currentIteration}");
                //Console.WriteLine($"Whale Score: {bestSearchAgent.score}");
                //Console.WriteLine($"Whale Positions: {String.Join(", ", bestSearchAgent.position.ToArray())}");
            }

            //  Console.WriteLine($"Whale Score: {bestSearchAgent.score}");
            // Console.WriteLine($"Whale Positions: {String.Join(", ", bestSearchAgent.position.ToArray())}");

            return(bestSearchAgent.score);
        }
Exemplo n.º 6
0
 public void UpdateWhale(Whale whale)
 {
     _whaleRepository.Update(whale);
 }
Exemplo n.º 7
0
 private void Awake()
 {
     instance      = this;
     WhaleInstance = GameObject.Instantiate(whaleObj, whaleSpawn.position, whaleSpawn.rotation).GetComponent <Whale>();
     _state        = LevelState.Whaling;
 }
Exemplo n.º 8
0
 static void Main(string[] args)
 {
     Mammal mammal = new Mammal();
     Whale  whale  = new Whale();
 }
Exemplo n.º 9
0
        public void CanWhaleNotPlay()
        {
            Whale whale = new Whale();

            Assert.False(whale.Play());
        }
Exemplo n.º 10
0
        public void CanWhaleSpeak()
        {
            Whale whale = new Whale();

            Assert.True(whale.Speak());
        }
Exemplo n.º 11
0
        public void WhaleIsAnimal()
        {
            Whale whale = new Whale();

            Assert.IsType <Whale>(whale);
        }
Exemplo n.º 12
0
        public void CanWhaleStopSwimming()
        {
            Whale whale = new Whale();

            Assert.True(whale.Stop());
        }
Exemplo n.º 13
0
        public void DoWhaleUseIswim()
        {
            Whale whale = new Whale();

            Assert.True(whale.Swim());
        }
Exemplo n.º 14
0
        public void AddWhale(WhaleDTO whale)
        {
            Whale whaleEntity = Convert(whale);

            _whaleManagementService.AddWhale(whaleEntity);
        }
Exemplo n.º 15
0
        public void CollectionNamesTest()
        {
            // animal
            var a  = new MongoRepository <Animal>();
            var am = new MongoRepositoryManager <Animal>();

            a.DeleteAll();

            var va = new Dog();

            am.Exists.ShouldBeFalse();
            a.Update(va);
            am.Exists.ShouldBeTrue();
            a.GetById(va.Id).ShouldBeOfType(typeof(Dog));
            am.Name.ShouldBe("AnimalsTest");
            a.CollectionName.ShouldBe("AnimalsTest");

            // cat
            var cl  = new MongoRepository <CatLike>();
            var clm = new MongoRepositoryManager <CatLike>();

            cl.DeleteAll();

            var vcl = new Lion();

            clm.Exists.ShouldBeFalse();
            cl.Update(vcl);
            clm.Exists.ShouldBeTrue();
            cl.GetById(vcl.Id).ShouldBeOfType(typeof(Lion));
            clm.Name.ShouldBe("Catlikes");
            cl.CollectionName.ShouldBe("Catlikes");

            // bird
            var b  = new MongoRepository <Bird>();
            var bm = new MongoRepositoryManager <Bird>();

            b.DeleteAll();

            var vb = new Bird();

            bm.Exists.ShouldBeFalse();
            b.Update(vb);
            bm.Exists.ShouldBeTrue();
            b.GetById(vb.Id).ShouldBeOfType(typeof(Bird));
            bm.Name.ShouldBe("Birds");
            b.CollectionName.ShouldBe("Birds");

            // lion
            var l  = new MongoRepository <Lion>();
            var lm = new MongoRepositoryManager <Lion>();

            l.DeleteAll();

            var vl = new Lion();

            //Assert.IsFalse(lm.Exists);   //Should already exist (created by cl)
            l.Update(vl);
            lm.Exists.ShouldBeTrue();
            l.GetById(vl.Id).ShouldBeOfType(typeof(Lion));
            lm.Name.ShouldBe("Catlikes");
            l.CollectionName.ShouldBe("Catlikes");

            // dog
            var d  = new MongoRepository <Dog>();
            var dm = new MongoRepositoryManager <Dog>();

            d.DeleteAll();

            var vd = new Dog();

            //Assert.IsFalse(dm.Exists);
            d.Update(vd);
            dm.Exists.ShouldBeTrue();
            d.GetById(vd.Id).ShouldBeOfType(typeof(Dog));
            dm.Name.ShouldBe("AnimalsTest");
            d.CollectionName.ShouldBe("AnimalsTest");

            // bird
            var m  = new MongoRepository <Bird>();
            var mm = new MongoRepositoryManager <Bird>();

            m.DeleteAll();

            var vm = new Macaw();

            m.Update(vm);
            mm.Exists.ShouldBeTrue();
            m.GetById(vm.Id).ShouldBeOfType(typeof(Macaw));
            mm.Name.ShouldBe("Birds");
            m.CollectionName.ShouldBe("Birds");

            // whale
            var w  = new MongoRepository <Whale>();
            var wm = new MongoRepositoryManager <Whale>();

            w.DeleteAll();

            var vw = new Whale();

            wm.Exists.ShouldBeFalse();
            w.Update(vw);
            wm.Exists.ShouldBeTrue();
            w.GetById(vw.Id).ShouldBeOfType(typeof(Whale));
            wm.Name.ShouldBe("Whale");
            w.CollectionName.ShouldBe("Whale");

            // cleanup
            am.Drop();
            clm.Drop();
            bm.Drop();
            lm.Drop();
            dm.Drop();
            mm.Drop();
            wm.Drop();
        }
Exemplo n.º 16
0
        public void CollectionNamesTest()
        {
            var a = new MongoRepository<Animal>();
            var am = new MongoRepositoryManager<Animal>();
            var va = new Dog();
            Assert.IsFalse(am.Exists);
            a.Update(va);
            Assert.IsTrue(am.Exists);
            Assert.IsInstanceOfType(a.GetById(va.Id), typeof(Dog));
            Assert.AreEqual(am.Name, "AnimalsTest");
            Assert.AreEqual(a.CollectionName, "AnimalsTest");

            var cl = new MongoRepository<CatLike>();
            var clm = new MongoRepositoryManager<CatLike>();
            var vcl = new Lion();
            Assert.IsFalse(clm.Exists);
            cl.Update(vcl);
            Assert.IsTrue(clm.Exists);
            Assert.IsInstanceOfType(cl.GetById(vcl.Id), typeof(Lion));
            Assert.AreEqual(clm.Name, "Catlikes");
            Assert.AreEqual(cl.CollectionName, "Catlikes");

            var b = new MongoRepository<Bird>();
            var bm = new MongoRepositoryManager<Bird>();
            var vb = new Bird();
            Assert.IsFalse(bm.Exists);
            b.Update(vb);
            Assert.IsTrue(bm.Exists);
            Assert.IsInstanceOfType(b.GetById(vb.Id), typeof(Bird));
            Assert.AreEqual(bm.Name, "Birds");
            Assert.AreEqual(b.CollectionName, "Birds");

            var l = new MongoRepository<Lion>();
            var lm = new MongoRepositoryManager<Lion>();
            var vl = new Lion();
            //Assert.IsFalse(lm.Exists);   //Should already exist (created by cl)
            l.Update(vl);
            Assert.IsTrue(lm.Exists);
            Assert.IsInstanceOfType(l.GetById(vl.Id), typeof(Lion));
            Assert.AreEqual(lm.Name, "Catlikes");
            Assert.AreEqual(l.CollectionName, "Catlikes");

            var d = new MongoRepository<Dog>();
            var dm = new MongoRepositoryManager<Dog>();
            var vd = new Dog();
            //Assert.IsFalse(dm.Exists);
            d.Update(vd);
            Assert.IsTrue(dm.Exists);
            Assert.IsInstanceOfType(d.GetById(vd.Id), typeof(Dog));
            Assert.AreEqual(dm.Name, "AnimalsTest");
            Assert.AreEqual(d.CollectionName, "AnimalsTest");

            var m = new MongoRepository<Bird>();
            var mm = new MongoRepositoryManager<Bird>();
            var vm = new Macaw();
            //Assert.IsFalse(mm.Exists);
            m.Update(vm);
            Assert.IsTrue(mm.Exists);
            Assert.IsInstanceOfType(m.GetById(vm.Id), typeof(Macaw));
            Assert.AreEqual(mm.Name, "Birds");
            Assert.AreEqual(m.CollectionName, "Birds");

            var w = new MongoRepository<Whale>();
            var wm = new MongoRepositoryManager<Whale>();
            var vw = new Whale();
            Assert.IsFalse(wm.Exists);
            w.Update(vw);
            Assert.IsTrue(wm.Exists);
            Assert.IsInstanceOfType(w.GetById(vw.Id), typeof(Whale));
            Assert.AreEqual(wm.Name, "Whale");
            Assert.AreEqual(w.CollectionName, "Whale");
        }
Exemplo n.º 17
0
 public IActionResult Delete([FromBody] Whale data)
 {
     _whaleRepository.DeleteWhale(data);
     return(new JsonResult(new { StatusCode = 200 }));
 }